Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created April 26, 2015 13:23
Show Gist options
  • Save flatcap/fa13870ea99f790f0c2b to your computer and use it in GitHub Desktop.
Save flatcap/fa13870ea99f790f0c2b to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2744 (2015-04-26)
#!/usr/bin/perl
use strict;
use Algorithm::Permute;
Algorithm::Permute::permute {
print "@ARGV\n";
} @ARGV;
#!/usr/bin/awk -f
{
count["B"] = 0;
count["C"] = 0;
count["D"] = 0;
for (i = 12; i > 0; i--) {
count[$i] += i;
}
b = count["B"];
c = count["C"];
d = count["D"];
# printf ("B: %2d, C: %2d, D: %2d\n", b, c, d);
if ((b == c) && (c == d)) {
print $0;
}
# rows++;
# if ((rows % 500000) == 0) {
# printf ("complete %0.1f%%\n", rows/399168);
# }
}
Three School Houses:
Berry, Cherry, Derry
Four students per House
Race: 12 points first, 11, 10 ... 1
Berry student came last
All three Houses score the same
Three Cherry House students placed consecutively
The two middle-placed Derry students placed consecutively
Which House Won?
How did its students place?
#!/bin/bash
permute.pl B B B C C C C D D D D | sed 's/$/ B/' > a1
score.awk a1 > a2
grep "C C C" a2 | grep "D.*[^D] D D [^D].*D" | uniq > a3
WINNER=$(cat a3 | cut -b1)
echo WINNER = $WINNER
sed 's/ /\n/g' a3 | nl | grep "$WINNER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment