« first day (6 days earlier)      last day (28 days later) » 

12:43 AM
Current Weekend Challenge: Poker Hand Evaluation
 
Feel free to go overboard all you want!!
 
 
2 hours later…
2:25 AM
And ... I'm going to bed.... I'll stew on it.
 
 
4 hours later…
6:29 AM
Ready to post :)
 
6:50 AM
Posted :D
 
0
Q: Poker Hand Evaluator Challenge

retailcoderThis week's review challenge is a poker hand evaluator. I started by enumerating the possible hands: public enum PokerHands { Pair, TwoPair, ThreeOfKind, Straight, Flush, FullHouse, FourOfKind, StraightFlush, RoyalFlush } Then I thought I was going to need c...

 
 
4 hours later…
11:03 AM
@retailcoder You're done already? WTF?
 
 
2 hours later…
1:32 PM
@sim went a little too fast :)
 
@retailcoder I'm still struggling with my code here. I have started it but I'm not sure if I am on a good track or not.
 
1:43 PM
My code sux, I might repost at one point..
 
I haven't watched your code yet, I try to avoid that until I post my own result
 
@sim I posted the minute all tests passed... which was dumb :/
 
So either it works fine but parts of it are not good code quality, or the tests passed but you had not tested everything?
I'm quite sure I am making this code more complicated than it needs to be, but I like flexibility so :)
 
@sim The bar is 6-7 notches below the quality of my RPLSL solution..
 
wow
Will be very interesting to read your solution later
 
1:54 PM
Lol yeah I coded crap
 
Well, at least it works
I don't even have a working solution yet
 
I just rushed delivery so I would post before @rolfl would post his :)
@SimonAndréForsberg oh sh!t, I only accounted for the [Ace] as a 14... my [Straight] fails with [A-2-3-4-5]...
 
So you missed a test after all
The Fastest Gun In The West is apparently not always The Best Gun In The West.
Well, the weekend challenges are about learning things, and I guess you will learn plenty of things from this week
 
Mostly about posting good CR questions - it should really be your best possible code, after you've tried everything you could to come up with good code - akin to SO's what have you tried? ...though we can't really enforce it.
 
Yeah, I've also thought about that one. I don't think we need a "What have you tried?" but I think we might need a "What does your code do?". Sometimes people just post their code without explaining it much, if they even explain something about it at all...
 
2:11 PM
I have note yet started....
I have been burning my candles from both ends recently .... and today I am spending time 'napping' and with the kids.... mostly.
I may get to it this evening.
(so I am not looking at any solutions)
 
@rolfl Take the time you need (or they need) with your family :) The weekend challenge is not in a hurry :)
 
2:26 PM
Ugh. I shouldn't have rushed this. TBH I'm not very happy with this code, it's not my best possible code and I feel like saying "scratch that, I'll post again when it meets my quality bar" - I didn't even do a single pass of refactoring, it's really the 1st "draft"... mainly I wanted to post my solution before @rolfl posted his; and it's not a race. :/ — retailcoder 38 secs ago
I deserve a downvote or two.
 
@retailcoder Downvoted by request :)
 
@retailcoder - best lessons are learned from other people's mistakes... lessons best learned are from your own mistakes:
2
in Code Review General Room, Nov 30 at 17:51, by Simon André Forsberg
OK, for next week's challenge, I'm definitely going to think more and not get stuck in the get-it-done-fast trap
You failed to learn frm 2 people's lessons .... huh... !!! ;-)
Now, don't do it again!
 
Haha, lol! I had forgot I made that mistake last week!
 
hehe .... I down-voted it,..... but did not read it .... ;-)
 
Same here :)
 
2:34 PM
bad, bad, bad CR etiquette
 
lol
Well, at least we did it on request. So I'd say it's good etiquette.
 
@rolfl lesson learned! And very well said / starred :)
 
2:58 PM
Yay, first tests passed!
Not checking everything yet though. Gotta add more tests. And more checks. Still not checking for straight for example.
 
3:14 PM
@sim hint: if you're checking all hands individually, some checks will be redundant :)
 
@retailcoder I know. I think I avoid that quite good.
I do, however, want my code to be quite flexible, which sometimes does not go hand in hand with avoiding redundancy..
Gotta eat now, will implement straight checks later.
 
4:00 PM
OK, time to check for straights!
 
4:40 PM
2
Q: Proposals for Weekly Challenge topics

