Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Solution code for Project Euler problem 1
- # Problem: If we list all the natural numbers below 10 that are multiples of 3 or 5,
- # we get 3, 5, 6 and 9. The sum of these multiples is 23.
- # Find the sum of all the multiples of 3 or 5 below 1000.
- # Set up our variables
- SUM=23
- CURR=11
- #Check to see if CURR is less than 1000. If it is, then quit.
- while [ "$CURR" -lt 1000 ]
- do
- if !(( "$CURR" % 3 )) || !(( "$CURR" % 5 ))
- then
- #echo $CURR is divisible by 3 or 5 # a little test code
- let "SUM+=$CURR"
- else
- # Do nothing
- echo > /dev/null
- fi
- # add 1 to the value of CURR
- let "CURR += 1"
- done
- echo The sum of all multiples of 3 or 5 that are below 1000 is $SUM.
Advertisement
Add Comment
Please, Sign In to add comment