Created
May 10, 2015 18:38
-
-
Save flatcap/b39a40e7378cbd76a230 to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2746 (2015-05-10)
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
5 digit combination | |
sum of the cubes of the first three digits is equal to the first three digits | |
sum of factorials of the latter three digits is equal to the last three digits |
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 | |
seq -w 99999 | grep -v 0 | sed 's/./& /g' | solve.awk |
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
#!/usr/bin/awk -f | |
BEGIN { | |
} | |
function fact(n) { | |
if (n == 1) { | |
return 1; | |
} | |
return (n * fact(n-1)); | |
} | |
{ | |
a = $1; | |
b = $2; | |
c = $3; | |
d = $4; | |
e = $5; | |
top = $1$2$3 | |
bot = $3$4$5 | |
first = (a * a * a) + (b * b * b) + (c * c * c); | |
second = fact(c) + fact(d) + fact(e); | |
if ((first == top) && (second == bot)) { | |
printf ("%s : %d - %d\n", $0, first, second); | |
} | |
} | |
END { | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment