473,890 Members | 1,339 Online

# rolling dice

Let's say I have m dice having n sides, such that n^m is not going to bust
int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}.
What is a good way to represent this in c so that I can check cases by brute
force? EC
Sep 30 '06
101 6449

"Michael Mair" <Mi**********@i nvalid.invalidw rote in message
news:4o******** ****@individual .net...
Elijah Cardon wrote:
>"Michael Mair" <Mi**********@i nvalid.invalidw rote
<snip>
>This is the line I wanted to take this in, but I gotta get my head around
the notions of recursion and stack depth. To that I end I ask this
question:
long factorial(int n) {
if (n == 1)
return 1;
return n * factorial(n - 1);
}

What is the stack depth as a function of n? If you look at the
discussion in chp 10 of _C Unleashed_, it follows the execution of this
source. At the end, there are n-1 paragraphs that begin:
Back on line ....
, so I think the stack depth is n-1 . If I'm wrong that it's near n, I
don't see how stack depth could be less than (n-1)! . EC

I now have got back my copy of C Unleashed, so I know what you mean:
You have essentially the same structure as above:
if (m == 1)
do something to *pCount;
else if (m 1)
hand it to the same function with (m-1)
i.e. you have the same stack depth as for the factorial() function.
The loop is merely decoration as it will not change the stack depth.
It changes the stack's contents, though:
Let's take the second run of the loop in main()
- The "first level call" to countSumOccurre nces_Rec() issues
a "second level call" for i = 0, 1, 2, 3, 4.
- The stack depth for each of the "second level calls" is the same
but you have different i values and, consequently, different sum
values in the call stack
I think that this response is partially based on the understanding that sum
values were relevant to this question, and this relies on OP.

Q2) We look at two recursive functions that are identical except that
where, e.g. one says long factorial(n){ as above }and the other long
factorial(n, m){ as follows }where n does the same darn thing and is an
analog to m, but m=42 so that we force our computer to remember a bunch of
constants, just to be jerks in a Gedankenexperim ent. They will have the
same number of "level calls" but the second stack will have the same number
of entries that are a function of n, plus a like number of 42's on the
stack. What can be said about the stack depth? Can one talk of stack
Oct 2 '06 #31

"Elijah Cardon" <in*****@invali d.netwrote in message
news:12******** *****@corp.supe rnews.com...
>
"Spiros Bousbouras" <sp****@gmail.c omwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
>Elijah Cardon wrote:
>>Where I have the comment, I could test for whether the dummies add to
seven and keep a counter of those that do, and those that don't. I
would
then have the probability I'm looking for.

What probability are you looking for ? You still
haven't explained what problem you're trying to
solve.
I've seen people play dice before and certainly recall hours of dice in my
hands for gaming purposes. I found myself in a situation, where I was not
only playing a dice game I'd never played before, apparently, it's called
"dice," and found myself attracted to certain aspects of the game.

Getting a one or a five means you get to roll again. So, for the purpose
of detremining whether you can roll again, you can map the six-sided die
onto the three-sided die. Someone wondered aloud what the chances are of
rolling again with 2 dice. I saw a picture in my head that looked like:
_____________
| x | o | o |
-------------
| x | o | o |
-------------
| x | x | x |
_____________
I said ,"five ninths."

Later, I'm trying to sleep, and wonder how it would look in a higher
dimension. The next would be like a Rubic's cube. First I saw x's
heading out along the orthogonals, but that would make 11 out of 27 cubes
x's, and your odds don't go down, so that was wrong. I decided I needed
to add the plane: 9 cubes to the 2 planes of residuals 9+2*5=19 x's out of
27. I verified this number from first principles.

And with 4 dimensions? I think you add the cube to twice the residual:
27+2(19)=65 out of 81. It's getting a little tedious to verify by hand.
EC
news:12******** *****@corp.supe rnews.com...
Conjecture verified in fortran. I'd bet dollars to donuts that this holds
in higher dimensions. EC
Oct 2 '06 #32

"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:Zs******** ***********@new s.indigo.ie...
Richard Heathfield posted:
>Apart from <snip Episode 4 of Babysisters' Club 2nd Seasonwhat you are
overlooking is that there is a large and influential code base which
uses ALL CAPS for type names - namely, the Win32 API.

And once again, the rule of thumb applies:

Don't do what Microsoft does.
People who know a lot about computers often like to make jokes at the
expense of Bill Gates and his software company.
Don't let that fool you into thinking that these reflect their real opinions
world, arguably the leading software company full stop.
--
www.personal.leeds.ac.uk/~bgy1mm

Oct 7 '06 #33
Malcolm posted:
People who know a lot about computers often like to make jokes at the
expense of Bill Gates and his software company.
Don't let that fool you into thinking that these reflect their real

No fooling required, it _does_ reflect my real opinion.

