Problem 55
Perl6
1my $num-of-lychrel = 0;
2my $num;
3my $is-lychrel;
4my $count = 0;
5(10..10000).map({
6 my $num = $_;
7 $is-lychrel = True;
8 $count = 0;
9 while $count < 55 {
10 $num = $num + $num.flip;
11 if $num == $num.flip { $is-lychrel = False } ;
12 $count += 1;
13 }
14 if $is-lychrel { $num-of-lychrel += 1 } ;
15});
16say $num-of-lychrel;
Ruby
1def is_palin(num)
2 puts "Checking to see if #{num}"
3 if num.to_s.reverse == num.to_s
4 puts "#{num} is a palindrome"
5 1
6 end
7 0
8end
9
10def reverse_num(num)
11 num.to_s.reverse.to_i
12end
13
14num_of_lychrel = 0
15count = 0
16iterator = 0
17num = -1
18while iterator <= 10_000
19 count = 0
20 num = iterator
21 palin = 0
22 while count <= 50
23 reversed_num = reverse_num(num)
24 sum_num = reversed_num + num
25 if is_palin(num) || is_palin(sum_num)
26 palin = 1
27 break
28 end
29 count += 1
30 end
31 if palin == 1
32 iterator += 1
33 else
34 num_of_lychrel += 1
35 iterator += 1
36 palin = 0
37 end
38end
39puts num_of_lychrel