Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Puzzle Time

by Athanasius (Abbot)
on Dec 23, 2012 at 03:39 UTC ( #1010071=note: print w/ replies, xml ) Need Help??


in reply to Puzzle Time

First, some assumptions:

  1. Numbers means natural numbers
  2. Digits means digits in the decimal representation
  3. Divisible by a digit means divisible without remainder
  4. The digit 0 is excluded, since division by 0 is undefined

There are 9 different digits allowed, and any number having more than 9 digits will necessarily have some digits repeated. So, the upper bound is 987,654,321.

#! perl use Modern::Perl; my $count = 0; OUTER: for my $n (1 .. 987_654_321) { my %digits; ++$digits{$_} for split //, $n; for (keys %digits) { next OUTER if ($_ == 0) || ($digits{$_} > 1) || ($n % $_); } printf "#%d is %d\n", ++$count, $n; }

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Puzzle Time
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2015-07-29 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls