#!/usr/bin/perl use strict; use warnings; my @digits= qw(9 8 7 6 5 4 3 2 1); my $max= 0; permut('', @digits); print "Solution: $max\n"; sub permut { my ($s, @digits)= @_; my $i= scalar @digits; DIV: { { no warnings; last DIV if $s<$max; } foreach my $i (split //m,$s) { last DIV if $s % $i; } print "$s\n"; $max=$s; } if ($i) { while ($i--) { my $f= shift @digits; permut($s.$f, @digits); push(@digits, $f); } } }