Solving Math Puzzles with data.tree 2


I got a note from Karim Lahrichi, who even thinks about math when he’s supposed to be drinking beer. The bar puzzle they were trying to solve goes like this: Using all of the numbers 1, 3, 4, 6 exactly once, and any combination of: addition, subtraction, multiplication and division (and parenthesis to group operations however you like), arrive at the number: 24.

Sounds easy, right? Until you try to find the answer…

Luckily, he remembered the puzzle the next morning, and had a systematic go at it. He used data.tree to do a brute force solution. Read all about it on RPubs.

Based on his code, it would also be straight forward to answer such world-shaking questions as: how many different ways to combine the numbers are there? Is there more than one solution to the puzzle? If yes, how many? Why are we looking for 24, shouldn’t we rather be looking for 42?

Anyway, if you like that sort of thing, make sure you check out this post too: solving Tic-Tac-Toe.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 thoughts on “Solving Math Puzzles with data.tree

  • Karim L

    Funny I was thinking about this kind of stuff while walking to the metro this morning, I think I’ll expand my code to find groups of “interesting” numbers, i.e. numbers for which there’s apparently a unique solution (so that I can ruin any party). There’s a lot in the package I haven’t explored yet, will be re-reading the superb vignette.