Comment On Krypto and 24

As a kid, I was never a fan gambling away my hard-earned allowance. Heck, even playing poker with M&M’s meant that maybe — just maybe — I’ll walk away with less chocolate than I came to the table with, and that was an anxiety worth not experiencing. Fortunately, I’ve since come to my senses, but I’ll never forget the game my risk-averse friends and I would play when we came across a deck of playing cards. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Krypto and 24

2010-05-05 09:05 • by Charleh
(2 + 2) - (16 / 4) + 1 = Frist!

Re: Krypto and 24

2010-05-05 09:17 • by MiffTheFox
Wasn't Krypto Superman's dog?

Re: Krypto and 24

2010-05-05 09:18 • by St.Pepper (unregistered)
307648 in reply to 307646
Charleh:
16


Fail!

Re: Krypto and 24

2010-05-05 09:22 • by 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).

Re: Krypto and 24

2010-05-05 09:30 • by 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.)

Re: Krypto and 24

2010-05-05 09:32 • by CrazyBomber (unregistered)
For some reason, this reminds me of Alex Zane's games...

Re: Krypto and 24

2010-05-05 09:32 • by Spivonious (unregistered)
No offense, but you were a major nerd :)

Re: Krypto and 24

2010-05-05 09:33 • by Ziplodocus (unregistered)
I think the real WTF is that Alex had friends...

Re: Krypto and 24

2010-05-05 09:34 • by nonpartisan
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.

Re: Krypto and 24

2010-05-05 09:36 • by Charleh
307657 in reply to 307648
St.Pepper:
Charleh:
16


Fail!


BODMAS?

Re: Krypto and 24

2010-05-05 09:37 • by Cardshark (unregistered)
The other RWTF is that the red-suit cards are printed in black.

Re: Krypto and 24

2010-05-05 09:38 • by Cad Delworth
307659 in reply to 307649
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/)

Re: Krypto and 24

2010-05-05 09:39 • by pete (unregistered)
307660 in reply to 307649
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.

Re: Krypto and 24

2010-05-05 09:47 • by pete (unregistered)
307661 in reply to 307659
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.

Re: Krypto and 24

2010-05-05 09:49 • by 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?

Re: Krypto and 24

2010-05-05 09:54 • by Dennis (unregistered)
For an extra challenge, assign units to the suits and require that the units in the result have to be correct.

Re: Krypto and 24

2010-05-05 10:02 • by Scotty (unregistered)
307664 in reply to 307655
Ziplodocus:
I think the real WTF is that Alex had friends...



Quite right Ziplodocus. This smacks of another WTFiction.

Re: Krypto and 24

2010-05-05 10:08 • by Alex (unregistered)
307665 in reply to 307662
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...

Re: Krypto and 24

2010-05-05 10:10 • by Brent (unregistered)
We played this in grade 4, only we also used the face cards.

Re: Krypto and 24

2010-05-05 10:12 • by St.Pepper (unregistered)
307668 in reply to 307657
Charleh:
St.Pepper:
Charleh:
16


Fail!


BODMAS?


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

Re: Krypto and 24

2010-05-05 10:16 • by Anonymous (unregistered)
307669 in reply to 307668
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...

Re: Krypto and 24

2010-05-05 10:32 • by Brent (unregistered)
307670 in reply to 307668
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.

Re: Krypto and 24

2010-05-05 10:35 • by Evo
Booooooooooooooooooooooooooooring.

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

Re: Krypto and 24

2010-05-05 10:42 • by 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>


Doesn't handle parentheses, but oh well.

Re: Krypto and 24

2010-05-05 10:43 • by Evo
307674 in reply to 307671
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

Re: Krypto and 24

2010-05-05 10:50 • by tentative (unregistered)
3 * (7 + 9 / 9) = 24

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

Re: Krypto and 24

2010-05-05 10:56 • by Anonymous (unregistered)
307677 in reply to 307675
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?"

...

Re: Krypto and 24

2010-05-05 10:57 • by Evo
307678 in reply to 307675
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.

Re: Krypto and 24

2010-05-05 11:12 • by tentative (unregistered)
307679 in reply to 307677
I knew it!
So this site has another side, huh?
Is it worth 10 minutes of coding to get there?

Re: Krypto and 24

2010-05-05 11:15 • by Not him. (unregistered)
307680 in reply to 307678
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

Re: Krypto and 24

2010-05-05 11:26 • by WhiskeyJack
"Dammit Chloe, where's that access code?!"

Whoops, wrong "24".

Re: Krypto and 24

2010-05-05 11:27 • by 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

Re: Krypto and 24

2010-05-05 11:29 • by 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.

Re: Krypto and 24

2010-05-05 11:43 • by Brent (unregistered)
307686 in reply to 307675
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.

Re: Krypto and 24

2010-05-05 11:43 • by 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;
}

Re: Krypto and 24

2010-05-05 11:47 • by Go Figure (unregistered)
307688 in reply to 307674
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

Re: Krypto and 24

2010-05-05 12:13 • by cellocgw (unregistered)
307690 in reply to 307671
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.

Re: Krypto and 24

2010-05-05 12:18 • by usitas (unregistered)
public static void main (String[] args)
{
System.out.println("42");
}

Re: Krypto and 24

2010-05-05 12:33 • by Spellcheck (unregistered)
307694 in reply to 307658
What about the url?
> http://thedailywtf.com/Articles/Krytpo-and-24.aspx

Re: Krypto and 24

2010-05-05 12:43 • by 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.

Re: Krypto and 24

2010-05-05 12:45 • by Peter (unregistered)
307698 in reply to 307685
wtf:
Presumably not all of the readers of this site are super-genius coders like (ahem) you and I.

Ahem. You and me.

Re: Krypto and 24

2010-05-05 12:47 • by 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.

Re: Krypto and 24

2010-05-05 12:50 • by Somebody (unregistered)
Bonus points to whoever can find all problems that have only one non-duplicated solution.

Re: Krypto and 24

2010-05-05 12:50 • by Flatline
307701 in reply to 307698
Ahem, 'me and you' or 'you and I'.

Re: Krypto and 24

2010-05-05 12:54 • by Buddy (unregistered)
307702 in reply to 307699
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

Re: Krypto and 24

2010-05-05 12:55 • by chikinpotpi
307703 in reply to 307690
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

Re: Krypto and 24

2010-05-05 13:03 • by usitas (unregistered)
307705 in reply to 307703
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

Re: Krypto and 24

2010-05-05 13:47 • by 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.

Re: Krypto and 24

2010-05-05 14:08 • by 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.

Re: Krypto and 24

2010-05-05 14:12 • by YeahRight (unregistered)
307709 in reply to 307707
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.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment