Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created June 28, 2015 17:03
Show Gist options
  • Save flatcap/af7921500788e039a41d to your computer and use it in GitHub Desktop.
Save flatcap/af7921500788e039a41d to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2753 (2015-06-28)
sign
l = length in cm
w = width in cm
l = 2w
(sum length digits)^2 - l = w
(sum width digits)^2 - w = l
#!/bin/bash
for ((WIDTH = 1; WIDTH < 100; WIDTH++)); do
LENGTH=$((WIDTH*2))
LDIGITS=$(( $(echo $LENGTH | sed -e 's/./+&/g') ))
LD_SQUARE=$((LDIGITS*LDIGITS))
LD_RESULT=$((LD_SQUARE - LENGTH))
[ $LD_RESULT -lt 0 ] && continue;
WDIGITS=$(( $(echo $WIDTH | sed -e 's/./+&/g') ))
WD_SQUARE=$((WDIGITS*WDIGITS))
WD_RESULT=$((WD_SQUARE - WIDTH))
[ $WD_RESULT -lt 0 ] && continue;
[ $LD_RESULT = $WIDTH ] && [ $WD_RESULT = $LENGTH ] && echo ${LENGTH}x${WIDTH}cm
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment