Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #23448
| From | Ron Aaron <rambamist@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Dice problem |
| Date | 2013-06-11 20:04 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <kp7l24$6be$1@dont-email.me> (permalink) |
| References | <kp7g25$7mj$1@dont-email.me> |
Not certain what the point of the problem is, really. Here's one possible solution using Reva Forth, which outputs: Calculating dice scores: (100 1000 1100 0 200 50 550 350) 100 1000 1100 0 200 50 550 350 Here's the code: create dice-scores 5 cells allot create score-table 100 , 200 , 1000 , 1100 , 1200 , 0 , 0 , 200 , 200 , 200 , 0 , 0 , 300 , 300 , 300 , 0 , 0 , 400 , 400 , 400 , 50 , 100 , 500 , 550 , 600 , 0 , 0 , 600 , 600 , 600 , : reset-count ( -- ) dice-scores 5 cells zero temp off ; : count-die ( one-die -- ) 1- cells dice-scores + ++ ; : get-score ( -- ) 5 0do | get score for this item i cells dice-scores + @ dup 0if drop else 1- cells | index to score-table and get the score: i 5 * cells score-table + + @ temp +! then loop temp ? ; : count-dice ( a1 a2 a3 .. aN N -- total ) reset-count 0do count-die loop get-score ; ." Calculating dice scores:" cr ." (100 1000 1100 0 200 50 550 350)" cr 1 1 count-dice 1 1 1 3 count-dice 1 1 1 1 4 count-dice 2 1 count-dice 2 2 2 3 count-dice 5 1 count-dice 5 5 5 5 4 count-dice 2 5 2 1 2 5 count-dice cr bye
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar
Dice problem "WJ" <w_a_x_man@yahoo.com> - 2013-06-11 15:34 +0000 Re: Dice problem Ron Aaron <rambamist@gmail.com> - 2013-06-11 20:04 +0300
csiph-web