arto (ocehb) wrote,
arto
ocehb

perlweeklychallenge

Challenge #1

Print all the niven numbers from 0 to 50 inclusive, each on their own line. A niven number is a non-negative number that is divisible by the sum of its digits.



# perl -le 'print join"\n",map{$_%(eval join"+",split"",$_)?():$_}1..50'   
1
2
3
4
5
6
7
8
9
10
12
18
20
21
24
27
30
36
40
42
45
48
50

Tags: perl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments