Practical numbers: Difference between revisions

m
J implementation
m (J implementation)
Line 52:
6666 is a practical number.
66666 is an impractical number.</pre>
 
=={{header|J}}==
 
Borrowed from the [[Proper divisors#J]] page:
 
<lang J>factors=: [: /:~@, */&>@{@((^ i.@>:)&.>/)@q:~&__
properDivisors=: factors -. ]</lang>
 
Borrowed from the [[Power set#J]] page:
 
<lang J>ps=: #~ 2 #:@i.@^ #</lang>
 
Implementation:
 
<lang J>isPrac=: ('' -:&# i. -. 0,+/"1@(ps ::empty)@properDivisors)"0</lang>
 
Task examples:
 
<lang J> +/ isPrac 1+i.333 NB. count practical numbers
77
(#~ isPrac) 1+i.333 NB. list them
1 2 4 6 8 12 16 18 20 24 28 30 32 36 40 42 48 54 56 60 64 66 72 78 80 84 88 90 96 100 104 108 112 120 126 128 132 140 144 150 156 160 162 168 176 180 192 196 198 200 204 208 210 216 220 224 228 234 240 252 256 260 264 270 272 276 280 288 294 300 304 306 30...
isPrac 666 NB. test
1</lang>
 
=={{header|Julia}}==
Line 101 ⟶ 125:
222222 is a practical number.
</pre>
 
 
=={{header|Phix}}==
6,962

edits