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