Hacker News new | past | comments | ask | show | jobs | submit login
Euclid's algorithm in the Shell (shiroyasha.github.io)
7 points by shiroyasha23 on March 6, 2015 | hide | past | favorite | 1 comment



Once you go to the trouble of naming the script, might as well show off a recursive version as well:

  #!/bin/sh

  a=$1
  b=$2

  # base case
  if [ $b -eq 0 ]
  then
    echo $a
    exit
  fi

  echo $(./gcd.sh $b $(($a % $b)))




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: