Skip to content

Na'an⚓︎

Difficulty:
Direct link: https://nannannannannannan.com

Objective⚓︎

Request

Shifty McShuffles is hustling cards on Film Noir Island. Outwit that meddling elf and win!

Shifty McShuffles

Hey there, stranger! Fancy a game of cards? Luck's on your side today, I can feel it.
Step right up, test your wit! These cards could be your ticket to fortune.
Trust me, I've got a good eye for winners, and you've got the look of luck about you.
Plus, I'd wager you've never played this game before, as this isn't any ordinary deck of cards. It's made with Python.
The name of the game is to bamboozle the dealer.
So whad'ya think? Are you clever enough?

Hints⚓︎

Stump the Chump

From: Shifty McShuffles

Try to outsmart Shifty by sending him an error he may not understand.

The Upper Hand

From: Shifty McShuffles

Shifty said his deck of cards is made with Python. Surely there's a weakness to give you the upper hand in his game.

Solution⚓︎

Food Cravings Ahead

Looking at the title of this challenge for too long will instill a strong desire for Indian cuisine. I, for my part, now could murder a curry.

In this card game, we and our opponent Shifty each label 5 cards with numbers from 0 to 9. Cards with the same value cancel each other. The player with the highest remaining number gets a point, as does the player with the lowest remaining number. First one to reach 10 points wins the game.

Our strategy is to label the cards with 0,1,2,3 and "nan". ("nan" in Python is a numeric data type used to represent an undefined value.)

What happens is that Shifty will also choose a "0", "1" and possibly "2", so the cards with the lowest number cancel each other. Yet our "nan" card trumps Shifty's highest card (invariably a "9"), and we gain one point.

Choosing 0,1,2 and 3 ensures that Shifty cannot get a point for the lowest uncancelled card, unless he chooses 0,1,2,3,4. But this never seems to happen.

Rinse, repeat 9 times, and we have won the game.

Why?⚓︎

Why does this work?

We do not have access to the server-side source code, but got the information that it is written in Python.

We may assume that the code

  • transforms our input from string to float using float()
  • checks whether the resulting number is <0 or >9.

The string "nan" will pass these tests. "nan" is a valid floating point number value in Python. Every numerical comparison with nan will return False. So, (nan < 0) is False, as is (nan > 9), and nan passes the test.

This certainly depends very much on the implementation details; had the test been (x>=0 and x<=9), nan would have not passed.

Then, our highest number is compared to Shifty's highest. Again, we must make learned guesses on the inner workings of the code:

  • The number of each player are put in a list "n", and that list is sorted using "n.sort()". This happens to puts a "nan" at the high end.
  • The highest number in each player's list are compared using code along the lines
            if n_shifty[4] > n_player[4]:
                    # Shifty scores
            elif n_shifty[4] == n_player[4]:
                    # Tie, no one scores
            else:
                    # Player scores
    
    Important is that the default path is that "we" win - all numerical comparison against "nan" done before will result in "False".

Where does Shifty cheat?

I fail to see where it is Shifty that does the cheating.

Images⚓︎

nan1

nan2

Answer

After solving the challenge, the fact will be listed as an "Achievements" in the player's badge.

Response⚓︎

Shifty McShuffles

Well, you sure are more clever than most of the tourists that show up here.
I couldn't swindle ya, but don't go telling everyone how you beat me!
An elf's gotta put food on the table somehow, and I'm doing the best I can with what I got.