Name that Poker hand - Tiny Code Challenge

Back down to 394, thanks mostly to richierich :point:

EDIT: new record: 392! verified for all permutations.

int h(char[]g){
	int n=99,i=-2,p=n,q=-p,r=p,s=q,v,w,y[]=new int[5*n];
	for(;i<13;y[n+g[++i]]++)y[" A23456789TJQK".indexOf(g[i+=2])]++;
	for(;n-->0;y[198+y[n]]=n)if(y[n]>0)if((p=n)<2)s=14;else{r=p=p<n?p:n;s=q=q>n?q:n;}
	for(w=q-p<5|s-r<5?7:0;++n<99;y[297+y[99+n]]=n,y[396+y[n]]++)w&=y[n]/2-1;
	for(v=y[302]>>5;new int[]{s-r<5?w&v:0,w&v,y[202],y[399]&p,v,w,y[201],p-1,p,1}[99-n]<1;n--)p=y[398];
	return n;
}

This could work


- s-r<5?w&v:0,
+ r>9?w&v:0,     //lowest card is > 9


2H 3H 4H 5H 6H
	Riven: royal flush
	Richy: straight flush

Seems like that fixes a bug in my impl… :slight_smile:

Totally intentional of course!

Edit: I have to say your boolean-array-within-for-loop thing to replace a long sequence of if/else tests is great. Evil, but great :stuck_out_tongue:

It’s getting pretty good now.

Verified against the “r > 9”

371 chars

int h(char[]g){
	int n=99,i=-2,p=n,q=-p,r=p,v,w,y[]=new int[5*n];
	for(;i<13;y[n+g[++i]]++)y[" A23456789TJQK".indexOf(g[i+=2])]++;
	for(;n-->0;y[198+y[n]]=n)p=y[n]>0?n<2?n:(q=q>n?q:n)-q+(r=p<n?p:n):p;
	for(w=q-p<5|r>9?7:0;++n<99;y[297+y[99+n]]=n,y[396+y[n]]++)w&=y[n]/2-1;
	for(v=y[302]>>5;new int[]{r>9?w&v:0,w&v,y[202],y[399]&p,v,w,y[201],p-1,p,1}[99-n]<1;n--)p=y[398];
	return n;
}

369 chars:


int h(char[]g)
{
	int n=99,i=-2,p=n,q=-p,r=p,v,y[]=new int[5*n];
	for(;i<13;y[n+g[++i]]++)y[" A23456789TJQK".indexOf(g[i+=2])]++;
	for(;n-->0;y[198+y[n]]=n)p=y[n]>0?n<2?n:(q=q>n?q:n)-q+(r=p<n?p:n):p;
	for(i=q-p<5|r>9?7:0;++n<99;y[297+y[99+n]]=n,y[396+y[n]]++)i&=y[n]/2-1;
	for(v=y[302]>>5;new int[]{r>9?i&v:0,i&v,y[202],y[399]&p,v,i,y[201],p-1,p,1}[99-n]<1;n--)p=y[398];
	return n;
}

So lame :stuck_out_tongue:

Better:

358 chars

int h(char[]g){
	int n=99,i=-2,p=n,q=-p,r=p,v,y[]=new int[5*n];
	for(;i<13;y[n+g[++i]]++)y[" A23456789TJQK".indexOf(g[i+=2])]++;
	for(;n-->0;y[198+y[n]]=n)q=y[n]>0&&(p=n)>1?q>(r=p)?q:n:q;
	for(i=q-p<5|r>9?7:0;++n<99;y[297+y[99+n]]=n,y[396+y[n]]++)i&=y[n]/2-1;
	for(v=y[302]>>5;new int[]{r>9?i&v:0,i&v,y[202],y[399]&p,v,i,y[201],p-1,p,1}[99-n]<1;n--)p=y[398];
	return n;
}

Just so happens that p is never less than n. (in the 2nd loop)

I stared and stared and stared and I can neither reduce FizzBuzz (how did you do it Riven?!?) nor this ‘h’ method.

If you post your FizzBuzz solution, I might give you a few hints.

I WILL NOT BE DENIED


http://i.imgur.com/iFXdUkB.png

Just give me time… and money. Mostly money, that’d be nice.

Just enough to bribe someone at Oracle to put an easteregg function in the stdlib. Then wait until next release.

Code like this gets people fired, and rightly so!

Or they realize they can’t fire you!

Screwing up occasionally? You get fired.
Screwing up consistently? You’ve got job security.

Yay! I matched Riven’s score on FizzBuzz. ;D

Edit: CRAP. I matched BurntPizza.

I hate you all.

My solution:


class S{public static void main(String[]a){for(int i=0;++i<101;)System.out.println(i%3<1?i%5<1?"FizzBuzz":"Fizz":i%5<1?"Buzz":i);}}

EDIT: Aha, I just figured out I could use <1 instead of ==0, new score of 6.70!
EDIT2: Just shaved off another character: 6.80!

Hint: You can cut off a few characters by switching the logic and using > instead of ==.

Hah, I just realized that right before you posted it ;D

Different algorithm - not sure how to count but this is about 40 chars fewer than the most recent one. Possibly buggy but handles the official test data so this way seems viable at least.

About 320:


int h(char[]g) {
  int i=0,f=0,k=0,s=0,p=0,t=0,q=0,n=0;
  for(;i<17;i++){n=0;for(char x:g)if(x=="A23456789TJQKCDHS".charAt(i))n++;
  if(i<13){if(n>0&&i==12)k++;if(n==1)s++;else if(s<5)s=1;if(n==2)p++;if(n==3)t++;if(n==4)q++;}
  else if(n==5)f=1;}if(s<5)s=0;for(i=0;new int[]{f&s&k,f&s,q,t&p,f,s,t,p-1,p,1}[i]<=0;i++);
  return 99-i;
}

Now I feel all dirty :stuck_out_tongue: