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.180 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.179 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.178 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.177 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.176 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.175 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.174 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.173 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.172 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.171 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.170 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.169 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.167 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.166 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.165 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.164 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.163 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.162 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.161 tracks/bash/exercises/armstrong-numbers/example.sh
trackler-2.2.1.160 tracks/bash/exercises/armstrong-numbers/example.sh