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

m
(→‎OCaml: add)
m (→‎{{header|Wren}}: Minor tidy)
(4 intermediate revisions by 3 users not shown)
Line 739:
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#}}==
Line 1,248 ⟶ 1,313:
<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}}==
Line 1,719 ⟶ 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>
 
Line 1,853 ⟶ 1,961:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var res = []
Line 1,868 ⟶ 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")</syntaxhighlight>
 
9,476

edits