Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions

m
(add FreeBASIC)
m (→‎{{header|Wren}}: Minor tidy)
(43 intermediate revisions by 29 users not shown)
Line 3:
;Task:
Find and show positive decimal integers divisible by their individual digits,   but not divisible by the product of their digits,
<br>where &nbsp; <big>'''n &nbsp; &lt; &nbsp; 10001,000''' </big>
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">F p(n)
‘True if n is divisible by each of its digits,
but not divisible by the product of those digits.
V digits = String(n).map(c -> Int(c))
R !(0 C digits) & (0 != (n % product(digits))) & all(digits.map(d -> 0 == @n % d))
 
F chunksOf(n)
‘A series of lists of length n, subdividing the
contents of xs. Where the length of xs is not evenly
divible, the final list will be shorter than n.
F go(xs)
R ((0 .< xs.len).step(@=n).map(i -> @xs[i .< @=n + i]))
R go
 
V xs = (1..999).filter(n -> p(n)).map(String)
V w = xs.last.len
print(xs.len" matching numbers:\n")
print(chunksOf(10)(xs).map(row -> row.map(cell -> cell.rjust(:w, ‘ ’)).join(‘ ’)).join("\n"))</syntaxhighlight>
 
{{out}}
<pre>
45 matching numbers:
 
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|8086 Assembly}}==
<langsyntaxhighlight lang="asm"> cpu 8086
org 100h
section .text
Line 58 ⟶ 92:
section .data
db '*****'
dbuf: db 13,10,'$'</langsyntaxhighlight>
 
{{out}}
Line 107 ⟶ 141:
936
999</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">BYTE FUNC Check(INT x)
BYTE d
INT tmp,prod
 
prod=1 tmp=x
WHILE tmp#0
DO
d=tmp MOD 10
IF x MOD d#0 THEN
RETURN (0)
FI
tmp==/10
prod==*d
OD
IF x MOD prod=0 THEN
RETURN (0)
FI
RETURN (1)
 
PROC Main()
INT i
 