Simon André ForsbergTo decide which subjects we should cover in the Code Review Weekend Challenges I am creating this meta-question. Propose one challenge per answer. The answer with the most up-votes each week gets chosen as the weekend challenge. (Answers containing already finished challenges is disregarded in c...

Added a note about the get-it-done-fast trap
 
 
1 hour later…
5:51 PM
@SimonAndréForsberg Ugh getting that straight straight is fun eh?!
 
@retailcoder Your pun was funnier.
getting a straight straight....
 
:)
@SimonAndréForsberg I think I messed up with my enum-based CardNominalValue - works for aces high, but aces low can't be in the enum because it would break my CardDeck class (not published)... and it wouldn't make sense anyway. I think.
 
@retailcoder In that case it sounds like you're screwed! :P
I have the Ace High & Low thing working fine I believe
 
nanananah - if there's a will, there's a way.
 
I just gotta straighten out these straights...
 
6:11 PM
@SimonAndréForsberg I'm trying to make mine work with an unknown number of cards, i.e. IsStraight=*HasAnyFiveConsecutiveCards*. B!tch and a half.
 
@retailcoder I'm also trying to work with an unknown number of cards, and find the best PokerHand out of them
PokerHand = 5-card poker hand
to make it work with Texas Hold'em for example
 
Me too :)
 
Also, to make things even worse for me, I want to support wildcards as well. And that's where things are starting to go not so straight ahead anymore for the straights...
For example: 2, 3, WILDCARD, 5, 6 should be a straight... Right now, it's not :P
 
6:27 PM
@SimonAndréForsberg I thought of including jokers at first, but I changed my mind. Do casinos allow wildcards?
 
@retailcoder I have no idea, but I know some video-game poker programs that do. Although I have never seen it combined with more than five cards.
 
@SimonAndréForsberg then you might as well go all the way and have a random wildcard that changes with each deal! :D
 
@retailcoder Lol, well... Let's not overdo it, shall we? :P
For now, only jokers are wild.
I'm having enough problems straightening things out already...
 
I got the ace high / ace low straight now. Damn I'm struggling more than I thought I'd be on that one!!
Hi @Jamal!
 
Hi! I've updated the tag wiki to refer to the new Meta post, which I mentioned this room second (as secondary). It seems better for the main location of problem submission to be Meta rather than chat (but the challenge can still be pinned here).
 
6:36 PM
Good!
@Jamal So you're not dating the tag wiki anymore? (nice typo :)
 
Yes, I meant updated. :-P (I've edited it twice already, so I suppose you're not entirely wrong...)
 
Good work, Jamal
OK, I'm seriously considering changing approach to this method to a slower variant since I can't get this method to work correctly.
 
I somehow wish I'd still have that VB6 code from 10 years ago somewhere...
 
6:54 PM
@retailcoder Be careful what you wish for.
 
@SimonAndréForsberg yeah, well, that code is long lost. And wouldn't be applicable anyway - I remember it was a hard-coded 5-cards hand.
 
And it probably looked like codecrap as well?
Violà, changed approach and now that method is working.
@retailcoder Have you considered the case where you have 10 cards, and 5 of those give you a straight and the other five give you a flush? What would your code return then? (Not a straight flush I hope)
 
@SimonAndréForsberg I'll test that and return result; :)
@SimonAndréForsberg wow you just broke my IsFlush()... I definitely need more tests...
 
@retailcoder I had a feeling about that :) I have thought about the problem but don't have a solution for it yet
 
Fixed IsFlush(): return Suits(cards).Any(suit => suit.Count() == 5);
I think the result should be the highest winning hand then
 
7:04 PM
Yes
And Flush is better than Straight, so it should be a flush.
 
Ahem. Fixed IsFlush(): return Suits(cards).Any(suit => suit.Count() >= 5);
 
haha
return Suits(cards).Any(suit => suit.Count() >= 5); seems like a lovely statement, but such beauty does not exists in Java yet. suit => suit.Count()... is some kind of Lambda expression, right? Or what is it called?
 
Should IsFourOfKind() assume there's only 1 deck of cards in the game?
lambda indeed
 
@retailcoder Why prevent it?
Java 8 will get Lambdas I have heard (looking forward to it)
 
I've never written in .net 2.0 ever since LINQ appeared in C# :)
 
7:10 PM
Oh, it's LINQ that adds that? You make me want to code C# :P
Simon reminds himself about Visual Studio - Desire to code C# disappeared
 
@SimonAndréForsberg no, LINQ is essentially a set of extension methods on IEnumerable<T> - that's Any(), GroupBy(), Where() and many, many others.
And they mostly work with lambdas
Doesn't Java have delegates?
 
@retailcoder Not in the same way. Java have interfaces. So even though you could have the same functionality, you'd need a whole lot of code to do it.
But, Java 8 will be an improvement there.
 
Hmm so Java is more akin to COM-style event handling right?
 
The windows COMponent model. See :)
 
