Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created September 13, 2015 15:21
Show Gist options
  • Save flatcap/7331bcaf6954c3e72a11 to your computer and use it in GitHub Desktop.
Save flatcap/7331bcaf6954c3e72a11 to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2764 (2015-09-13)
#!/bin/bash
rm -f list{1,2}
for ((a = 1; a < 20; a++)); do
for ((b = a+1; b < 20; b++)); do
for ((c = b+1; c < 20; c++)); do
for ((d = c+1; d < 20; d++)); do
for ((e = d+1; e < 20; e++)); do
echo $a $b $c $d $e >> list-number
for i in $a $b $c $d $e; do
sed -n "${i}p" twenty
done | paste -s -d' ' >> list-name
done
done
done
done
done
cat list-name | while read a b c d e; do
printf "%s\n" $a $b $c $d $e | sort | paste -s -d' '
done > list-alpha
cat list-name | while read a b c d e; do
printf "%d\t%s\n" ${#a} $a ${#b} $b ${#c} $c ${#d} $d ${#e} $e | sort -n | cut -d$'\t' -f2 | paste -s -d' '
done > list-length
five different numbers under 20
three lists
numbers in ascending order
numbers in english in alphabetical order
numbers in english in increasing length order
(each must be longer than previous)
each number is in a different position in the three lists
what are my five numbers?
#!/usr/bin/awk -f
{
# 1 2 3 4 5 - 6 7 8 9 10 - 11 12 13 14 15
# no numbers in the same place
if (($1 == $6) || ($6 == $11) || ($1 == $11)) next;
if (($2 == $7) || ($7 == $12) || ($2 == $12)) next;
if (($3 == $8) || ($8 == $13) || ($3 == $13)) next;
if (($4 == $9) || ($9 == $14) || ($4 == $14)) next;
if (($5 == $10) || ($10 == $15) || ($5 == $15)) next;
if (($6 == $11) || ($11 == $16) || ($6 == $16)) next;
# increasing work length
if (length ($11) >= length ($12)) next;
if (length ($12) >= length ($13)) next;
if (length ($13) >= length ($14)) next;
if (length ($14) >= length ($15)) next;
print;
}
#!/bin/bash
paste list-name list-alpha list-length | awk -f solve.awk | while read a b c d e x; do
grep -nw -e $a -e $b -e $c -e $d -e $e twenty | cut -d: -f1 | paste -s -d' '
done
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment