Now solve it again in hex instead of base 10...
use strict; use Algorithm::Loops qw( NextPermute ); $|= 1; my %map; @map{1..9,'a'..'f'}= reverse 1..9,'a'..'f'; my @digs= reverse 1..9,'a'..'f'; sub Biggest { my( $len, @toks )= @_; do { my $hex= join '', @map{ @toks[0..$len-1] }; my $num; if( $len <= 8 ) { $num= hex $hex; } else { $num= hex substr( $hex, 0, 7 ); $num *= 16 for 9..$len; $num += hex substr( $hex, 8, -1 ); } for( $hex =~ /./g, 0 ) { if( ! $_ ) { print "$hex\n"; return; } last if 0 != $num % hex($_); } @toks[ $len .. $#toks ]= reverse @toks[ $len .. $#toks ] if $len < $#toks; } while( NextPermute(@toks) ); @toks= @map{ @toks }; print "No solution for $len of hexits: @toks\n"; } for my $len ( 1..@digs ) { Biggest( $len, @map{ @digs } ); }
Update2: And, in CODE tags inside of HTML comments is the output. The prior silly code that didn't realize that 5*2 isn't "10" in hex can also be grabbed via "select code-to-download".
- tye
|
|---|