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.139 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.138 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.137 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.136 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.135 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.134 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.133 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.132 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.131 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.130 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.129 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.128 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.127 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.126 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.125 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.124 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.123 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.122 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.121 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.120 tracks/bash/exercises/armstrong-numbers/example.sh