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
FH/AAABB: 13
3K/AAABC: 11
2P/AABBC: 9
1P/AABCD: 7
CH/ABCDE: 5

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

Code:
min(19,sum(seq(sum(L1=L1(A)),A,1,5
sub("CH1P2P3KFH??4K5K",Ans-4,2


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.


Code:
abs(20-sum(seq(sum(L1=X)²,X,1,6
sub("4K5KFH3K2P1PCH",Ans-2,2


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.


Code:
abs(sum(2-seq(sum(L1=X)²,X,0,9
sub("4K5KFH3K2P1PCH",Ans-2,2
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:

Code:
:DelVar L₂DelVar L₃SortA L₁
:For(θ,1,dim(L₁
:L₁(θ→L₂(1+dim(L₂
:sum(L₁=Ans→L₃(dim(L₂
:θ-1+Ans→θ
:End

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:

Code:
DelVar L3SortA L1
For(X,1,dim(L1
sum(L1=L1(X->L3(1+dim(L3
X-1+Ans->X
End
SortD L3
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.


Code:
abs(sum(18-seq(sum(L1=X)³,X,1,6
sub("5K----FH4K--2T----TR3K3P2P1PLS6K",Ans/3-5,2
*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.

Code:
sub("-LS1P2P3P3KTR--5K2T6K4KFH",remainder(Sigma(sum(L1=X)³,X,1,6)/3,26),2


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.

EDIT:

Code:
sub("-2T3KLS6KTR1P4K--2PFH5K3P",remainder(Sigma(sum(L1=X)³,X,1,6),26),2


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:


Code:

sum(seq(sum(L1=X)³,X,1,6
sub("-2T3KLS6KTR1P4K--2PFH5K3P",Ans-26int(Ans/26),2


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.

Code:
round(26fPart(26^^-1sum(seq(sum(L1=X)³,X,1,6
sub("-2T3KLS6KTR1P4K--2PFH5K3P",Ans,2
Karma given.

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

2 Dice: (29 bytes)

Code:
:sub(“BA”,.5sum(seq(sum(L1=X)^^2,X,1,6)),1

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

3 Dice: (31 bytes)

Code:
:int(.4sum(seq(sum(L1=X)^^2,X,1,6
:sub(“CBA”,Ans,1

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

4 Dice: (34 bytes)

Code:
:int(.4sum(seq(sum(L1=X)^^2,X,1,6
:sub(“EDCB-A”,Ans,1

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)

Code:
:int(8fPart(7^^-1sum(seq(sum(L1=X)^^3,X,1,6
:sub(“DBEFGAC”,Ans,1

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)

Code:
:int(12fPart(39^^-1sum(seq(sum(L1=X)^^3,X,1,6
:sub(“KBJEIAHDGCF”,Ans,1

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)

Code:
:int(16fPart(76^^-1sum(seq(sum(L1=X)^^3,X,1,6
:sub(“-NEMLKJAIDHCBGF”,Ans,1


8 Dice: (59 bytes)

Code:
:int(29fPart(388^^-1sum(seq(sum(L1=X)^4,X,1,6
:sub(“-TSRBQPOHDCNM—AGFLKJ-E-I”,Ans,1


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 UTC - 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

 

Advertisement