/train-numbers

Ever seen the carriage numbers on a train and wondered if you can combine them to make 10?

Primary LanguageC++

train-numbers

Ever seen the carriage numbers on a train and wondered if you can combine them to make 10 (treating each digit as an input and using only "standard" operations)? For example, given 1337 you can do 10 = (1 + 7/3) * 3. If you're allowed exponentiation (always a matter of debate) you could just do 10 = (3 + 7) * 1 ^ 3.

Here are a couple of simple algorithms for figuring this out, and for fun it's also available as a service: http://train-numbers.appspot.com.

Note that these algorithms don't tell you how to make 10, because that would be cheating (it's probably cheating anyway, but only a little bit).