Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created April 26, 2015 13:21
Show Gist options
  • Save flatcap/4aabc6339f6b4b85ad25 to your computer and use it in GitHub Desktop.
Save flatcap/4aabc6339f6b4b85ad25 to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2742 (2015-04-12)
#!/usr/bin/awk -f
BEGIN {
}
{
top = $1$2$3;
mid = $4$5$6;
bot = $7$8$9;
if ((top > mid) || (mid > bot)) {
next;
}
if ((top < 100) || (mid < 100) || (bot < 100)) {
next;
}
if ((top > 500) || (mid > 500) || (bot > 500)) {
next;
}
sum_top = $1 + $2 + $3;
sum_mid = $4 + $5 + $6;
sum_bot = $7 + $8 + $9;
if ((sum_top != sum_mid) || (sum_mid != sum_bot)) {
next;
}
mean = (top + mid + bot) / 3;
if ((top != mean) && (mid != mean) && (bot != mean)) {
next;
}
printf ("%d %d %d\n", top, mid, bot);
}
END {
}
three three-digit hymn numbers
all <= 500
one is the mean of the others
no digits repeated
for each number: sum of digits is the same
#!/usr/bin/perl
use strict;
use Algorithm::Permute;
Algorithm::Permute::permute {
print "@ARGV\n";
} @ARGV;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment