TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The answer is 2011. The question can be brute force.

156 pointsby qbonnardover 13 years ago

9 comments

barrkelover 13 years ago
This is an extended version of the numbers game on the UK TV gameshow Countdown, which is itself based off of a French gameshow (I don't know the details of it, though).<p>I had to solve this version of the problem once upon a time in a programming competition. I approached it slightly differently than this article; I implemented a RPN stack machine evaluator, and a recursive routine which permuted first over operators, then operands; the core routine looked like this:<p><pre><code> static int FindSolutions(int[] numbers, int numberIndex, int stackDepth) { int result = 0; if (stackDepth == 1) if (Evaluate(g_program.Program) == g_target) ++result; // Try the operators (all are binary here) if (stackDepth &#62; 1) { for (OpCode opCode = OpCode.Add; opCode &#60;= OpCode.Div; ++opCode) { g_program.Push(opCode); result += FindSolutions(numbers, numberIndex, stackDepth - 1); g_program.Pop(); } } if (numberIndex &#60; numbers.Length) { // Try each number for (int i = numberIndex; i &#60; numbers.Length; ++i) { Swap(numbers, numberIndex, i); g_program.Push(numbers[numberIndex]); result += FindSolutions(numbers, numberIndex + 1, stackDepth + 1); g_program.Pop(); Swap(numbers, numberIndex, i); } // Try without the number result += FindSolutions(numbers, numberIndex + 1, stackDepth); } return result; } </code></pre> If you know that g_program is writing the RPN program as a stack itself (so it can easily push and pop the last instruction), I think it's reasonably easy to follow.
waterhouseover 13 years ago
An old math teacher of mine gave me this fun little problem: For each number n from 1 to 9, make 6 from three copies of n, using only basic-ish arithmetic and no other numbers. For example, 2+2+2 = 6. I will leave the rest as a puzzle for the reader.<p>Precise statement of restrictions (enumerating these may give you a bit of a hint): You're allowed to use these operators: + - * / √ !<p>I did this, and then I figured out that if you're allowed to use the floor function as well, you can fulfill this task for any n ≥ 1. If [x] denotes the floor of x, then I'll demonstrate with 56:<p>√56 is somewhat less than 8. √√56 is somewhat less than 3. √√√56 is somewhat less than 2. Then [√√√56] = 1. Thus, we can have: ([√√√56]+[√√√56]+[√√√56])! = 3! = 6.<p>The expression to find "number of times you'll have to take square root of n" is slightly interesting: we want to take k square roots and end up with something less than 2, so n^(1/2^k) &#60; 2, or n &#60; 2^(2^k), so k &#62; log_2(log_2(n)).
评论 #3164238 未加载
评论 #3163763 未加载
评论 #3163258 未加载
评论 #3163115 未加载
shastaover 13 years ago
Reasoning in the article has a flaw - no factorial is a perfect square, but how do you know all intermediate results need be integers? At the least, this deserves an additional argument. (Though it would be fair to say that factorial is only defined on integers, I think.)
评论 #3163761 未加载
franzeover 13 years ago
<a href="https://www.google.com/search?q=(1%2B2)!!+%2B+3!%5E4+-+5&#38;pws=0" rel="nofollow">https://www.google.com/search?q=(1%2B2)!!+%2B+3!%5E4+-+5&#38...</a>
chrislloydover 13 years ago
Fascinating article. I remember in high school I had a teacher who set us a similar problem. We had to find every number from 0 to 30 with any operator but at most only four 2's. Most fun I've had in a math class ever.
ltover 13 years ago
Julian Bucknall just posted an article he wrote for PCPlus last year on this very subject.<p><a href="http://blog.boyet.com/blog/pcplus/pcplus-297-arithmetic-with-cards/" rel="nofollow">http://blog.boyet.com/blog/pcplus/pcplus-297-arithmetic-with...</a><p>As usual, well explained and interesting.
评论 #3163547 未加载
VMGover 13 years ago
I'm curious to know what a list implementation would look like
jsvaughanover 13 years ago
nice work but pity about the caveat "That leaves the door open to solutions with less than 5 initial numbers. I would bet that there aren't any..."
muninover 13 years ago
isn't this what SAT solvers are for?