7:16 PM
Yeah, I guess it is. (@rolfl probably knows more about this than I do)
 
@SimonAndréForsberg back to Poker, if your game has two decks with jokers (i.e. 108 cards), and your hand is A-A-A-A-A, that should be a FourOfKind + HiCard(Ace).
 
@retailcoder My code is not dependent on how many decks there are, or what they contain.
It would say that it has Four of a kind + Ace "kicker"
 
But if your hand has 10 cards and you get A-A-A-A-A-2-2-Q-Q-Q, it should output "CHEATER!" right?
 
@retailcoder I don't have any cheater condition check.
 
RollPlayerInTar(); RollPlayerInFeathers(); NowDance();
 
7:20 PM
Don't see any reason to include cheater condition check here either. That is up to the calling methods to determine if the hand should even be possible or not.
at least that's my approach
 
So it would be FourOfKind(Ace)+FullHouse+Ace.
 
Well, a poker hand can only be 5 cards (in my code at least). So I would only return FourOfKind(Ace) + Ace. But yes, IsFullHouse (or however your code looks) would return true as well.
 
Makes sense
 
Now I gotta add more tests. I think my code works fine now. But I don't want to do the same mistakes as others have done ;)
 
7:52 PM
Saw my name pop up here.... this is why I am not writing a game at the moment:
0
A: Find elements occurring even number of times in an integer array

rolflWiki Answer - discussion of scalability. After some investigation I thought it would be interesting to publish some of the performance results I have seen.... there are some interesting observations. I have taken two algorithms, both on this page, the 200_Success one, and the rolfl one. I have ...

And I should be ** working** !!!!
 
8:14 PM
@rolfl Impressive
 
8:29 PM
Feels like my test code is longer than my main code... :P
 
@SimonAndréForsberg that means your code is well covered :)
I have like 15 tests.... doesn't feel right, but I'm somewhat sure my code works
 
@retailcoder Now you just said something! I gotta make an actual covering analysis as well!
 
cobertura?
 
If you want to...
 
@rolfl EclEmma
I need tests! Can someone give me a bunch of cards to test? @retailcoder?
 
8:44 PM
@SimonAndréForsberg DAMN! the (ding!) made me click ths [Post your Question] button!!
0
Q: Poker Hand Evaluator, take 2

