473,890 Members | 1,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
breadth? EC
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
about Microsoft. Microsoft are the leading consumer software company in the
world, arguably the leading software company full stop.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.


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
opinions about Microsoft.

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
opinions about Microsoft.


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
freeware games to download.
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};

instead of:

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.

Similar topics

1
1968
by: lawentzel | last post by:
I am new to PHP and am an avid RPG gamer. I am looking to use PhpMyChat to be able to game with friends all over the US. With that having been said, PhpMyChat seems to offer a lot of what I am looking for. It allows you to send a message to individual players (chatters). It allows for actions using "/me". The only thing it really needs is the capability to do a dice roll. Can someone point me to a site which might have some examples...
4
6388
by: dpp4669 | last post by:
I need help with writing a program to use randmax and the standard deviation when u roll the dice 10000 times I know you will need the standard dev. and the average where do i put the randmax and do i use 1+6 after it ? LOST!
17
9624
by: Jose Durazo | last post by:
Hello, I'm doing an exercise to simulate rolling a pair of dice 36,000 times, then count and display how many times the simulation rolls each possible sum. For some reason each time I run my simulation, one or more of my sums is zero, which is highly unlikely. So I'm sure there's a bug in my code. But I can't tell what it is, even after re-reading it several times. Can someone give me a hint? Here is my code:
4
4137
by: vegtard | last post by:
simple question. is it possible to write a script that rolls a six sided dice? if this is possible, is it possible to tell it to roll the six sided dice 4 times and ignore the dice that rolled the lowest score? if you want to know, i am working on a script to create a dungeons and dragons character :)
2
3403
by: sunnydude | last post by:
Anybody know how to write a 3 dice rolling program like this Sample output Welcome to the dice roller! First of all, please enter a seed for the random number generator. This should be a positive integer: 3 How many times would you like me to roll the 3 dice?
2
6492
by: cowboyjeff05 | last post by:
the question is 1) build a Die class (6 sided). Then create a driver that tests your class. Start with one die in your driver then add a second die and notify the user and count when he or she rolls 7, 11, or a double. When the user is done rolling, output the results of the session. Create a child class from the Die class called MultisidedDie. This die should allow the programmer using the class to decide how many sides the die has. ...
0
9980
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10830
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9641
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5855
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.