Created
June 5, 2011 13:46
-
-
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.
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 | |
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 |
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
This is awesome. There, I said it.