Sha256: ecd849ad8388da27cecbb8134bad985b076a48a78fa8e8b9b25741257afa849b

Contents?: true

Size: 374 Bytes

Versions: 93

Compression:

Stored size: 374 Bytes

Contents

#!/usr/bin/env bash

is_armstrong() {
  sum=0
  number=$1
  power=${#number}

  index=1
  while [ $index -le ${#number} ]; do
      digit=$(echo ${number} | cut -c${index}-${index})
      sum=$(expr $sum + $(($digit**$power)))

      index=$(expr $index + 1)
  done

  if [ $sum -eq $number ]; then
    echo "true"
    exit 0
  else
    echo "false"
    exit 1
  fi
}

"$@"

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.118 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.117 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.116 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.115 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.114 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.113 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.111 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.110 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.109 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.108 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.107 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.106 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.105 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.104 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.103 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.102 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.101 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.100 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.99 tracks/bash/exercises/armstrong-numbers/example.sh