Created
January 1, 2014 04:44
-
-
Save brimstone/8205166 to your computer and use it in GitHub Desktop.
Add operations to and solve: 10 9 8 7 6 5 4 3 2 1 = 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
s=$1 | |
e=$[ $s + 1 ] | |
for a in $(seq $(echo "4^8 * $s" | bc -l) $(echo "4^8 * $e" | bc -l)); do | |
n=$(echo "obase=4;$a" | bc) | |
f=$( | |
( for b in $(seq 1 $[ 9 - ${#n} ]); do | |
printf "0"; done; echo "$n" | |
) | sed -e 's/\(.\)/\1\n/g' | tr '0123' '+\-*/' | for a in {10..1}; do | |
read o | |
printf "$a $o " | |
done | |
echo | |
) | |
printf "$f= " | |
echo "$f" | bc -l | |
done | |
Usage: | |
./2014 0 > out.0 | |
./2014 1 > out.1 | |
./2014 2 > out.2 | |
./2014 3 > out.3 | |
10 * 9 * 8 * 7 / 6 / 5 * 4 * 3 - 2 - 1 = 2013 | |
10 * 9 * 8 * 7 / 6 / 5 * 4 * 3 - 2 * 1 = 2014 | |
10 * 9 * 8 * 7 / 6 / 5 * 4 * 3 - 2 / 1 = 2014 | |
10 * 9 * 8 * 7 / 6 / 5 * 4 * 3 - 2 + 1 = 2015 | |
10 * 9 * 8 * 7 / 6 / 5 * 4 * 3 + 2 - 1 = 2017 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment