re: Write better code: Day 2 - Single Riffle Shuffle VIEW POST


Logic was to get the shuffled deck and check if the last card in shuffled deck belongs to the top of half 1 of half 2.

-do while loop until shuffled deck is empty.
-pick a card from the shuffled deck - check if it's the top card of half 1 or half2.
-if it matches top of half1 - pop it from half1, pop from deck.
-else if is top of half2, repeat.
-if the card does not match the top of either halves, it's not a single shuffle.


I think I could improve this. I am not sure yet what the complexity of using pop is.
If its always O[1] then this logic is good. But anyhow since the max deck of cards is always 52, change in performance wont make much difference even with better code than this.

code of conduct - report abuse