Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions
(Add Factor) |
m (added numbers are positive integers in base ten.) |
||
Line 2: | Line 2: | ||
;Task: |
;Task: |
||
Find and show |
Find and show positive decimal integers divisible by their individual digits, but not by the product of their digits, where <big>'''n < 1000''' |
||
<br><br> |
<br><br> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
Revision as of 09:28, 8 April 2021
- Task
Find and show positive decimal integers divisible by their individual digits, but not by the product of their digits, where n < 1000
Factor
<lang factor>USING: combinators.short-circuit grouping kernel math math.functions math.ranges math.text.utils prettyprint sequences ;
- needle? ( n -- ? )
dup 1 digit-groups dup product { [ 2nip zero? not ] [ nip divisor? not ] [ drop [ divisor? ] with all? ] } 3&& ;
1000 [1..b] [ needle? ] filter 9 group simple-table.</lang>
- Output:
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555 636 648 666 728 777 784 824 848 864 888 936 999
Julia
<lang julia>isonlydigdivisible(n) = (d = digits(n); !(0 in d) && all(x -> n % x == 0, d) && n % prod(d) != 0)
foreach(p -> print(rpad(p[2], 5), p[1] % 15 == 0 ? "\n" : ""), enumerate(filter(isonlydigdivisible, 1:1000)))
</lang>
- Output:
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555 636 648 666 728 777 784 824 848 864 888 936 999
Ring
<lang ring> load "stdlib.ring"
decimals(0) see "working..." + nl see "Numbers divisible by their individual digits, but not by the product of their digits are:" + nl
row = 0 limit = 1000
for n = 1 to limit
flag = 1 pro = 1 strn = string(n) for m = 1 to len(strn) temp = strn[m] if temp != 0 pro = pro * number(temp) ok if n%temp = 0 flag = 1 else flag = 0 exit ok next bool = ((n%pro) != 0) if flag = 1 and bool row = row + 1 see "" + n + " " if row%10 = 0 see nl ok ok
next
see nl + "Found " + row + " numbers" + nl see "done..." + nl </lang>
- Output:
working... Numbers divisible by their individual digits, but not by the product of their digits are: 22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555 636 648 666 728 777 784 824 848 864 888 936 999 Found 45 numbers done...