Advertisement
tsinclai2002

Project Euler 8 - Math Makes Things Better

Mar 24th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.92 KB | None | 0 0
  1. # A quick script to find the largest product of five consecutive digits
  2.  
  3. # Set up our variables
  4.  
  5. DIGIT_STR=73167176519225119674426574742355349194934969239574788518438581294949595833471852952276689664452316173111217223831136222989343362766144866452382712188399827466572785224352586415722155397536978179778451693219784686224828397224137968652142124122758866688116427171479924442965674813919123162824586178664583591245665294765456828489128836321655444362979927244913387599116983572972571636269561852
  6. POSITION=0
  7. LEN=5
  8. z=10000
  9.  
  10. echo We have ${#DIGIT_STR} digits to process
  11.  
  12. # Let's pull out our five digit substrings
  13. # Code samples:
  14. # z=`expr substr $string $position $length`
  15. # echo ${DIGIT_STR:0:5}
  16. # let "var += 5"
  17. # TEST=`echo "76843" | grep -o . | sort -nr | tr -d '\n'`
  18.  
  19. while ((z >= 10000 ))
  20. do
  21. {
  22.     z=${DIGIT_STR:$POSITION:$LEN}
  23.     let "POSITION += 1"
  24.     echo $z | grep -o . | sort -nr | tr -d '\n'
  25.     echo
  26.    
  27. }
  28. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement