I have already seen Weregoose's routine on Yahtzee, but I have a different set of possibilities to sort.
Here they are:
(1) 5 of a kind (5K): Identical to a Yahtzee. (AAAAA)
(2) 4 of a kind (4K): 4 of a kind and one single (AAAAB)
(3) Full House (FH): 3 of a kind and a pair (AAABB)
(4) 3 of a kind (3K): 3 of a kind and two singles (AAABC)
(5) 2 pair (2P): 2 pairs and a single (AABBC)
(6) 1 pair (1P): One pair and 3 singles (AABCD)
(7) Chance (CH): 5 singles (ABCDE)

For example, a roll of {2,4,5,2,6} would be a pair. {3,4,5,4,3} would be two pair, etc.

The program should input a list of 5 numbers 1-6 and output the correct two-letter abbreviation. Source code should be in the post, with downloads optional.

Karma to the shortest program. (Extra karma if you can create a seperate program for all of the possibilities for 6 dice.)
I'm busy, but someone mentioned 'shortest program', so I'll work on it. If you already have a routine, I'd be interested to see it (after I write my own!)

EDIT: If we take the sums of the squares of the sizes of the groups, we get the following. For example, AAAAB gives us 4^2+1^2 = 17.

5K/AAAAA: 25
4K/AAAAB: 17
3K/AAABC: 11

So maybe something like this? I haven't tested it yet, and even if it works there could be another byte or two.


EDIT: -5 bytes, and tested-- the sum(seq( calculates the same thing, but the obvious way was shorter. I think I'm within a few bytes of the optimal solution now.


What do you mean by a separate program for all 6 possibilities?

EDIT: Saved one more byte at the cost of speed. I can't think of any more improvements.

Wow. That's short.

What I meant by "6 dice possibilities" is all the possibilities for 6 dice. AAAAAA, ABCDEF, etc. Edited post to clarify.
There are 11 integer partitions of 6, and I think the routine would get a little messier. I'm more interested in the general case, though: getting a list of the number of occurrences of each element.

Here's a routine from tibasicdev.
Galandros wrote:

:DelVar L₂DelVar L₃SortA L₁

If we don't need the actual elements, we can get rid of L2; we can also sort L3 so the highest values are first:

DelVar L3SortA L1
SortD L3
lirtosiast wrote:
There are 11 integer partitions of 6, and I think the routine would get a little messier.

I smell a challenge, and I accept.

*cracks knuckles* Time for some computer-assisted code golf: https://repl.it/DfGv. Not shown: search program, also in Python.

Based on your work, I think I have this, which, if it works and I counted bytes correctly, is 56 bytes. Not yet tested, but it would be an 8-byte improvement.


On 83+ the summation can be replaced with a sum(seq(, which takes one byte for the extra close-paren; and the remainder( with fPart( which takes a lot more bytes.



I was being an idiot; the /3 did nothing. 29+3+22=54 bytes now.
*bows in defeat* You win.

I'm guessing the shortest program on the Ti-83 would be:



BTW, I didn't think of remainder over anything. Mainly because I don't have an 84-Plus, though a CE is on my wish list. Smile
With nonnegative Ans you can do round(26fPart(Ans/26; the round( corrects rounding errors. It's actually only two bytes longer. So 56 bytes.

Karma given.

With letters instead of abbreviations, one can get even smaller. Heres the best I can do for 2 dice through 8 dice. After each section of code, Ill give a chart of what each letter means.

2 Dice: (29 bytes)


A: (2) One pair
B: (1,1) Two singles

3 Dice: (31 bytes)


A: (3) One triple
B: (2,1) One pair, and one single
C: (1,1,1) Three singles

4 Dice: (34 bytes)


A: (4) One quadruple
B: (3,1) One triple, one single
C: (2,2) Two pairs
D: (2,1,1) One pair, and two singles
E: (1,1,1,1) Four singles

5 Dice: (37 bytes)


A: (5) One set of five
B: (4,1) One quadruple, and one single
C: (3,2) One triple, and one pair
D: (3,1,1) One triple, and two singles
E: (2,2,1) Two pairs, and one single
F: (2,1,1,1) One pair, and three singles
G: (1,1,1,1,1) Five singles

6 Dice: (43 bytes)


A: (6) One set of six
B: (5,1) One set of five, and one single
C: (4,2) One quadruple, and one pair
D: (4,1,1) One quadruple, and two singles
E: (3,3) Two triples
F: (3,2,1) One triple, one pair, and one single
G: (3,1,1,1) One triple, and three singles
H: (2,2,2) Three pairs
I: (2,2,1,1) Two pairs, and two singles
J: (2,1,1,1,1) One pair, and four singles
K: (1,1,1,1,1,1) Six singles

7 Dice: (47 bytes)


8 Dice: (59 bytes)


Can you improve?

NEED TO DO: Type up last two charts.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum