aboutsummaryrefslogtreecommitdiff
path: root/challenge-054/shahed-nooshmand/perl/ch-2.pl
blob: 59f5253b94a90eb09e8d10449ba471bcf0e617f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env perl

my %hail = (1 => 1);

for (1..1e6-1) {
    my $n = $_;
    my $i = 0;
    until (exists $hail{$n}) {
    	$n = $n % 2 ? $n * 3 + 1 : $n / 2;
    	$i++
    }
    $hail{$_} = $i + $hail{$n}
}

print "$_    $hail{$_}\n" for (sort { $hail{$b} <=> $hail{$a} } keys %hail)[0..19]