• (cs)

    (2 + 2) - (16 / 4) + 1 = Frist!

  • (cs)

    Wasn't Krypto Superman's dog?

  • St.Pepper (unregistered) in reply to Charleh
    Charleh:
    16

    Fail!

  • Danj (unregistered)

    This sounds rather similar to the "numbers game" in the British game show Countdown (more details on Wiki at http://en.wikipedia.org/wiki/Countdown_(game_show)#Numbers_round).

  • Michael Mol (unregistered)

    Once you've solved these on your own, check out Rosetta Code to see examples of a "24" game and a player for such in a variety of languages.

    Again, don't check it out until you've done it yourself, or you spoil much of the purpose of this blog post...

    http://rosettacode.org/wiki/24_game http://rosettacode.org/wiki/24_game/Solve

    (Disclaimers: Yes, it's my site. No, I didn't write that code. No, I'm not participating in writing one for this blog post; I've already seen other people solve it in a couple dozen languages. I just thought some of the coder geeks around here might fine it interesting.)

  • CrazyBomber (unregistered)

    For some reason, this reminds me of Alex Zane's games...

  • Spivonious (unregistered)

    No offense, but you were a major nerd :)

  • Ziplodocus (unregistered)

    I think the real WTF is that Alex had friends...

  • (cs)

    Wow. Just . . . wow.

    I never played these card games, but I thought I was the only one who would take a series of numbers from some random place (could be anything -- license plates, telephone numbers, SSNs, etc.) and try to insert mathematical symbols to make the preceding numbers have a total of the last digit (or last couple of digits, whatever worked). To find that there's actually a card game for this . . . I wouldn'ta thunk it.

  • (cs) in reply to St.Pepper
    St.Pepper:
    Charleh:
    16

    Fail!

    BODMAS?

  • Cardshark (unregistered)

    The other RWTF is that the red-suit cards are printed in black.

  • (cs) in reply to Danj
    Danj:
    This sounds rather similar to the "numbers game" in the British game show Countdown

    First of all, let's remember that 'Countdown' is itself based on the French game show 'Des Chiffres Et Des Lettres.' :)

    Also, the Countdown numbers game is somewhat different, though I agree that Krypto (and yes that IS the name of Superman's dog) has some basic similarities.

    Countdown's game has a random three-digit 'target,' and one chooses from two set of numbers: one set is 25, 50, 75, and 100; the other set is two lots of the numbers 1 through 10. You can choose from one to four 'big' numbers, which are made up to a total of six numbers by random picks from the 'small numbers.'

    (And since all non-UK readers have already dozed off ;), did you know that TWO large numbers is the choice that gives the best chance of a solution existing? Check out this site: http://www.crosswordtools.com/numbers-game/)

  • pete (unregistered) in reply to Danj
    Danj:
    This sounds rather similar to the "numbers game" in the British game show Countdown (more details on Wiki at http://en.wikipedia.org/wiki/Countdown_(game_show)#Numbers_round).

    I thought the same I wrote a solver for countdown (letters and numbers games) in J2ME many many years ago (when that was all the rage), wonder where it is.

  • pete (unregistered) in reply to Cad Delworth
    Cad Delworth:
    Danj:
    This sounds rather similar to the "numbers game" in the British game show Countdown

    First of all, let's remember that 'Countdown' is itself based on the French game show 'Des Chiffres Et Des Lettres.' :)

    Also, the Countdown numbers game is somewhat different, though I agree that Krypto (and yes that IS the name of Superman's dog) has some basic similarities.

    Countdown's game has a random three-digit 'target,' and one chooses from two set of numbers: one set is 25, 50, 75, and 100; the other set is two lots of the numbers 1 through 10. You can choose from one to four 'big' numbers, which are made up to a total of six numbers by random picks from the 'small numbers.'

    (And since all non-UK readers have already dozed off ;), did you know that TWO large numbers is the choice that gives the best chance of a solution existing? Check out this site: http://www.crosswordtools.com/numbers-game/)

    There are a couple of other differences, in countdown any divisions can't be fractions so you can't do (9/2) + 1 = 5.5 * 10 = 55 and in countdown not all numbers must be used.

  • Toon (unregistered)

    The only solution I can think of, off the top of my head, involves recursion. And so I can't do the Easy solution, I have to do Medium or better. Is there something I'm missing here?

  • Dennis (unregistered)

    For an extra challenge, assign units to the suits and require that the units in the result have to be correct.

  • Scotty (unregistered) in reply to Ziplodocus
    Ziplodocus:
    I think the real WTF is that Alex had friends...

    Quite right Ziplodocus. This smacks of another WTFiction.

  • Alex (unregistered) in reply to Toon
    Toon:
    The only solution I can think of, off the top of my head, involves recursion. And so I can't do the Easy solution, I have to do Medium or better. Is there something I'm missing here?
    You can do Medium, but not easy ?!
    def Medium(blahblah):
        #Do your stuff
        return [solution]
    
    def Easy(blahblah):
        return Medium(blahblah)[0]
    

    I'm a little disappointed in you...

  • Brent (unregistered)

    We played this in grade 4, only we also used the face cards.

  • St.Pepper (unregistered) in reply to Charleh
    Charleh:
    St.Pepper:
    Charleh:
    16

    Fail!

    BODMAS?

    Please tell what set of cards contains numeric values above 10.

  • Anonymous (unregistered) in reply to St.Pepper
    St.Pepper:
    Please tell what set of cards contains numeric values above 10.
    All of them. The ace is worth 11 in many card games and all packs have 4 aces, so...
  • Brent (unregistered) in reply to St.Pepper
    St.Pepper:
    Charleh:
    St.Pepper:
    Charleh:
    16

    Fail!

    BODMAS?

    Please tell what set of cards contains numeric values above 10.

    Tarot. The Major Arcana are numbered in a proper deck... 16 would be The Tower.

  • (cs)

    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

  • JimBoB (unregistered)

    Messy thrown together javascript:

    <script type="text/javascript">
      var operators=["+","-","*","/"];
    
      function playGame(numbers){
    
        for(var i=0;i<math.pow(4,numbers.length-2);i++){ var="" expression="numbers[0];" for(var="" j="1;j<numbers.length-1;j++){" expression+="operators[Math.floor(i/Math.pow(4,j-1))%4]+numbers[j];" }="" var="" result="eval(expression);" if(result="=numbers[numbers.length-1]){" document.write(expression="" +"="+result+" <br="">");
          }
        }
      }
    
      playGame([1,2,3,4,5,6,7,8,9]);
    </script>
    </math.pow(4,numbers.length-2);i++){>

    Doesn't handle parentheses, but oh well.

  • (cs) in reply to Evo
    Evo:
    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

    My puzzle: 3 7 9 9

  • tentative (unregistered)

    3 * (7 + 9 / 9) = 24

    Sorry for the newb question, but why would I want to do this elementary coding exercise?

  • Anonymous (unregistered) in reply to tentative
    tentative:
    3 * (7 + 9 / 9) = 24

    Sorry for the newb question, but why would I want to do this elementary coding exercise?

    Are you setting up for a joke? OK, I'll bite:

    "I don't know, why would you want to do this elementary coding exercise?"

    ...

  • (cs) in reply to tentative
    tentative:
    3 * (7 + 9 / 9) = 24

    Sorry for the newb question, but why would I want to do this elementary coding exercise?

    Ahh, damn it. I missed that solution. My intended solution was (9*7+9)/3...

    And why you would want to do the exercise? No idea. I've always wondered why it exists on this site. It doesn't fit, imho.

  • tentative (unregistered) in reply to Anonymous

    I knew it! So this site has another side, huh? Is it worth 10 minutes of coding to get there?

  • Not him. (unregistered) in reply to Evo
    Evo:
    tentative:
    3 * (7 + 9 / 9) = 24

    Sorry for the newb question, but why would I want to do this elementary coding exercise?

    Ahh, damn it. I missed that solution. My intended solution was (9*7+9)/3...

    And why you would want to do the exercise? No idea. I've always wondered why it exists on this site. It doesn't fit, imho.

    It fits to the extent that the intent of the site is to improve code and highlight particularly bad and to-be-avoided practices

  • (cs)

    "Dammit Chloe, where's that access code?!"

    Whoops, wrong "24".

  • Syntax (unregistered)

    Here's an excellent clip of Countdown where the guy solves the numbers round in amazing fashion... Who'd have thought it was possible :)

    http://www.youtube.com/watch?v=pfa3MHLLSWI

  • wtf (unregistered)

    Presumably not all of the readers of this site are super-genius coders like (ahem) you and I. Maybe there's people who haven't already solved every problem there is reading this. I know, it's terrible, you're associated with "noobs" just by reading a site that they're allowed to read. Sorry.

  • Brent (unregistered) in reply to tentative
    tentative:
    but why would I want to do this elementary coding exercise?

    Because small hacks in joke languages like Intercal can be fun, but writing real applications in Intercal is not.

    Also, if you happen to be learning or want to learn a new language, small problems are a good way to jump in and get your feet wet. Starting with a real application as your first project in an unfamiliar language leads to the types of things we see regularly on this site.

  • Buddy (unregistered)

    Partial solution in C++:

    • Plays 24
    • Allows any number of cards as input
    • Outputs as RPN
    • Does NOT filter out equivalent solutions

    Assumptions:

    • Input will be valid
    • Operations are done via floating point
    • As per standard rules, can reorders cards

    To use, compile as "_24" and echo the cards or enter from console:

    echo '3 3 3 3' | ./_24 3 3 * 3 * 3 -

    echo '7 8 9 7 1' | ./_24 8 7 / 1 + 7 * 9 + 8 9 + 7 / 1 + 7 * 9 7 / 1 + 7 * 8 + 9 7 - 8 * 1 + 7 + 9 7 - 8 * 7 + 1 + 9 8 + 7 / 1 + 7 *

    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    #include <math.h>
    
    #define GOAL		24.0
    #define TOLERANCE	0.0000001
    
    enum {ADDITION, SUBTRACTION, MULTIPLY, DIVIDE, OPERATORS};
    
    int main(void)
    {
    	vector<int> input;
    
    	while (!cin.eof())
    	{
    		int element;
    		cin >> element;
    		if (cin.good())
    			input.push_back(element);
    	}
    
    	sort(input.begin(), input.end());
    
    	int size = input.size();
    
    	long count = pow(size - 1, OPERATORS);
    
    	stringstream output;
    
    	do
    	{
    		for (long n = 0; n < count; n++)
    		{
    			long working = n;
    
    			vector<int>::iterator it = input.begin();
    
    			double accumulator = *it;
    
    			output << *it;
    
    			for (it++; it < input.end(); it++)
    			{
    				output << ' ' << *it;
    				double d = *it;
    
    				int operation = working % OPERATORS;
    
    				switch (operation)
    				{
    					case ADDITION:
    						accumulator += d;
    						output << " +";
    						break;
    
    					case SUBTRACTION:
    						accumulator -= d;
    						output << " -";
    						break;
    
    					case MULTIPLY:
    						accumulator *= d;
    						output << " *";
    						break;
    
    					case DIVIDE:
    						accumulator /= d;
    						output << " /";
    						break;
    				}
    
    				working /= OPERATORS;
    			}
    
    			if (fabs(accumulator - GOAL) < TOLERANCE)
    				cout << output.str() << '\n';
    
    			output.str("");
    		}
    	}
    	while (next_permutation(input.begin(), input.end()));
    
    	return 0;
    }
    
  • Go Figure (unregistered) in reply to Evo
    Evo:
    Evo:
    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

    My puzzle: 3 7 9 9

    (7*9+9)/3

  • cellocgw (unregistered) in reply to Evo
    Evo:
    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

    OK, but first: bonus points for someone who can define "hardest" in this context.

  • usitas (unregistered)

    public static void main (String[] args) { System.out.println("42"); }

  • Spellcheck (unregistered) in reply to Cardshark

    What about the url?

    http://thedailywtf.com/Articles/Krytpo-and-24.aspx

  • Leonard (unregistered)
    Our goal was to race to see who could make a mathematical equation using only the four basic arithmetic expressions and parenthesis.
    Wow Sheldon you are such a geek! No wonder you can't even get Irish Girl to appear on your site any more.
  • Peter (unregistered) in reply to wtf
    wtf:
    Presumably not all of the readers of this site are super-genius coders like (ahem) you and I.
    Ahem. You and me.
  • unekdoud (unregistered)

    I tried this once. Failed because the code couldn't solve 2,7,7,10 for 24.

    Hint/Spoiler: Problem difficulty may increase severalfold at this point, depending on what language you're using.

  • Somebody (unregistered)

    Bonus points to whoever can find all problems that have only one non-duplicated solution.

  • (cs) in reply to Peter

    Ahem, 'me and you' or 'you and I'.

  • Buddy (unregistered) in reply to unekdoud
    unekdoud:
    I tried this once. Failed because the code couldn't solve 2,7,7,10 for 24.

    Hint/Spoiler: Problem difficulty may increase severalfold at this point, depending on what language you're using.

    Using my submission got:

    10 7 / 2 + 7 *

    Which translates in standard bracketed notation to:

    (10 / 7 + 2) * 7 = 24

  • (cs) in reply to cellocgw
    cellocgw:
    Evo:
    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

    OK, but first: bonus points for someone who can define "hardest" in this context.

    my abs

  • usitas (unregistered) in reply to chikinpotpi
    chikinpotpi:
    cellocgw:
    Evo:
    Booooooooooooooooooooooooooooring.

    Though I like the 24 game... Bonus points for the person who can come up with the hardest 24 game puzzle.

    OK, but first: bonus points for someone who can define "hardest" in this context.

    my ab

    FTFY

  • Machtyn (unregistered)

    My high school girlfriend and I would play this game on occasion. She introduced it to me. She was awesome, valedictorian in HS, top honors at her engineering program at a major university (she was #1 or 2 of her class), and she's currently married and a stay-at-home mom... she is awesome.

  • Trevel (unregistered)

    My prefered variant is with seven dice, two are different colours. Roll 'em. The two become a two-digit number, the other five are used to try to make it.

  • YeahRight (unregistered) in reply to Machtyn
    Machtyn:
    My high school girlfriend and I would play this game on occasion. She introduced it to me. She was awesome, valedictorian in HS, top honors at her engineering program at a major university (she was #1 or 2 of her class), and she's currently married and a stay-at-home mom... she is awesome.

    Win for CREEEEEEEPY.

Leave a comment on “Krypto and 24”

Log In or post as a guest

Replying to comment #:

« Return to Article