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)))




Applications are open for YC Summer 2021

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

Search: