tsinclai2002

Euler Problem 1 Script

Sep 12th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.70 KB | None | 0 0
  1. #!/bin/bash
  2. # Solution code for Project Euler problem 1
  3. # Problem: If we list all the natural numbers below 10 that are multiples of 3 or 5,
  4. # we get 3, 5, 6 and 9. The sum of these multiples is 23.
  5.  
  6. # Find the sum of all the multiples of 3 or 5 below 1000.
  7.  
  8. # Set up our variables
  9. SUM=23  
  10. CURR=11
  11.  
  12. #Check to see if CURR is less than 1000. If it is, then quit.
  13. while [ "$CURR" -lt 1000 ]
  14. do
  15.     if   !(( "$CURR" % 3 )) || !(( "$CURR" % 5 ))
  16.     then
  17.         #echo $CURR is divisible by 3 or 5 # a little test code
  18.         let "SUM+=$CURR"
  19.     else
  20.         # Do nothing
  21.         echo > /dev/null
  22.     fi
  23.     # add 1 to the value of CURR
  24.     let "CURR += 1"
  25. done
  26. 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