retailcoderThis is following up on my previous attempt, which was admittedly done fast and not-so-well. This one is more tested, and abstracts the dirt away into an interface: public interface IPokerHandEvaluator { bool IsPair(IEnumerable<PlayingCard> cards); bool IsTwoPair(IEnumerable<PlayingCard>...

I think it's fine..
 
@retailcoder Then click "Edit", then "Delete", then continue editing? :)
 
lol
nah, I was just re-reading the last bits
@SimonAndréForsberg Don't you have a CardDeck class that you can Shuffle() and Draw() poker hands out of?
 
@retailcoder Good thinking!! (I do have such a class, didn't think about integrating it into this project :P)
a is incorrect though, you'd be surprised at how many Card-related classes I have...
 
0
Q: Poker Hand Evaluator, take 2

retailcoderThis is following up on my previous attempt, which was admittedly done fast and not-so-well. This one is more tested, and abstracts the dirt away into an interface: public interface IPokerHandEvaluator { bool IsPair(IEnumerable<PlayingCard> cards); bool IsTwoPair(IEnumerable<PlayingCard>...

 
Today's song should really be: youtube.com/watch?v=bESGLojNYSo
 
8:55 PM
lol I knew it was that song before I even clicked the link!
 
9:25 PM
Should I vote to close my first post?
 
for what reason?
(Still haven't read it btw)
 
not-working code...
it doesn't account for aces low
 
Ah
I don't know... I guess it works partially
you weren't aware of the problem at the time of posting
 
..not at the time of posting, indeed. (ignorance is bliss)
 
Maybe I will change my mind later when actually reading your question
Found a problem here. [JACK-DIAMONDS, ACE-HEARTS, 7-SPADES, 2-DIAMONDS, 2-HEARTS, 4-DIAMONDS, WILDCARD] should be three of a kind (2s), but it becomes two pair (ace + 2s)
Gotta fix this
Next challenge, let's do something a bit easier, shall we? Something that even I can't over-complicate...
 
9:46 PM
@SimonAndréForsberg I guess @rolfl's (ding! still here?) Sudoku Solver doesn't really fall in that category does it?
Looking at @radarbob's answer on the first post, I suspect upcoming weekend-challenge posts will push it to determining the winning hand out of two... — retailcoder 9 mins ago
 
Can't we just do a super-sophisticated and over-engineered Hello, World!?
2
 
lol
 
@retailcoder Since I already have a flexible tree-solving algorithm around here, I actually don't think it will be that complicated :)
 
Classes for "hello" and "world", at least.
 
@Jamal OMG.
 
9:48 PM
@Jamal Sure! I've already done a super-sophisticated Fizz-Buzz-Banana in Java a while ago, so Hello World should be the next step! (This is why I wanted to make Fizz-Buzz-Banana in another language)
 
...or would that just delve into bad code, therefore being off-topic?
 
@Jamal Naah, one class for each letter. And at least two interfaces.
The worst part is, it would actually work...
 
@Jamal Not necessarily. Of course things like what @SimonAndréForsberg has just mentioned would be, but a super-overkill implementation of Dependency Injection could eventually turn into a nice CW.
 
I have a feeling making a class for each letter would just be downvote-bait.
 
And one class for each word wouldn't?
 
9:51 PM
@retailcoder I am working I am on my work computer, I have ding! turned off.
 
It could, but two classes are better than... however many characters are in that string.
 
HELOWRD, 7. Or 8 if including space.
And don't forget the interfaces.
 
Hey Jamal, did you ever follow that 99bottlesofbeer link I put in ideone ... ?
Let's write a program that makes that 'readable'.
 
I didn't understand a bit of it. :-P
 
@retailcoder I answered a C# question ... can you please check it and curse me out if I am wrong?
0
A: Running a block of code on every interval except the first iteration

rolflInitialize the first byte, and then start the loop from 1..... You may also want to do a bit-check instead of modulo, but they may be equally fast... if (dataSize > 0) { data[0] ^= key; } for (int i = 1; i < dataSize; i++) { // Increase the key as per the algorithm if (i & 3 == 0) { ...

Or anyone else for that matter.
 
9:55 PM
Anyone brave enough to write something in Brainfuck? :P
2
 
I am not brave enough to put those four letters together online.... ;-)
Although, I think I can use that language as a euphamism..... like all you brains here should get the bugs out of your code.
 
It's not like I made up the language. :-P Okay, I created CR's tag for it, but still.
 
@Jamal >+++++++4+[>++++++<-]>++++.----.++++.*/
 
Well, that was a brained up thing to do.
 
Does that generate all the prime numbers from 2 to 1000?
 
9:59 PM
1000 is prime ?
 
Less than 1000. Whatever...
 
Did you guys know that the largest signed 32-bit value is prime?
 
Welcome, @syb0rg
2147483647 ? Really?
(Memorized that number 10 years ago)
 
It's quite an easy large prime number to remember....
 
10:01 PM
@SimonAndréForsberg Hi, that response almost seemed automated.
Haha
 
@syb0rg Trust me, it wasn't :)
 
I believe you, just coming over for a visit.
 
I was checking to see if there was a weekend challenge in the making really.
 
Wait a fe seconds
 
10:02 PM
@syb0rg Yup, there is. @retailcoder has posted his code already, and I am working on mine.
The current challenge is: Poker Hand Evaluation
 
@retailcoder first posted his broken code, then is partially broken code.....
 
The Poker Hand thing? That's what I thought it was, but I was just checking the chat logs to make sure it was it.
 
@rolfl lol.
 
@retailcoder Hi! Unfortunately, I don't program in C#. Java and C are my main languages.
 
10:04 PM
@syb0rg the current challenge will always be pinned in the starred posts list, and you can implement it in the language you want!
 
@syb0rg You can choose any language you want for the challenge :) I'm doing it in Java myself.
 
@retailcoder Thanks, I didn't notice that at first. Good tip!
 
@rolfl Thanks for instructing me to hang my browser for a couple of seconds. (I think I'll use wolframalpha to check/calculate primes for me instead)
 
 
1 hour later…
11:15 PM
5 messages deleted
 
@retailcoder My code seems to be working fine now, but perhaps I haven't added enough "equals" checks. For example, [2, 3, King, 10, 10, 12, 12] vs. [4, 5, King, 10, 10, 12, 12] should be equal in rank, right?
 
11:32 PM
@SimonAndréForsberg depends the suits of the pairs would be a tiebreaker
 
@retailcoder Why would the suits matter?
 
@SimonAndréForsberg "Just one more thing" here:
1
A: Poker Hand Evaluator Challenge

radarbobThe Design may be Incomplete The readability concern in the PokerGame class can be addressed by encapsulation instead of syntactical slight of hand. Push details down is the mantra. Addresses the concern about a fungible Dictionary by enveloping (encapsulating) it. Would a HandEvaluator class...

 
No no no, I don't want to read your code yet!
I don't want to be corrupted
 
corrupted
 
that's what I said :P
 

« first day (6 days earlier)      last day (28 days later) »