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
?
[quote]AC 8C QA JH TC: high card
AC 8C QA JH TC: one pair
Exception in thread “main” java.lang.IllegalStateException
at Poker.main(Poker.java:39)
[/quote]
[quote=“richierich,post:60,topic:47415”]
Cant you omit the “=0” when declaring the int “n”? n gets defined anyways at the beginning of the for loop.
[/quote]
Lol, OK actually in my test data I “fixed” the invalid card QA! Not sure why you got an IllegalStateException though - when I run it it just reports the QA hand as a pair because of 2 'A’s (which is wrong of course).
Do we actually have to handle invalid inputs, or just that particular odd one? My solution definitely has other bugs if it has to handle anything.
Yep looks like it - nice one!
Changed that ‘QA’ (lol, can’t believe we didn’t see that) to a ‘QS’:
Passed the initial battery, but the permutation generator is the real test, which it failed quickly:
[quote]AH 3H 4H 5H 6H
Riven: flush
Richy: straight flush
[/quote]
Made a more “extensible” test framework using Riven’s permutation gen with our 3 submissions:
http://pastebin.java-gaming.org/0a2155d9e0717
EDIT: fixed duplicate test
Ah cool - didn’t see the permutation tester
This version gets much further, and is a few characters longer, 325 or 330 I think.
int h(char[]g) {
int i=0,f=0,r=0,s=0,p=0,t=0,q=0,n;
for(;i<18;i++){n=0;for(char x:g)if(x=="A23456789TJQKACDHS".charAt(i))n++;
if(i<14){if(n==1){s++;if(i==13&&s==5)r=1;}else if(s<5)s=0;
if(i<13){if(n==2)p++;if(n==3)t++;if(n==4)q++;}}
if(n==5)f=1;}s=(s<5)?0:1;for(i=0;new int[]{f&s&r,f&s,q,t&p,f,s,t,p-1,p,1}[i]<=0;i++);
return 99-i;
}
Reaches this:
2/52, 3/52
Exception in thread "main" 2H 3H 4H 5H 6H
Riven: royal flush
Richy: straight flush
Which seems like a good time to quit for the night
Will try out the new test framework tomorrow…
I don’t know which version of Riven’s you’re testing against, but that’s definitely a straight flush, and your new code verifies successfully on the tester. Congratz!
EDIT: golf’d it a bit, was 325, now 304. No algorithmic changes.
int h(char[]g){
int i=-1,f=0,r=0,s=0,p=0,t=0,q=0,n;for(;i++<17;){n=0;
for(int x:g)if(x=="A23456789TJQKACDHS".charAt(i))n++;
s=i<14&n>0?s==4&i==13?s+(r=1):s+1:s<5?0:s;
if(i<13){if(n==2)p++;if(n==3)t++;if(n==4)q++;}f=n==5?1:f;}
s=s<5?0:1;for(i=0;new int[]{f&s&r,f&s,q,t&p,f,s,t,p-1,p,1}[i]<=0;i++);
return 99-i;
}
Yay i also achived 7.0.
I would be interested in seeing how our implementations differ…
my solution:
class S{public static void main(String[]a){for(int i=0;i<100;)System.out.println((++i%3<1?"Fizz":"")+(i%5>0?i%3>0?i:"":"Buzz"));}}
- new int[]{...}[i]<=0
+ new int[]{...}[i]<1
- s=s<5?0:1;for(i=0;new int[]{f&s&r,f&s,q,t&p,f,s,t,p-1,p,1}[i]<1;i++);
+ s=s<5?0:1;for(i=0;new int[]{f&s&r,f&s,q,t&p,f,s,t,p-1,p,1}[i++]<1;);
I don’t think it would take many changes to get something which can be posted to http://codegolf.stackexchange.com/questions/6494/name-the-poker-hand
@moogie
You’re just going to give away the answer like that?
I actually feel kind of dumb because I had that solution (a thing or two moved around) for the longest time (the 6.3 pt solution), but simply didn’t realize the class didn’t have to be named ‘Solution’ like many of the other challenges. :emo:
yep
it frustrated me that I could not look at other submissions to see if there is any other “tricks” I could utilise! I try to share my insights to help others avoid similar frustration.
[quote=“moogie,post:73,topic:47415”]
That’s kind of the point
Pretty sure that configuration is optimal, a few things can be switched, e.g. where i is incremented, etc.