Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions
Content added Content deleted
(→{{header|J}}: redo, with some comments) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 9: | Line 9: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F p(n) |
||
‘True if n is divisible by each of its digits, |
‘True if n is divisible by each of its digits, |
||
but not divisible by the product of those digits. |
but not divisible by the product of those digits. |
||
Line 28: | Line 28: | ||
V w = xs.last.len |
V w = xs.last.len |
||
print(xs.len" matching numbers:\n") |
print(xs.len" matching numbers:\n") |
||
print(chunksOf(10)(xs).map(row -> row.map(cell -> cell.rjust(:w, ‘ ’)).join(‘ ’)).join("\n"))</ |
print(chunksOf(10)(xs).map(row -> row.map(cell -> cell.rjust(:w, ‘ ’)).join(‘ ’)).join("\n"))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 42: | Line 42: | ||
=={{header|8086 Assembly}}== |
=={{header|8086 Assembly}}== |
||
< |
<syntaxhighlight lang="asm"> cpu 8086 |
||
org 100h |
org 100h |
||
section .text |
section .text |
||
Line 93: | Line 93: | ||
section .data |
section .data |
||
db '*****' |
db '*****' |
||
dbuf: db 13,10,'$'</ |
dbuf: db 13,10,'$'</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 144: | Line 144: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">BYTE FUNC Check(INT x) |
||
BYTE d |
BYTE d |
||
INT tmp,prod |
INT tmp,prod |
||
Line 172: | Line 172: | ||
FI |
FI |
||
OD |
OD |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Numbers_divisible_by_their_individual_digits,_but_not_by_the_product_of_their_digits.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Numbers_divisible_by_their_individual_digits,_but_not_by_the_product_of_their_digits.png Screenshot from Atari 8-bit computer] |
||
Line 181: | Line 181: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ada.Integer_Text_Io; |
with Ada.Integer_Text_Io; |
||
Line 219: | Line 219: | ||
end if; |
end if; |
||
end loop; |
end loop; |
||
end Numbers_Divisible;</ |
end Numbers_Divisible;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 |
<pre> 22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 |
||
Line 226: | Line 226: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68">BEGIN # find numbers divisible by their digits but not the product of their digits # |
||
INT max number = 999; |
INT max number = 999; |
||
INT number count := 0; |
INT number count := 0; |
||
Line 250: | Line 250: | ||
FI |
FI |
||
OD |
OD |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 259: | Line 259: | ||
=={{header|ALGOL-M}}== |
=={{header|ALGOL-M}}== |
||
< |
<syntaxhighlight lang="algolm">begin |
||
integer function mod(a, b); |
integer function mod(a, b); |
||
integer a, b; |
integer a, b; |
||
Line 298: | Line 298: | ||
end; |
end; |
||
write(""); |
write(""); |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 |
<pre> 22 33 44 48 55 66 77 88 99 122 |
||
Line 307: | Line 307: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
< |
<syntaxhighlight lang="algolw">begin % find numbers divisible by their digits but not the product of their digits % |
||
% returns true if n is divisible by its digits but not the product of its % |
% returns true if n is divisible by its digits but not the product of its % |
||
% digits, false otherwise % |
% digits, false otherwise % |
||
Line 341: | Line 341: | ||
end if_divisibleByDigitsButNotDigitProduct__i |
end if_divisibleByDigitsButNotDigitProduct__i |
||
end for_i |
end for_i |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 352: | Line 352: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
< |
<syntaxhighlight lang="apl">(⊢(/⍨)((⍎¨∘⍕)((∧/0=|)∧0≠(×/⊣)|⊢)⊢)¨)⍳999</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>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 |
<pre>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 |
||
Line 358: | Line 358: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">valid?: function [n][ |
||
digs: digits n |
digs: digits n |
||
facts: factors n |
facts: factors n |
||
Line 365: | Line 365: | ||
] |
] |
||
print select 1..999 => valid?</ |
print select 1..999 => valid?</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 372: | Line 372: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<syntaxhighlight lang="autohotkey">main: |
|||
<lang AutoHotkey>main: |
|||
while n < 1000 |
while n < 1000 |
||
{ |
{ |
||
Line 388: | Line 388: | ||
} |
} |
||
MsgBox % result |
MsgBox % result |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>22 33 44 48 55 66 77 88 99 122 124 126 |
<pre>22 33 44 48 55 66 77 88 99 122 124 126 |
||
Line 396: | Line 396: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f NUMBERS_DIVISIBLE_BY_THEIR_INDIVIDUAL_DIGITS_BUT_NOT_BY_THE_PRODUCT_OF_THEIR_DIGITS.AWK |
# syntax: GAWK -f NUMBERS_DIVISIBLE_BY_THEIR_INDIVIDUAL_DIGITS_BUT_NOT_BY_THE_PRODUCT_OF_THEIR_DIGITS.AWK |
||
# converted from C |
# converted from C |
||
Line 419: | Line 419: | ||
return(n % p) |
return(n % p) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 431: | Line 431: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
< |
<syntaxhighlight lang="basic">10 DEFINT A-Z |
||
20 FOR I=1 TO 999 |
20 FOR I=1 TO 999 |
||
30 N=I: P=1 |
30 N=I: P=1 |
||
Line 441: | Line 441: | ||
90 IF N THEN 40 |
90 IF N THEN 40 |
||
100 IF I MOD P <> 0 THEN PRINT I, |
100 IF I MOD P <> 0 THEN PRINT I, |
||
110 NEXT I</ |
110 NEXT I</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 |
<pre> 22 33 44 48 55 |
||
Line 454: | Line 454: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang="bcpl">get "libhdr" |
||
let divisible(n) = valof |
let divisible(n) = valof |
||
Line 478: | Line 478: | ||
$) |
$) |
||
wrch('*N') |
wrch('*N') |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 |
<pre> 22 33 44 48 55 66 77 88 99 122 |
||
Line 487: | Line 487: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int divisible(int n) { |
int divisible(int n) { |
||
Line 514: | Line 514: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 525: | Line 525: | ||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
< |
<syntaxhighlight lang="clu">divisible = proc (n: int) returns (bool) |
||
prod: int := 1 |
prod: int := 1 |
||
dgts: int := n |
dgts: int := n |
||
Line 549: | Line 549: | ||
end |
end |
||
end |
end |
||
end start_up</ |
end start_up</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 |
<pre> 22 33 44 48 55 66 77 88 99 122 |
||
Line 558: | Line 558: | ||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
< |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD. |
PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD. |
||
Line 607: | Line 607: | ||
MULTIPLY DIGIT(D) BY NDIV. |
MULTIPLY DIGIT(D) BY NDIV. |
||
IF NDIV IS NOT EQUAL TO N SET OK TO 0. |
IF NDIV IS NOT EQUAL TO N SET OK TO 0. |
||
NOPE. EXIT.</ |
NOPE. EXIT.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height: 50ex;'> 22 |
<pre style='height: 50ex;'> 22 |
||
Line 656: | Line 656: | ||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
< |
<syntaxhighlight lang="cowgol">include "cowgol.coh"; |
||
sub divisible(n: uint16): (r: uint8) is |
sub divisible(n: uint16): (r: uint8) is |
||
Line 692: | Line 692: | ||
n := n + 1; |
n := n + 1; |
||
end loop; |
end loop; |
||
print_nl();</ |
print_nl();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 703: | Line 703: | ||
=={{header|Draco}}== |
=={{header|Draco}}== |
||
< |
<syntaxhighlight lang="draco">proc nonrec divisible(word n) bool: |
||
word dprod, c, dgt; |
word dprod, c, dgt; |
||
bool div; |
bool div; |
||
Line 733: | Line 733: | ||
fi |
fi |
||
od |
od |
||
corp</ |
corp</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 |
<pre> 22 33 44 48 55 66 77 88 99 122 |
||
Line 742: | Line 742: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Nigel Galloway. April 9th., 2021 |
// Nigel Galloway. April 9th., 2021 |
||
let rec fN i g e l=match g%10,g/10 with (0,_)->false |(n,_) when i%n>0->false |(n,0)->i%(l*n)>0 |(n,g)->fN i g (e+n) (l*n) |
let rec fN i g e l=match g%10,g/10 with (0,_)->false |(n,_) when i%n>0->false |(n,0)->i%(l*n)>0 |(n,g)->fN i g (e+n) (l*n) |
||
seq{1..999}|>Seq.filter(fun n->fN n n 0 1)|>Seq.iter(printf "%d "); printfn "" |
seq{1..999}|>Seq.filter(fun n->fN n n 0 1)|>Seq.iter(printf "%d "); printfn "" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 754: | Line 754: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
< |
<syntaxhighlight lang="factor">USING: combinators.short-circuit grouping kernel math |
||
math.functions math.ranges math.text.utils prettyprint sequences ; |
math.functions math.ranges math.text.utils prettyprint sequences ; |
||
Line 765: | Line 765: | ||
} 3&& ; |
} 3&& ; |
||
1000 [1..b] [ needle? ] filter 9 group simple-table.</ |
1000 [1..b] [ needle? ] filter 9 group simple-table.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 776: | Line 776: | ||
=={{header|FOCAL}}== |
=={{header|FOCAL}}== |
||
< |
<syntaxhighlight lang="focal">01.10 F I=1,999;D 2 |
||
01.20 Q |
01.20 Q |
||
Line 792: | Line 792: | ||
02.75 S Z=I/P |
02.75 S Z=I/P |
||
02.80 I (FITR(Z)-Z)2.85,2.65 |
02.80 I (FITR(Z)-Z)2.85,2.65 |
||
02.85 T %4,I,!</ |
02.85 T %4,I,!</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 844: | Line 844: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: divisible? { n -- ? } |
||
1 { p } |
1 { p } |
||
n |
n |
||
Line 872: | Line 872: | ||
main |
main |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 885: | Line 885: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
This function does a bit more than the task asks for, just to make things interesting. |
This function does a bit more than the task asks for, just to make things interesting. |
||
< |
<syntaxhighlight lang="freebasic">function divdignp( n as const integer ) as ubyte |
||
'returns 1 if the number is divisible by its digits |
'returns 1 if the number is divisible by its digits |
||
' 2 if it is NOT divisible by the product of its digits |
' 2 if it is NOT divisible by the product of its digits |
||
Line 903: | Line 903: | ||
for i as uinteger = 1 to 999 |
for i as uinteger = 1 to 999 |
||
if divdignp(i) = 3 then print i;" "; |
if divdignp(i) = 3 then print i;" "; |
||
next i : print</ |
next i : print</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>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 |
<pre>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 |
||
Line 911: | Line 911: | ||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 947: | Line 947: | ||
} |
} |
||
fmt.Printf("\n%d such numbers found\n", len(res)) |
fmt.Printf("\n%d such numbers found\n", len(res)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 962: | Line 962: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.List.Split (chunksOf) |
||
import Text.Printf |
import Text.Printf |
||
Line 981: | Line 981: | ||
where |
where |
||
n = takeWhile (< 1000) numbers |
n = takeWhile (< 1000) numbers |
||
split = chunksOf 10 n</ |
split = chunksOf 10 n</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 993: | Line 993: | ||
and another approach might be to obtain (unordered) digit lists numerically, rather than by string conversion. |
and another approach might be to obtain (unordered) digit lists numerically, rather than by string conversion. |
||
< |
<syntaxhighlight lang="haskell">import Data.Bool (bool) |
||
import Data.List (unfoldr) |
import Data.List (unfoldr) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
Line 1,029: | Line 1,029: | ||
justifyRight :: Int -> Char -> String -> String |
justifyRight :: Int -> Char -> String -> String |
||
justifyRight n c = (drop . length) <*> (replicate n c <>)</ |
justifyRight n c = (drop . length) <*> (replicate n c <>)</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre> 22 33 44 48 55 66 77 88 99 122 |
<pre> 22 33 44 48 55 66 77 88 99 122 |
||
Line 1,038: | Line 1,038: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j"> ([ #~ ((10 #.inv]) ((0~:*/@[|]) * */@(0=|)) ])"0) >:i.999 |
||
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</ |
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</syntaxhighlight> |
||
<code>([ #~ ... ) >:i.999</code> filters the numbers based on the predicate (shown as '...' here). |
<code>([ #~ ... ) >:i.999</code> filters the numbers based on the predicate (shown as '...' here). |
||
Line 1,050: | Line 1,050: | ||
{{works with|jq}} |
{{works with|jq}} |
||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
< |
<syntaxhighlight lang="jq">def digits: |
||
tostring | explode | map( [.] | implode | tonumber); |
tostring | explode | map( [.] | implode | tonumber); |
||
Line 1,062: | Line 1,062: | ||
| digits |
| digits |
||
| all( unique[]; $n % . == 0) |
| all( unique[]; $n % . == 0) |
||
and ($n % prod != 0);</ |
and ($n % prod != 0);</syntaxhighlight> |
||
'''The Task''' |
'''The Task''' |
||
< |
<syntaxhighlight lang="jq">"Numbers < 1000 divisible by their digits, but not by the product thereof:", |
||
(range(1; 1000) |
(range(1; 1000) |
||
| select(is_divisible_by_digits_but_not_product))</ |
| select(is_divisible_by_digits_but_not_product))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,119: | Line 1,119: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight 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))) |
foreach(p -> print(rpad(p[2], 5), p[1] % 15 == 0 ? "\n" : ""), enumerate(filter(isonlydigdivisible, 1:1000))) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 |
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 |
||
Line 1,130: | Line 1,130: | ||
=={{header|Ksh}}== |
=={{header|Ksh}}== |
||
< |
<syntaxhighlight lang="ksh"> |
||
#!/bin/ksh |
#!/bin/ksh |
||
Line 1,164: | Line 1,164: | ||
(( ! i % 10 )) || _isdivisible ${i} || printf "%d " ${i} |
(( ! i % 10 )) || _isdivisible ${i} || printf "%d " ${i} |
||
done |
done |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}}<pre> |
{{out}}<pre> |
||
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 </pre> |
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 </pre> |
||
=={{header|MAD}}== |
=={{header|MAD}}== |
||
< |
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER |
||
PRINT COMMENT $ $ |
PRINT COMMENT $ $ |
||
Line 1,191: | Line 1,191: | ||
VECTOR VALUES FMT = $I4*$ |
VECTOR VALUES FMT = $I4*$ |
||
END OF PROGRAM </ |
END OF PROGRAM </syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height: 50ex;"> 22 |
<pre style="height: 50ex;"> 22 |
||
Line 1,240: | Line 1,240: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[SaveDivisible,DivisibleDigits] |
||
SaveDivisible[n_,0] := False |
SaveDivisible[n_,0] := False |
||
SaveDivisible[n_,m_] := Divisible[n,m] |
SaveDivisible[n_,m_] := Divisible[n,m] |
||
DivisibleDigits[n_Integer] := AllTrue[IntegerDigits[n],SaveDivisible[n,#]&] |
DivisibleDigits[n_Integer] := AllTrue[IntegerDigits[n],SaveDivisible[n,#]&] |
||
Select[Range[999],DivisibleDigits[#]\[And]!SaveDivisible[#,Times@@IntegerDigits[#]]&] |
Select[Range[999],DivisibleDigits[#]\[And]!SaveDivisible[#,Times@@IntegerDigits[#]]&] |
||
Length[%]</ |
Length[%]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{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} |
<pre>{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} |
||
Line 1,251: | Line 1,251: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import strutils |
||
iterator digits(n: Positive): int = |
iterator digits(n: Positive): int = |
||
Line 1,270: | Line 1,270: | ||
echo "Found ", result.len, " matching numbers." |
echo "Found ", result.len, " matching numbers." |
||
for i, n in result: |
for i, n in result: |
||
stdout.write ($n).align(3), if (i + 1) mod 9 == 0: '\n' else: ' '</ |
stdout.write ($n).align(3), if (i + 1) mod 9 == 0: '\n' else: ' '</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,282: | Line 1,282: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
==={{header|Free Pascal}}=== |
==={{header|Free Pascal}}=== |
||
< |
<syntaxhighlight lang="pascal"> |
||
program DivByDgtsNotByProdOfDgts; |
program DivByDgtsNotByProdOfDgts; |
||
Line 1,325: | Line 1,325: | ||
writeln; |
writeln; |
||
writeln(' count : ',cnt); |
writeln(' count : ',cnt); |
||
END.</ |
END.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,335: | Line 1,335: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; |
use strict; |
||
Line 1,346: | Line 1,346: | ||
} 1 .. 999; |
} 1 .. 999; |
||
print @numbers . " numbers found\n\n@numbers\n" =~ s/.{25}\K /\n/gr;</ |
print @numbers . " numbers found\n\n@numbers\n" =~ s/.{25}\K /\n/gr;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,361: | Line 1,361: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">didbntp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">didbntp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #004080;">integer</span> <span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> |
<span style="color: #004080;">integer</span> <span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> |
||
Line 1,374: | Line 1,374: | ||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">didbntp</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">didbntp</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d didbntp thingies less than one thousand: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">","</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d didbntp thingies less than one thousand: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">","</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,381: | Line 1,381: | ||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
< |
<syntaxhighlight lang="plm">100H: |
||
/* CHECK NUMBER */ |
/* CHECK NUMBER */ |
||
Line 1,426: | Line 1,426: | ||
CALL BDOS(0,0); |
CALL BDOS(0,0); |
||
EOF</ |
EOF</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:50ex;">22 |
<pre style="height:50ex;">22 |
||
Line 1,475: | Line 1,475: | ||
=={{header|Plain English}}== |
=={{header|Plain English}}== |
||
< |
<syntaxhighlight lang="plainenglish">To run: |
||
Start up. |
Start up. |
||
Loop. |
Loop. |
||
Line 1,496: | Line 1,496: | ||
Repeat. |
Repeat. |
||
If the number is evenly divisible by the digit product, say no. |
If the number is evenly divisible by the digit product, say no. |
||
Say yes.</ |
Say yes.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,503: | Line 1,503: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">'''Numbers matching a function of their digits''' |
||
from functools import reduce |
from functools import reduce |
||
Line 1,555: | Line 1,555: | ||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main() |
main() |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>45 matching numbers: |
<pre>45 matching numbers: |
||
Line 1,567: | Line 1,567: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang="quackery"> [ dup 0 = iff |
||
[ 2drop false ] done |
[ 2drop false ] done |
||
mod 0 = ] is divisible ( n n --> b ) |
mod 0 = ] is divisible ( n n --> b ) |
||
Line 1,589: | Line 1,589: | ||
drop ] is meetscriteria ( n n --> b ) |
drop ] is meetscriteria ( n n --> b ) |
||
1000 times [ i^ meetscriteria if [ i^ echo sp ] ]</ |
1000 times [ i^ meetscriteria if [ i^ echo sp ] ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,597: | Line 1,597: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}" given |
||
(^1000).grep: -> $n { $n.contains(0) ?? False !! all |($n.comb).map($n %% *), $n % [*] $n.comb };</ |
(^1000).grep: -> $n { $n.contains(0) ?? False !! all |($n.comb).map($n %% *), $n % [*] $n.comb };</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,609: | Line 1,609: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm finds integers divisible by its individual digits, but not by product of digs*/ |
||
parse arg hi cols . /*obtain optional argument from the CL.*/ |
parse arg hi cols . /*obtain optional argument from the CL.*/ |
||
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/ |
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/ |
||
Line 1,641: | Line 1,641: | ||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</ |
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,657: | Line 1,657: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
Line 1,695: | Line 1,695: | ||
see nl + "Found " + row + " numbers" + nl |
see nl + "Found " + row + " numbers" + nl |
||
see "done..." + nl |
see "done..." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,711: | Line 1,711: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">^1000 -> grep {|n| |
||
n.digits.all {|d| d `divides` n } && !(n.digits.prod `divides` n) |
n.digits.all {|d| d `divides` n } && !(n.digits.prod `divides` n) |
||
}.say</ |
}.say</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,720: | Line 1,720: | ||
=={{header|Snobol}}== |
=={{header|Snobol}}== |
||
< |
<syntaxhighlight lang="snobol"> define('divis(n)i,d,p') :(divis_end) |
||
divis p = 1 |
divis p = 1 |
||
i = n |
i = n |
||
Line 1,732: | Line 1,732: | ||
loop output = divis(n) n |
loop output = divis(n) n |
||
n = lt(n,1000) n + 1 :s(loop) |
n = lt(n,1000) n + 1 :s(loop) |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,786: | Line 1,786: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int, Nums |
||
import "/seq" for Lst |
import "/seq" for Lst |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 1,800: | Line 1,800: | ||
System.print("Numbers < 1000 divisible by their digits, but not by the product thereof:") |
System.print("Numbers < 1000 divisible by their digits, but not by the product thereof:") |
||
for (chunk in Lst.chunks(res, 9)) Fmt.print("$4d", chunk) |
for (chunk in Lst.chunks(res, 9)) Fmt.print("$4d", chunk) |
||
System.print("\n%(res.count) such numbers found")</ |
System.print("\n%(res.count) such numbers found")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,815: | Line 1,815: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">func Check(N); |
||
\Return 'true' if N is divisible by its digits and not by the product of its digits |
\Return 'true' if N is divisible by its digits and not by the product of its digits |
||
int N, M, Digit, Product; |
int N, M, Digit, Product; |
||
Line 1,841: | Line 1,841: | ||
Text(0, " such integers found below 1000. |
Text(0, " such integers found below 1000. |
||
"); |
"); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |