Skip to content

Instantly share code, notes, and snippets.

@Eriner
Created January 23, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eriner/920dcd7c2ee51d8d3624 to your computer and use it in GitHub Desktop.
Save Eriner/920dcd7c2ee51d8d3624 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# contents of file in an array, read from file as argv[1]
sums=($(<${1}))
# get the number of pairs
for n in {1..${#sums}..2}; do
first=${sums[${n}]}
second=${sums[$(( ${n} + 1 ))]}
# array to store correct results
valid=()
# do math
for i in {1..${second}}; do
modulus=$(( ${i} % ${first} ))
if [[ ${modulus} == 0 ]]; then
valid+=${i}
fi
done
# print results and a seperation newline
print -l ${valid}
print
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment