Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created May 10, 2015 18:38
Show Gist options
  • Save flatcap/b39a40e7378cbd76a230 to your computer and use it in GitHub Desktop.
Save flatcap/b39a40e7378cbd76a230 to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2746 (2015-05-10)
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
#!/bin/bash
seq -w 99999 | grep -v 0 | sed 's/./& /g' | solve.awk
#!/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