FOR i=1 TO 999
DO
IF Check(i) THEN
PrintI(i) Put(32)
FI
OD
RETURN</syntaxhighlight>
{{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]
<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|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
with Ada.Integer_Text_Io;
 
Line 147 ⟶ 218:
end if;
end loop;
end Numbers_Divisible;</langsyntaxhighlight>
{{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>
 
=={{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 number count := 0;
FOR n TO max number DO
INT digit product := 1;
INT v := n;
BOOL divisible by digits := n /= 0;
WHILE v > 0 AND divisible by digits DO
INT digit = v MOD 10;
divisible by digits := IF digit = 0
THEN FALSE
ELSE n MOD digit = 0
FI;
digit product *:= digit;
v OVERAB 10
OD;
IF divisible by digits THEN
IF n MOD digit product /= 0 THEN
# have a number divisible by its digits but not the product of the digits #
print( ( " ", whole( n, -3 ) ) );
IF ( number count +:= 1 ) MOD 15 = 0 THEN print( ( newline ) ) FI
FI
FI
OD
END</syntaxhighlight>
{{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>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algolm">begin
integer function mod(a, b);
integer a, b;
mod := a-a/b*b;
integer function divisible(n);
integer n;
begin
integer r, p, c, d;
p := 1;
c := n;
r := 0;
while c <> 0 do
begin
d := mod(c, 10);
if d = 0 then go to stop;
if mod(n, d) <> 0 then go to stop;
p := p * d;
c := c / 10;
end;
if mod(n, p) <> 0 then r := 1;
stop:
divisible := r;
end;
integer c, n;
c := 0;
for n := 1 step 1 until 1000 do
begin
if divisible(n) <> 0 then
begin
if (c-1)/10 <> c/10 then
write(n)
else
writeon(n);
c := c + 1;
end;
end;
write("");
end</syntaxhighlight>
{{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>
 
=={{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 %
% digits, false otherwise %
logical procedure divisibleByDigitsButNotDigitProduct ( integer value n ) ;
begin
integer v, p;
logical matches;
v := n;
p := 1;
matches := v not = 0;
while matches and v > 0 do begin
integer d;
d := v rem 10;
v := v div 10;
if d = 0 then matches := false else matches := n rem d = 0;
p := p * d
end while_matches_and_v_gt_0 ;
if matches then begin
if p = 0 then matches := false else matches := n rem p not = 0
end if_matche ;
matches
end divisibleByDigitsButNotDigitProduct ;
integer count;
% show the members of the seuence up to 1000 %
write( "Numbers below 1000 that are divisible by their digits but not the product of their digits:" );
write();
count := 0;
for i := 0 until 999 do begin
if divisibleByDigitsButNotDigitProduct( i ) then begin
writeon( i_w := 3, s_w := 0, " ", i );
count := count + 1;
if count rem 15 = 0 then write()
end if_divisibleByDigitsButNotDigitProduct__i
end for_i
end.</syntaxhighlight>
{{out}}
<pre>
Numbers below 1000 that are divisible by their digits but not the product of their digits:
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|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">(⊢(/⍨)((⍎¨∘⍕)((∧/0=|)∧0≠(×/⊣)|⊢)⊢)¨)⍳999</langsyntaxhighlight>
{{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>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">valid?: function [n][
digs: digits n
facts: factors n
and? [not? in? product digs facts]
[every? digs 'd -> in? d facts]
]
 
print select 1..999 => valid?</syntaxhighlight>
 
{{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>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">main:
while n < 1000
{
n := A_Index
prod = 1
for i, v in StrSplit(n)
{
if (v = 0) || (n/v <> floor(n/v))
continue, main
prod *= v
}
if (n/prod = floor(n/prod))
continue
result .= n "`t"
}
MsgBox % result
</syntaxhighlight>
{{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>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_DIVISIBLE_BY_THEIR_INDIVIDUAL_DIGITS_BUT_NOT_BY_THE_PRODUCT_OF_THEIR_DIGITS.AWK
# converted from C
BEGIN {
start = 1
stop = 999
for (i=start; i<=stop; i++) {
if (divisible(i)) {
printf("%4d%1s",i,++count%10?"":"\n")
}
}
printf("\nNumbers divisible by their individual digits but not by the product of their digits %d-%d: %d\n",start,stop,count)
exit(0)
}
function divisible(n, c,d,p) {
p = 1
for (c=n; c; c=int(c/10)) {
d = c % 10
if (!d || n % d) { return(0) }
p *= d
}
return(n % p)
}
</syntaxhighlight>
{{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
Numbers divisible by their individual digits but not by the product of their digits 1-999: 45
</pre>
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT A-Z
20 FOR I=1 TO 999
30 N=I: P=1
Line 171 ⟶ 440:
90 IF N THEN 40
100 IF I MOD P <> 0 THEN PRINT I,
110 NEXT I</langsyntaxhighlight>
{{out}}
<pre> 22 33 44 48 55
Line 182 ⟶ 451:
666 728 777 784 824
848 864 888 936 999</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let divisible(n) = valof
$( let p = 1
let c = n
until c = 0 do
$( let d = c rem 10
if d=0 resultis false
unless n rem d=0 resultis false
p := p * d
c := c / 10
$)
resultis n rem p ~= 0
$)
 
let start() be
$( let c = 0
for n = 1 to 1000 do
if divisible(n) do
$( writef("%I5",n)
c := c + 1
if c rem 10=0 then wrch('*N')
$)
wrch('*N')
$)</syntaxhighlight>
{{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>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int divisible(int n) {
Line 211 ⟶ 513:
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 220 ⟶ 522:
488 515 555 636 648 666 728 777 784 824
848 864 888 936 999</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">divisible = proc (n: int) returns (bool)
prod: int := 1
dgts: int := n
while dgts > 0 do
dgt: int := dgts // 10
if dgt=0 cor n//dgt~=0 then
return(false)
end
prod := prod * dgt
dgts := dgts / 10
end
return(n//prod~=0)
end divisible
 
start_up = proc ()
po: stream := stream$primary_output()
col: int := 0
for n: int in int$from_to(1,1000) do
if divisible(n) then
stream$putright(po, int$unparse(n), 5)
col := col + 1
if col//10=0 then stream$putc(po,'\n') end
end
end
end start_up</syntaxhighlight>
{{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>
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CALCULATION.
02 N PIC 9(4).
02 DGT-PROD PIC 9(3).
02 NSTART PIC 9.
02 D PIC 9.
02 N-INDEXING REDEFINES N.
03 DIGIT PIC 9 OCCURS 4 TIMES.
02 NDIV PIC 9(4).
02 OK PIC 9.
01 OUTPUT-FORMAT.
02 DISP-N PIC Z(4).
PROCEDURE DIVISION.
BEGIN.
PERFORM CHECK VARYING N FROM 1 BY 1
UNTIL N IS EQUAL TO 1000.
STOP RUN.
CHECK SECTION.
BEGIN.
SET NSTART TO 1.
INSPECT N TALLYING NSTART FOR LEADING '0'.
SET DGT-PROD TO 1.
PERFORM MUL-DIGIT VARYING D FROM NSTART BY 1
UNTIL D IS GREATER THAN 4.
IF DGT-PROD = 0 GO TO NOPE.
SET OK TO 1.
PERFORM CHECK-DIGIT VARYING D FROM NSTART BY 1
UNTIL D IS GREATER THAN 4.
IF OK = 0 GO TO NOPE.
DIVIDE N BY DGT-PROD GIVING NDIV.
MULTIPLY DGT-PROD BY NDIV.
IF NDIV IS EQUAL TO N GO TO NOPE.
MOVE N TO DISP-N.
DISPLAY DISP-N.
MUL-DIGIT.
IF D IS GREATER THAN 4 GO TO NOPE.
MULTIPLY DIGIT(D) BY DGT-PROD.
CHECK-DIGIT.
IF D IS GREATER THAN 4 GO TO NOPE.
DIVIDE N BY DIGIT(D) GIVING NDIV.
MULTIPLY DIGIT(D) BY NDIV.
IF NDIV IS NOT EQUAL TO N SET OK TO 0.
NOPE. EXIT.</syntaxhighlight>
{{out}}
<pre style='height: 50ex;'> 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|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub divisible(n: uint16): (r: uint8) is
Line 258 ⟶ 691:
n := n + 1;
end loop;
print_nl();</langsyntaxhighlight>
 
{{out}}
Line 267 ⟶ 700:
488 515 555 636 648 666 728 777 784 824
848 864 888 936 999</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec divisible(word n) bool:
word dprod, c, dgt;
bool div;
c := n;
div := true;
dprod := 1;
while div and c /= 0 do
dgt := c % 10;
c := c / 10;
if dgt = 0 or n % dgt /= 0
then div := false
else dprod := dprod * dgt
fi
od;
div and n % dprod /= 0
corp
 
proc nonrec main() void:
word n, c;
c := 0;
for n from 1 upto 999 do
if divisible(n) then
write(n:5);
c := c+1;
if c % 10 = 0 then writeln() fi
fi
od
corp</syntaxhighlight>
{{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>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function IsDivisible(N: integer): boolean;
{Returns true if N is divisible by each of its digits}
{And not divisible by the product of all the digits}
var I: integer;
var S: string;
var B: byte;
var P: integer;
begin
Result:=False;
{Test if digits divide into N}
S:=IntToStr(N);
for I:=1 to Length(S) do
begin
B:=Byte(S[I])-$30;
if B=0 then exit;
if (N mod B)<>0 then exit;
end;
{Test if product of digits doesn't divide into N}
P:=1;
for I:=1 to Length(S) do
begin
B:=Byte(S[I])-$30;
P:=P * B;
end;
Result:=(N mod P)<>0;
end;
 
 
procedure ShowDivisibleDigits(Memo: TMemo);
{Show numbers that are even divisible by each of its digits}
{But not divisible by the product of all its digits}
var I,Cnt: integer;
var S: string;
begin
Cnt:=0;
S:='';
for I:=1 to 999 do
if IsDivisible(I) then
begin
Inc(Cnt);
S:=S+Format('%4D',[I]);
If (Cnt mod 10)=0 then S:=S+#$0D#$0A;
end;
Memo.Lines.Add('Count='+IntToStr(Cnt));
Memo.Lines.Add(S);
end;
 
</syntaxhighlight>
{{out}}
<pre>
Count=45
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|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// 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)
seq{1..999}|>Seq.filter(fun n->fN n n 0 1)|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{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>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: combinators.short-circuit grouping kernel math
math.functions math.ranges math.text.utils prettyprint sequences ;
 
Line 291 ⟶ 829:
} 3&& ;
 
1000 [1..b] [ needle? ] filter 9 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 302 ⟶ 840:
 
=={{header|FOCAL}}==
<langsyntaxhighlight FOCALlang="focal">01.10 F I=1,999;D 2
01.20 Q
 
Line 318 ⟶ 856:
02.75 S Z=I/P
02.80 I (FITR(Z)-Z)2.85,2.65
02.85 T %4,I,!</langsyntaxhighlight>
 
{{out}}
Line 367 ⟶ 905:
= 936
= 999</pre>
 
=={{header|Forth}}==
{{works with|Gforth}}
<syntaxhighlight lang="forth">: divisible? { n -- ? }
1 { p }
n
begin
dup 0 >
while
10 /mod swap
dup 0= if
2drop false exit
then
dup n swap mod 0<> if
2drop false exit
then
p * to p
repeat
drop n p mod 0<> ;
 
: main
0 { count }
1000 1 do
i divisible? if
i 4 .r
count 1+ to count
count 10 mod 0= if cr else space then
then
loop cr ;
 
main
bye</syntaxhighlight>
 
{{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>
 
=={{header|FreeBASIC}}==
This function does a bit more than the task asks for, just to make things interesting.
<langsyntaxhighlight lang="freebasic">function divdignp( n as const integer ) as ubyte
'returns 1 if the number is divisible by its digits
' 2 if it is NOT divisible by the product of its digits
Line 388 ⟶ 967:
for i as uinteger = 1 to 999
if divdignp(i) = 3 then print i;" ";
next i : print</langsyntaxhighlight>
{{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>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"rcu"
)
 
func main() {
var res []int
for n := 1; n < 1000; n++ {
digits := rcu.Digits(n, 10)
var all = true
for _, d := range digits {
if d == 0 || n%d != 0 {
all = false
break
}
}
if all {
prod := 1
for _, d := range digits {
prod *= d
}
if prod > 0 && n%prod != 0 {
res = append(res, n)
}
}
}
fmt.Println("Numbers < 1000 divisible by their digits, but not by the product thereof:")
for i, n := range res {
fmt.Printf("%4d", n)
if (i+1)%9 == 0 {
fmt.Println()
}
}
fmt.Printf("\n%d such numbers found\n", len(res))
}</syntaxhighlight>
 
{{out}}
<pre>
Numbers < 1000 divisible by their digits, but not by the product thereof:
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
 
45 such numbers found
</pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import ControlData.MonadList.Split (chunksOf)
import Data.List.Split
import Text.Printf
 
divisible :: Int -> Bool
divisible = divdgt `ap`<*> dgt
where
where dgt = map (read . pure) . show
dgt = divdgt x d =map (notread $. elempure) 0. d)show
divdgt x d =
&& 0/=x `mod` product d
notElem && all ((0==).mod x) d
&& 0 /= x `mod` product d
&& all ((0 ==) . mod x) d
 
numbers :: [Int]
numbers = filter divisible [1 ..]
 
main :: IO ()
main = putStr $ unlines $ map (concatMap $ printf "%5d") $ split
where
where n = takeWhile (< 1000) numbers
n = takeWhile (< 1000) numbers
split = chunksOf 10 n</lang>
split = chunksOf 10 n</syntaxhighlight>
 
{{out}}
Line 420 ⟶ 1,054:
848 864 888 936 999
</pre>
 
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.Split (chunksOf)
import Data.Tuple (swap)
 
-- DIVISIBLE BY ALL DIGITS, BUT NOT BY PRODUCT OF ALL DIGITS
 
p :: Int -> Bool
p n =
( ( (&&)
. all
( (&&) . (0 /=)
<*> (0 ==) . rem n
)
)
<*> (0 /=) . rem n . product
)
$ digits n
 
digits :: Int -> [Int]
digits =
unfoldr $
(bool Nothing . Just . swap . flip quotRem 10) <*> (0 <)
 
--------------------------- TEST -------------------------
main :: IO ()
main =
let xs = [1 .. 1000] >>= (\n -> [show n | p n])
w = length $ last xs
in (putStrLn . unlines) $
unwords
<$> chunksOf
10
(fmap (justifyRight w ' ') xs)
 
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</syntaxhighlight>
{{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>
 
=={{header|J}}==
<syntaxhighlight lang="j"> J>([ #~ ((10 #.^:_1inv]) ((0:~:*/@[|]) *. *./@(0:=|)) ])"0) >:i.999</lang>
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>((10 #.inv]) ... ])"0</code> extracts a predicate value for each number, with the number's digits as the left argument and the number itself as the right argument.
 
<code>((0~:*/@[|]) * */@(0=|))</code> is true if the product of the digits does not evenly divide the number (<code>(0~:*/@[|])</code>) AND all of the digits individually evenly divide the number (<code>*/@(0=|)</code>).
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">def digits:
tostring | explode | map( [.] | implode | tonumber);
 
def prod:
reduce .[] as $i (1; .*$i);
def is_divisible_by_digits_but_not_product:
. as $n
| tostring
| select( null == index("0"))
| digits
| all( unique[]; $n % . == 0)
and ($n % prod != 0);</syntaxhighlight>
'''The Task'''
<syntaxhighlight lang="jq">"Numbers < 1000 divisible by their digits, but not by the product thereof:",
(range(1; 1000)
| select(is_divisible_by_digits_but_not_product))</syntaxhighlight>
{{out}}
<pre>
<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>
Numbers < 1000 divisible by their digits, but not by the product thereof:
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|Julia}}==
<langsyntaxhighlight 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)))
</langsyntaxhighlight>{{out}}
<pre>
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168
Line 436 ⟶ 1,192:
488 515 555 636 648 666 728 777 784 824 848 864 888 936 999
</pre>
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
#!/bin/ksh
 
# Numbers divisible by their digits, but not by the product of their digits
 
# # Variables:
#
integer MAXN=1000
 
# # Functions:
#
# # Function _isdivisible(n) - return 1 if:
# # - is divisible by individual digits, and
# # - not divisible by product of digits
#
function _isdivisible {
typeset _n ; integer _n=$1
typeset _i _digit _product ; integer _i _digit _product=1
 
for ((_i=0; _i<${#_n}; _i++)); do
_digit=${_n:_i:1}
(( ! _digit )) || (( _n % _digit )) && return 0
(( _product*=_digit ))
done
return $(( _n % _product ))
}
 
######
# main #
######
 
for ((i=10; i<MAXN; i++)); do
(( ! i % 10 )) || _isdivisible ${i} || printf "%d " ${i}
done
</syntaxhighlight>
{{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>
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
PRINT COMMENT $ $
Line 460 ⟶ 1,255:
 
VECTOR VALUES FMT = $I4*$
END OF PROGRAM </langsyntaxhighlight>
{{out}}
<pre style="height: 50ex;"> 22
Line 507 ⟶ 1,302:
936
999</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[SaveDivisible,DivisibleDigits]
SaveDivisible[n_,0] := False
SaveDivisible[n_,m_] := Divisible[n,m]
DivisibleDigits[n_Integer] := AllTrue[IntegerDigits[n],SaveDivisible[n,#]&]
Select[Range[999],DivisibleDigits[#]\[And]!SaveDivisible[#,Times@@IntegerDigits[#]]&]
Length[%]</syntaxhighlight>
{{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}
45</pre>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (table 12 5 numbers)]
 
table :: num->num->[num]->[char]
table cols cw = lay . map concat . split . map fmt
where split [] = []
split ls = take cols ls : split (drop cols ls)
fmt n = reverse (take cw ((reverse (shownum n)) ++ repeat ' '))
 
numbers :: [num]
numbers = [n | n<-[1..1000]; divisible n]
 
divisible :: num->bool
divisible n = False, if digprod = 0 \/ n mod digprod = 0
= and [n mod d = 0 | d <- digits n], otherwise
where digprod = product (digits n)
 
digits :: num->[num]
digits = map (mod 10) . takewhile (>0) . iterate (div 10)</syntaxhighlight>
{{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>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strutils
 
iterator digits(n: Positive): int =
var n = n.int
while n != 0:
yield n mod 10
n = n div 10
 
var result: seq[int]
for n in 1..1000:
block check:
var m = 1
for d in n.digits:
if d == 0 or n mod d != 0: break check
m *= d
if n mod m != 0: result.add n
 
echo "Found ", result.len, " matching numbers."
for i, n in result:
stdout.write ($n).align(3), if (i + 1) mod 9 == 0: '\n' else: ' '</syntaxhighlight>
 
{{out}}
<pre>Found 45 matching numbers.
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|OCaml}}==
<syntaxhighlight lang="ocaml">let test b x =
let rec loop m n =
if n < b
then x mod n = 0 && x mod (m * n) > 0
else let d = n mod b in d > 0 && x mod d = 0 && loop (m * d) (n / b)
in loop 1 x
 
let () =
Seq.ints 1 |> Seq.take 999 |> Seq.filter (test 10)
|> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{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>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
program DivByDgtsNotByProdOfDgts;
 
function ProdDigits(n:cardinal):cardinal;
// returns product of Digits if n is divisible by digits
var
p,q,r,dgt : cardinal;
begin
q := n;
p := 1;
repeat
r := q DIV 10;
dgt := q-10*r;
if (dgt= 0)OR(n mod dgt <> 0) then
EXIT(0);
p := p*dgt;
q := r;
until q = 0;
Exit(p)
end;
 
const
LimitLow = 1;
LimitHigh = 1000;
var
i,mul,cnt : Cardinal;
BEGIN
cnt := 0;
writeln('Limits ',LimitLow,'..',LimitHigh);
For i := LimitLow to LimitHigh do
begin
mul := ProdDigits(i);
if (mul <> 0) AND (i MOD MUL<>0) then
Begin
write(i:4);
inc(cnt);
if cnt AND 15= 0 then
writeln;
end;
end;
if cnt AND 15 <> 0 then
writeln;
writeln(' count : ',cnt);
END.</syntaxhighlight>
{{out}}
<pre>
Limits 1..1000
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
count : 45</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
use warnings;
 
my @numbers = grep
{
my $n = $_;
! /0/ and $_ % eval s/\B/*/gr and 0 == grep $n % $_, split //
} 1 .. 999;
 
print @numbers . " numbers found\n\n@numbers\n" =~ s/.{25}\K /\n/gr;</syntaxhighlight>
{{out}}
<pre>
45 numbers found
 
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|Phix}}==
<!--<langsyntaxhighlight Phixlang="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: #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 522 ⟶ 1,478:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 528 ⟶ 1,484:
</pre>
 
=={{header|RakuPL/M}}==
<syntaxhighlight lang="plm">100H:
 
/* CHECK NUMBER */
<lang perl6>say "{+$_} matching numbers:\n{.batch(10)».fmt('%3d').join: "\n"}" given
DIVISIBLE: PROCEDURE (N) BYTE;
(^1000).grep: -> $n { $n.contains(0) ?? False !! all |($n.comb).map($n %% *), $n % [*] $n.comb };</lang>
DECLARE (N, I, PROD) ADDRESS;
DECLARE D BYTE;
PROD = 1;
I = N;
DO WHILE N > 0;
D = N MOD 10;
N = N / 10;
IF D = 0 THEN RETURN 0;
IF I MOD D <> 0 THEN RETURN 0;
PROD = PROD * D;
END;
RETURN I MOD PROD <> 0;
END DIVISIBLE;
 
/* CP/M BDOS CALL - PL/M DOESN'T ACTUALLY COME WITH OUTPUT ROUTINES */
BDOS: PROCEDURE (FN, ARG);
DECLARE FN BYTE, ARG ADDRESS;
GO TO 5;
END BDOS;
 
/* PRINT DECIMAL NUMBER */
PRINT$NUMBER: PROCEDURE (N);
DECLARE S (8) BYTE INITIAL ('.....',13,10,'$');
DECLARE (N, P) ADDRESS, C BASED P BYTE;
P = .S(5);
DIGIT:
P = P - 1;
C = N MOD 10 + '0';
N = N / 10;
IF N > 0 THEN GO TO DIGIT;
CALL BDOS(9, P);
END PRINT$NUMBER;
 
/* TEST THE NUMBERS 1..1000 */
DECLARE N ADDRESS;
DO N=1 TO 999;
IF DIVISIBLE(N) THEN
CALL PRINT$NUMBER(N);
END;
 
CALL BDOS(0,0);
EOF</syntaxhighlight>
{{out}}
<pre style="height:50ex;">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|Plain English}}==
<syntaxhighlight lang="plainenglish">To run:
Start up.
Loop.
If a counter is past 999, break.
If the counter is digit-divisible but non-digit-product-divisible, write the counter then " " on the console without advancing.
Repeat.
Wait for the escape key.
Shut down.
 
To decide if a number is digit-divisible but non-digit-product-divisible:
If the number is 0, say no.
Put the number into a shrinking number.
Put 1 into a digit product number.
Loop.
If the shrinking number is 0, break.
Divide the shrinking number by 10 giving a quotient and a remainder.
Multiply the digit product by the remainder.
If the number is not evenly divisible by the remainder, say no.
Put the quotient into the shrinking number.
Repeat.
If the number is evenly divisible by the digit product, say no.
Say yes.</syntaxhighlight>
{{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>
 
=={{header|Python}}==
<syntaxhighlight lang="python">'''Numbers matching a function of their digits'''
 
from functools import reduce
from operator import mul
 
 
# p :: Int -> Bool
def p(n):
'''True if n is divisible by each of its digits,
but not divisible by the product of those digits.
'''
digits = [int(c) for c in str(n)]
return not 0 in digits and (
0 != (n % reduce(mul, digits, 1))
) and all(0 == n % d for d in digits)
 
 
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''Numbers below 1000 which satisfy p
'''
xs = [
str(n) for n in range(1, 1000)
if p(n)
]
w = len(xs[-1])
print(f'{len(xs)} matching numbers:\n')
print('\n'.join(
' '.join(cell.rjust(w, ' ') for cell in row)
for row in chunksOf(10)(xs)
))
 
 
# ----------------------- GENERIC ------------------------
 
# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
'''A series of lists of length n, subdividing the
contents of xs. Where the length of xs is not evenly
divible, the final list will be shorter than n.
'''
def go(xs):
return (
xs[i:n + i] for i in range(0, len(xs), n)
) if 0 < n else None
return go
 
 
# MAIN ---
if __name__ == '__main__':
main()
</syntaxhighlight>
{{Out}}
<pre>45 matching numbers:
 
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|Quackery}}==
<syntaxhighlight lang="quackery"> [ dup 0 = iff
[ 2drop false ] done
mod 0 = ] is divisible ( n n --> b )
 
[ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] is digits ( n --> [ )
 
[ 1 swap witheach * ] is product ( [ --> n )
 
[ dup digits
dup product
dip over divisible
iff [ 2drop false ] done
true unrot
witheach
[ dip dup divisible not if
[ dip not conclude ] ]
drop ] is meetscriteria ( n n --> b )
 
1000 times [ i^ meetscriteria if [ i^ echo sp ] ]</syntaxhighlight>
 
{{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>
 
=={{header|Raku}}==
<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 };</syntaxhighlight>
 
{{out}}
Line 542 ⟶ 1,711:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX pgm finds numbersintegers divisible by its individual digits, but not by product of digs.*/
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
@ndnptitle= ' base ten integers < ' commas(hi) " that are divisible" ,
'by its digits, but not by the product of its digits'
if cols>0 then say ' index │'center(@ndnptitle, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
finds= 0; idx= 1 /*initialize # of found numbers & index*/
$= /*a list of integers found (so far). */
do j=1 for hi-1; L= length(j); != 1 /*search for integers within the range.*/
if pos(0, j)>0 then iterate /*Does J have a zero? Yes, then skip. */ /* ◄■■■■■■■■ a filter. */
do k=1 for L; x= substr(j, k, 1) /*extract a single decimal digit from J*/
if j//x\==0 then iterate j /*J ÷ by this digit? No, then skip it.*/ /* ◄■■■■■■■■ a filter. */
!= ! * x /*compute the running product of digits*/
end /*k*/
if j//!==0 then iterate /*J ÷ by its digit product? Yes, skip.*/ /* ◄■■■■■■■■ a filter. */
finds= finds + 1 /*bump the number of found integers. */
if cols==<0 then iterate /*Build the list (to be shown later)? */
$= $ right( commas(j), w) /*add the number found to the $ list.*/
if finds//cols\==0 then iterate /*have we populated a line of output? */
Line 571 ⟶ 1,740:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(finds) @ndnptitle
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 ?</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 590 ⟶ 1,759:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
Line 628 ⟶ 1,797:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 641 ⟶ 1,810:
done...
 
</pre>
 
=={{header|RPL}}==
{{works with|HP|48}}
≪ DUP →STR → n
≪ '''CASE'''
DUP 9 ≤ n "0" POS OR '''THEN''' DROP 0 '''END'''
≪ n j DUP SUB STR→ ≫ 'j' 1 n SIZE 1 SEQ <span style="color:grey">@ make list of digits</span>
DUP2 MOD ∑LIST '''THEN''' DROP2 0 '''END'''
ΠLIST MOD SIGN
'''END'''
≫ '<span style="color:blue">GOOD?</span>' STO
 
≪ 1 999 '''FOR''' j '''IF''' j <span style="color:blue">GOOD?</span> '''THEN''' j + '''END NEXT''' ≫ EVAL
{{out}}
<pre>
1: { 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|Rust}}==
<syntaxhighlight lang="rust">
fn to_digits( n : i32 ) -> Vec<i32> {
let mut i : i32 = n ;
let mut digits : Vec<i32> = Vec::new( ) ;
while i != 0 {
digits.push( i % 10 ) ;
i /= 10 ;
}
digits
}
 
fn my_condition( num : i32 ) -> bool {
let digits : Vec<i32> = to_digits( num ) ;
if ! digits.iter( ).any( | x | *x == 0 ) {
let prod : i32 = digits.iter( ).product( ) ;
return digits.iter( ).all( | x | num % x == 0 ) &&
num % prod != 0 ;
}
else {
false
}
}
 
fn main() {
let mut count : i32 = 0 ;
for n in 10 .. 1000 {
if my_condition( n ) {
print!("{:5}" , n) ;
count += 1 ;
if count % 10 == 0 {
println!( ) ;
}
}
}
println!();
}</syntaxhighlight>
{{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>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">res =(1..1000).select do |n|
digits = n.digits
next if digits.include? 0
digits.uniq.all?{|d| n%d == 0} &! (n % digits.inject(:*) == 0)
end
 
p res</syntaxhighlight>
{{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>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">^1000 -> grep {|n|
n.digits.all {|d| d `divides` n } && !(n.digits.prod `divides` n)
}.say</syntaxhighlight>
{{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>
 
=={{header|Snobol}}==
<langsyntaxhighlight lang="snobol"> define('divis(n)i,d,p') :(divis_end)
divis p = 1
i = n
Line 656 ⟶ 1,909:
loop output = divis(n) n
n = lt(n,1000) n + 1 :s(loop)
end</langsyntaxhighlight>
 
{{out}}
Line 708 ⟶ 1,961:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int, Nums
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var res = []
Line 723 ⟶ 1,974:
}
System.print("Numbers < 1000 divisible by their digits, but not by the product thereof:")
for (chunk in Lst.chunks(res, 9)) Fmt.printtprint("$4d", chunkres, 9)
System.print("\n%(res.count) such numbers found")</langsyntaxhighlight>
 
{{out}}
Line 736 ⟶ 1,987:
 
45 such numbers found
</pre>
 
=={{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
int N, M, Digit, Product;
[Product:= 1;
M:= N;
repeat M:= M/10;
Digit:= rem(0);
if Digit = 0 then return false;
if rem(N/Digit) then return false;
Product:= Product * Digit;
until M=0;
return rem(N/Product) # 0;
];
 
int Count, N;
[Count:= 0;
for N:= 1 to 1000-1 do
if Check(N) then
[IntOut(0, N);
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
CrLf(0);
IntOut(0, Count);
Text(0, " such integers found below 1000.
");
]</syntaxhighlight>
 
{{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
45 such integers found below 1000.
</pre>
9,476

edits