# # Lenny Conundrum Round 284 # http://www.neopets.com/games/conundrum_feature.phtml?round=284 # # You have four numbers: 553, 546, 897, and 318. However, the numbers aren't # what they seem. One of the numbers (I'm not telling you which!) is actually # in base 13, one is in base 17, one is in base 19, and one is in base 23. # It's just coincidence that all four numbers only use digits 9 and below. # # Now, if you add all four numbers and convert them to base 32 notation, the # resulting number can also be written only using digits 0-9. What is that # sum, as denoted in base 32? For example, if the sum in base 10 was 288, you # would submit the base 32 answer: 90. # use strict; use warnings; use Algorithm::Loops qw( NextPermuteNum ); use List::Util qw( sum ); { my @nums = (0..9,'a'..'z','A'..'Z'); my %nums = map { $nums[$_] => $_ } 0..$#nums; sub to_base { my $base = shift; my $number = shift; return $nums[0] if $number == 0; my $rep = ""; # this will be the end value. while( $number > 0 ) { $rep = $nums[$number % $base] . $rep; $number = int( $number / $base ); } return $rep; } sub fr_base { my $base = shift; my $rep = shift; my $number = 0; for( $rep =~ /./g ) { $number *= $base; $number += $nums{$_}; } return $number; } } my @nums = ( 553, 546, 897, 318 ); my @bases = ( 13, 17, 19, 23 ); @bases = sort @bases; do { my $sum32 = to_base( 32, sum( map { fr_base( $bases[$_], $nums[$_] ) } 0..$#bases ) ); print( join( ' + ', map { "$nums[$_]($bases[$_])" } 0..$#bases ), " = $sum32(32)", ( $sum32 =~ /[^0-9]/ ? '' : ' <----' ), "\n" ); } while NextPermuteNum( @bases ); __END__ 553(13) + 546(17) + 897(19) + 318(23) = 6uc(32) 553(13) + 546(17) + 897(23) + 318(19) = 7pk(32) 553(13) + 546(19) + 897(17) + 318(23) = 6na(32) 553(13) + 546(19) + 897(23) + 318(17) = 7ua(32) 553(13) + 546(23) + 897(17) + 318(19) = 726(32) <---- 553(13) + 546(23) + 897(19) + 318(17) = 7du(32) 553(17) + 546(13) + 897(19) + 318(23) = 6ug(32) 553(17) + 546(13) + 897(23) + 318(19) = 7po(32) 553(17) + 546(19) + 897(13) + 318(23) = 6bi(32) 553(17) + 546(19) + 897(23) + 318(13) = 86a(32) 553(17) + 546(23) + 897(13) + 318(19) = 6me(32) 553(17) + 546(23) + 897(19) + 318(13) = 7lu(32) 553(19) + 546(13) + 897(17) + 318(23) = 6ng(32) 553(19) + 546(13) + 897(23) + 318(17) = 7ug(32) 553(19) + 546(17) + 897(13) + 318(23) = 6bk(32) 553(19) + 546(17) + 897(23) + 318(13) = 86c(32) 553(19) + 546(23) + 897(13) + 318(17) = 6r6(32) 553(19) + 546(23) + 897(17) + 318(13) = 7eu(32) 553(23) + 546(13) + 897(17) + 318(19) = 72g(32) 553(23) + 546(13) + 897(19) + 318(17) = 7e8(32) 553(23) + 546(17) + 897(13) + 318(19) = 6mk(32) 553(23) + 546(17) + 897(19) + 318(13) = 7m4(32) 553(23) + 546(19) + 897(13) + 318(17) = 6ra(32) 553(23) + 546(19) + 897(17) + 318(13) = 7f2(32)