I use Microsoft software all the time, and it rarely crashes so I find it
quite useful. What I don't like, however, is the programming snippets you
find on MSDN, things like "ZeroMemory " which render non-portable, code which
could otherwise be perfectly portable!

--

Frederick Gotham
Oct 7 '06 #34

"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:v5******** ***********@new s.indigo.ie...
Malcolm posted:
>People who know a lot about computers often like to make jokes at the
expense of Bill Gates and his software company.
Don't let that fool you into thinking that these reflect their real

No fooling required, it _does_ reflect my real opinion.

I use Microsoft software all the time, and it rarely crashes so I find it
quite useful. What I don't like, however, is the programming snippets you
find on MSDN, things like "ZeroMemory " which render non-portable, code
which
could otherwise be perfectly portable!
Most PC programs don't need to be ported to other platforms. It certainly
isn't in Microsoft's interests for them to be ported to other platforms.
If your real opinion is that Microsoft is incompetent, as opposed to making
a joke, then I'm afraid you don't know very much about the computer
industry.
--
www.personal.leeds.ac.uk/~bgy1mm
Oct 7 '06 #35
Malcolm posted:
Most PC programs don't need to be ported to other platforms. It
certainly isn't in Microsoft's interests for them to be ported to other
platforms. If your real opinion is that Microsoft is incompetent, as
opposed to making a joke, then I'm afraid you don't know very much about
the computer industry.
Let's say that tomorrow, AMD announce that they've made a major
breakthrough in CPU technology, and that they have produced a 63.88 EHz CPU
which will go on the market in 2 months time. The CPU in question uses a
bit-pattern of all-one's for null pointers. If Microsoft had used:

struct MyStruct obj = {0};

struct MyStruct obj;
ZeroMemory(&obj ,sizeof obj);

, then they wouldn't have a problem.

The point I'm trying to get across is this:
Sure, there's certain things that you can't do portably... but if you
_can_ do it portably, then _do_ _it_ _portably_!

My major peeve with ZeroMemory is that I've seen no justification
whatsoever for its usage in the place of perfectly portable built-in
language functionality.

The executables that Microsoft turns out tend to be pretty good, not
crashing too often or anything. Their code is a different story.

--

Frederick Gotham
Oct 7 '06 #36
On Sat, 07 Oct 2006 10:13:47 GMT, in comp.lang.c , Frederick Gotham
<fg*******@SPAM .comwrote:
>What I don't like, however, is the programming snippets you
find on MSDN, things like "ZeroMemory " which render non-portable, code which
could otherwise be perfectly portable!
What one needs to bear in mind is that MSDN isn't a free programming
reference manual , its a free Microsoft product reference manual.
Oracle's online manuals are similarly full of oracle-isms that render
otherwise perfectly portable SQL nonportable.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 7 '06 #37
Mark McIntyre posted:
On Sat, 07 Oct 2006 10:13:47 GMT, in comp.lang.c , Frederick Gotham
<fg*******@SPA M.comwrote:
>>What I don't like, however, is the programming snippets you
find on MSDN, things like "ZeroMemory " which render non-portable, code
which could otherwise be perfectly portable!

What one needs to bear in mind is that MSDN isn't a free programming
reference manual , its a free Microsoft product reference manual.
Oracle's online manuals are similarly full of oracle-isms that render
otherwise perfectly portable SQL nonportable.

I don't think it would hurt for Microsoft to send their programmers on a one-
day course about portable programming. It would only take a matter of hours
to get them using things like the following:

struct MyStruct obj = {0};

--

Frederick Gotham
Oct 7 '06 #38
Frederick Gotham <fg*******@SPAM .comwrites:
My major peeve with ZeroMemory is that I've seen no justification
whatsoever for its usage in the place of perfectly portable built-in
language functionality.
Microsoft doesn't *want* programmers writing portable code. That's
the justification for ZeroMemory() and similar Microsoftisms.

It doesn't make technical sense, but it makes perfect business and
marketing sense (at least if such things are not contradictions in terms.)

Charlton
Oct 7 '06 #39
Charlton Wilbur posted:
>My major peeve with ZeroMemory is that I've seen no justification
whatsoever for its usage in the place of perfectly portable built-in
language functionality.

Microsoft doesn't *want* programmers writing portable code. That's
the justification for ZeroMemory() and similar Microsoftisms.

It doesn't make technical sense, but it makes perfect business and
marketing sense (at least if such things are not contradictions in terms.)

They have enough money to stop focusing on business, and start focusing on
what they actually would like to do. Bill Gates gives millions (if not
billions) to charity every year.

If they're greedy enough to write non-portable code for the sake of non-
portable code, you'd wouldn't expect them to be giving money to charity...

--

Frederick Gotham
Oct 7 '06 #40

This thread has been closed and replies have been disabled. Please start a new discussion.