Sha256: 0c193d8a3d821217153ce6c81f4c48453bc80d408de08884f4cf27b58b2b42fe

Contents?: true

Size: 306 Bytes

Versions: 95

Compression:

Stored size: 306 Bytes

Contents

#!/usr/bin/env bash

if [ "$1" -gt 0 ]; then
    N=$1
else
    echo "Error: Only positive numbers are allowed"
    exit 1
fi

STEP=0

while [ "$N" -ne "1" ]
do
    if [ "$(($N % 2))" -eq "0" ]; then
        N=$(($N / 2))
    else
        N=$((($N * 3) + 1))
    fi
    STEP=$(($STEP + 1))
done

echo $STEP

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.179 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.178 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.177 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.176 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.175 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.174 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.173 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.172 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.171 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.170 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.169 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.167 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.166 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.165 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.164 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.163 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.162 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.161 tracks/bash/exercises/collatz-conjecture/example.sh
trackler-2.2.1.160 tracks/bash/exercises/collatz-conjecture/example.sh