HHC 2015 RPN programming Contest is now open
|
10-03-2015, 08:55 AM
(This post was last modified: 10-03-2015 08:57 AM by Csaba Tizedes.)
Post: #81
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-02-2015 01:01 PM)David Hayden Wrote:(10-01-2015 04:30 PM)Peter Murphy Wrote: Would anyone be willing to discuss the scheme or schemes they used to solve this?My solution sets the flags that correspond to the dice. So mine sets flags 1, 3, 4, and 5 in the example ... he has a bunch of code to detect duplicate dice ... no need to detect duplicate dice (setting a flag works if the flag is initially set), but the code to detect a small straight is complicated. Same as my method but I used lots of steps for totally same task: My method is works on that we store the numbers of dices in R1~R5. We need one additional register R6 to mark if we have 6 on any dice. This is that point where my solution grows too high: with indirect addressing I marked each register (steps: 011~023): Code:
This is totally same but very very long code... If I use flags these steps can shortened. After marking registers from R1~R6 the original content is remain in each registers only the sign is changed: If we have 1,1,2,6,6,9 in registers R1~R6, after running above code we have -1,-1,2,6,6,-9 in registers (because on dices we have 1, 2 and 6). The other part (counting) is also straighforward. Csaba |
|||
10-03-2015, 11:01 AM
Post: #82
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 03:12 AM)David Hayden Wrote:(10-01-2015 02:39 PM)Werner Wrote: 1 E4 = 3 bytesYes, but on the 41 you don't have to enter 1, you can just enter EEX 4 which is 2 bytes (the same as 4 10^X as you pointed out). Yes, that's a valid shortcut but it will be registered as 1 E4 nonetheless. Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
10-03-2015, 03:20 PM
Post: #83
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open | |||
10-03-2015, 03:25 PM
Post: #84
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open | |||
10-03-2015, 03:29 PM
Post: #85
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-02-2015 01:01 PM)David Hayden Wrote:(10-01-2015 04:30 PM)Peter Murphy Wrote: Would anyone be willing to discuss the scheme or schemes they used to solve this?Egan's first solution works by taking each unique die value X and summing up 10X. For example, if the roll is 4 3 5 3 1, it will add up 104 + 103 + 105 + 101 = 111,010. It then looks for 1111 in the sequence. In this example, 1111 doesn't appear so there is no small straight. Others took this approach as well including Werner's 42-byter. However Werner looked for >= 1111 so that nothing was required to remove dups. I was working on a similar solution, but decided to pursue different approaches, including your flag approach, but I never finished it. |
|||
10-03-2015, 03:54 PM
(This post was last modified: 10-03-2015 04:16 PM by Egan Ford.)
Post: #86
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 01:19 AM)Allen Wrote: To that end \(6x+1\) makes for an even shorter program. ( by checking 8645, 38285, and 108965). (maps to 7,13,19,5^2,31,37). After I posted my prime-based solution I tried to create other prime and co-prime series, but it didn't get me close to 42 bytes. Dieter's optimization + your series still puts it 7 bytes short: 49 bytes (was 53 with x^2-x+11): Code:
We can shave off a byte by only checking for 1,2,5,6 pairs, then checking 3,4: 48 bytes: Code:
Next possible optimization would be to pre compute series, store checks in registers, loop the checks. That's 3 loops and possibly a GSB. |
|||
10-03-2015, 04:48 PM
Post: #87
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 11:01 AM)Massimo Gnerucci Wrote:(10-03-2015 03:12 AM)David Hayden Wrote: Yes, but on the 41 you don't have to enter 1, you can just enter EEX 4 which is 2 bytes (the same as 4 10^X as you pointed out). Gene: And EEX 4 would violate the no synthetic programming rule. The contest was wide open. Very few constraints so that a lot of ideas could be tried. In reality, to fit the small straight routine into the larger yahtzee program, other considerations have to be accounted for. The YZ program uses flags already, so modifying flags would force a re-write of many areas. The YZ program uses memories 1-13 to store the scorecard for the game. Dice are actually in 14-18. :-) That's what made Werner's code so attractive. Short, no flags, no extra memories. Seems like a good fit. Perhaps, given the improvement found here :-) I should post the code for the game in total. Who knows how short it might become! |
|||
10-03-2015, 05:12 PM
(This post was last modified: 10-03-2015 05:13 PM by Egan Ford.)
Post: #88
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
Optimized brute-force search.
40 bytes: Code:
|
|||
10-03-2015, 06:22 PM
Post: #89
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 04:48 PM)Gene Wrote: Perhaps, given the improvement found here :-) I should post the code for the game in total. Who knows how short it might become! I would find that very interesting, indeed. Thank you again for such a fun challenge. I learned some things from the other programmers! 17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b |
|||
10-04-2015, 01:52 PM
Post: #90
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-03-2015 04:48 PM)Gene Wrote: Gene: And EEX 4 would violate the no synthetic programming rule.EEX is not synthetic. It's on the keyboard after all. It sounds like there is a synthetic E command, but EEX is fair game. However, someone else pointed out that entering EEX 4 in program mode results in the 3 byte number 1 E4. |
|||
10-04-2015, 01:57 PM
(This post was last modified: 10-04-2015 01:59 PM by Dieter.)
Post: #91
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-04-2015 01:52 PM)David Hayden Wrote:(10-03-2015 04:48 PM)Gene Wrote: Gene: And EEX 4 would violate the no synthetic programming rule.EEX is not synthetic. It's on the keyboard after all. It sounds like there is a synthetic E command, but EEX is fair game. I think Gene wanted to say that a two byte "E4" command was not allowed as it can only be generated by synthetic programming. As you said, simply typing [EEX] [4] yields a standard "1 E4" line with three bytes. Dieter |
|||
10-04-2015, 03:22 PM
Post: #92
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-04-2015 01:52 PM)David Hayden Wrote:(10-03-2015 04:48 PM)Gene Wrote: Gene: And EEX 4 would violate the no synthetic programming rule.EEX is not synthetic. It's on the keyboard after all. It sounds like there is a synthetic E command, but EEX is fair game. Correct. 1 E4 is valid per the conditinos. E4 is not. :-) Missed you (and Egan) at the conference this year! |
|||
10-04-2015, 08:50 PM
Post: #93
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
Here's another solution. It's 25 steps, 40 bytes and uses 2 registers.
The idea is to sort the numbers and then count the number of times that the difference between adjacent numbers is 1. If the difference is ever greater than 1, then reset the counter. In pseudo-code: Code: SORT Notice that because last_die is initialized to zero, the first time through teh loop diff is always greater than 1 so sum gets reset to 0. Here is the code with byte counts and comments. R06 is the index register R07 is the value of the last die Code: 01 LBL 'RR' 6 bytes |
|||
10-05-2015, 06:33 PM
(This post was last modified: 10-07-2015 04:48 PM by Jeff O..)
Post: #94
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
As is my usual practice, I worked on the challenge for a while before checking the discussion here.
I initially resisted methods that required the sort routine. I worked through a few methods, best I could do was 32 steps/56 bytes using flags. I kept having nagging misgivings about using flags, when to clear them, etc. So I worked on a scheme where I stored ones in a sequence of registers, and “optimized” that down to 42 steps/66 bytes. With this concept, I kept having nagging misgivings about using registers and when to clear them. So I finally PMed Gene and asked about the propriety of using flags and/or registers. He said the rules did not prevent it, but that “in reality the routine is in the middle of a program that uses the first 15 user flags and has most registers spoken for.” So I decided to abandon my reticence to using the sort routine and see if that would help me develop shorter/better programs. After a few iterations, I arrived at 25 step/45 byte version that re-uses register 5, but no other registers or flags, and a 26 step/46 byte version that uses no flags or registers and preserves all of the die values, in case they are needed later in the Yahtzee program. These two programs are presented below for those who might be interested. I thought about the problem for a couple of days, trying to come up with alternate approaches that might lead to shorter programs, but had no flashes of inspiration, so I finally read this thread. As I suspected, there were some approaches that made sense and I might have arrived at independently had I kept devoting time to the problem, and others I would never have thought of in million years (e.g., using prime numbers.) Thanks Gene for another fun project. Code:
- edited for the sake of brevity, improve program comments, and to correct typos Dave - My mind is going - I can feel it. |
|||
10-07-2015, 12:41 AM
(This post was last modified: 10-07-2015 12:44 AM by Sylvain Cote.)
Post: #95
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
It took me 6 versions (between 40 and 45 bytes) before being able to come up with a version under 40 bytes.
Code: CAT"1 Code: BB LL Code Comment Resources ... Regs.: 1 to 5 with values sets before running this program Flags: 1 to 5 and need to be cleared before running this program Prog.: 38 Bytes Comments: 1) there is only two valid values 1234 and 2345 2) the flags 1 to 5 are set based on the values (1 to 5) found. I used flags to remove duplicates and the needed for sorting 3) because a sequence of four is a winner, if flag 5 is set, then I set the flag 1 and only the first four flags (1 to 4) is validated Edit: Arrrg, I forgot the value 6, I will correct it and come back |
|||
10-07-2015, 02:51 PM
Post: #96
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-07-2015 12:41 AM)Sylvain Cote Wrote: Edit: Arrrg, I forgot the value 6, I will correct it and come backNote that the contest also required that you be able to run the program again by loading R01-R05 with new values and pressing R/S, so you need to clear the flags and deal with the STOP somehow. |
|||
10-14-2015, 05:29 PM
Post: #97
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
In analyzing Werner’s code (which is quite brilliant, in my opinion), I decided that I needed a list of every possible combination of die values that could fall out of the Yahtzee cup. With five dice, each having six possible values, there are 6^5 or 7776 possible sets. But the order does not matter (e.g., 1-2-3-4-5 is the same as 5-4-3-2-1 is the same as 3-1-5-4-2, etc.), so there are a lot fewer unique combinations that we need to worry about. Through a laborious and most likely inefficient process (listing and counting them in excel), I determined that there seem to be just 252 unique combinations, as follows:
6 + 30 + 30 + 60 + 60 + 60 + 6 = 252 Can anyone confirm the above? (Or deny, I may be wrong and won’t mind being corrected.) Figuring items 1 and 7 is trivial, even for me. I think items 2 and 3 are figured simply as 6 ways to pick the first number times 5 ways to pick the second equals 30. I am a little murkier on how to figure items 4, 5 and 6. For items 4 and 5, my inclination would be to start with 6 ways to pick the first number times 5 ways to pick the second times 4 ways to pick the third equals 120. But that would include some duplications, I think, as for example, 3 sixes, 1 five and 1 four is the same as 3 sixes, 1 four and 1 five. Seems like each such combination would appear twice, so I would divide the 120 by 2 to get 60. For item 6, I’d start 6 x 5 x 4 x 3 equals 360, then divide by 3! to account for the repeats among the three single values, yielding 360/6 which equals 60. But I’m not completely sure about those methods. Assuming I have the figures correct, is there a simple method to calculate that there are 252 unique combinations among the 7776 non-unique ones? (My exposure to calculations involving probabilities and statistics is pretty limited, so please be gentle.) Dave - My mind is going - I can feel it. |
|||
10-14-2015, 07:01 PM
Post: #98
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-14-2015 05:29 PM)Jeff O. Wrote: I determined that there seem to be just 252 unique combinations You are correct: Number of combinations with repetition \[ \binom{n+k−1}{k}=\binom{6+5−1}{5}=\binom{10}{5}=252 \] Cheers Thomas |
|||
10-15-2015, 11:51 AM
Post: #99
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(10-14-2015 07:01 PM)Thomas Klemm Wrote: You are correct: Number of combinations with repetition Thanks for the information, and for not telling me to "RTFI" (Read the Fine Internet). :-) I guess I forgot that it is 2015 and all I had to do was type "combination" into a search engine. It is too easy to rely on the expertise that I know resides in the members of this Forum. Dave - My mind is going - I can feel it. |
|||
10-15-2015, 12:19 PM
Post: #100
|
|||
|
|||
RE: HHC 2015 RPN programming Contest is now open
(09-29-2015 09:25 AM)Werner Wrote: Managed to squeeze off a byte: As I stated elsewhere, in my opinion your program is quite brilliant. It took me a little while to figure out what you were doing, what the heck the LOG, FRC and SIGN instructions could possibly have to do with this problem. But after walking through it a time or two (or three), I was able to see the method you used, which is quite clever. Then I thought I saw a simple improvement, put the RCL 5 in the loop to build the sum, like this: Code:
That is indeed one step shorter, but due to the need to enter the 0 ahead of the summing loop, the byte count is the same. More elegant to start the sum with one of the values to be summed (10^register 5) and then sum the rest than to start at zero. For the same byte count, I’ll take elegance over step count. Other similar rearrangements yielded 25 steps, but higher byte counts, so I think your code is optimal. Again, very nice work! Dave - My mind is going - I can feel it. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 9 Guest(s)