Thread Kaprekar-Zahl
(7 answers)
Opened by Dominik at 2017-12-14 19:25 Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #!/usr/bin/perl use strict; use warnings; for my $cnt (0..800000){ my $aquadrat=$cnt**2; my @parts = split('',$aquadrat); my $first = ''; while(@parts) { $first .= shift(@parts); last if($first >= $cnt); next unless $first; last unless @parts; my $last = join('',@parts); next unless $last; next if($last >= $cnt); if($first + $last == $cnt) { print "$cnt**2 => $aquadrat => $first + $last\n"; last; } } } Last edited: 2017-12-17 09:34:01 +0100 (CET) |