Created
June 28, 2015 17:03
-
-
Save flatcap/af7921500788e039a41d to your computer and use it in GitHub Desktop.
Sunday Times Teaser 2753 (2015-06-28)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sign | |
l = length in cm | |
w = width in cm | |
l = 2w | |
(sum length digits)^2 - l = w | |
(sum width digits)^2 - w = l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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