Skip to content

Instantly share code, notes, and snippets.

@czottmann
Created June 5, 2011 13:46
Show Gist options
  • Save czottmann/1008974 to your computer and use it in GitHub Desktop.
Save czottmann/1008974 to your computer and use it in GitHub Desktop.
Find the sum of all the multiples of 3 or 5 below 1000.
#!/bin/bash
SUM=0
for I in {1..999}; do
if [[ $( echo "${I} % 3" | bc ) == "0" || $( echo "${I} % 5" | bc ) == "0" ]]; then
SUM=$( echo "${SUM} + ${I}" | bc )
fi
done
echo $SUM
@czottmann
Copy link
Author

Right. :P No suggestions regarding my weak bash-fu or anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment