Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions
Numbers divisible by their individual digits, but not by the product of their digits. (view source)
Revision as of 11:34, 6 January 2024
, 4 months ago→{{header|Wren}}: Minor tidy
No edit summary |
m (→{{header|Wren}}: Minor tidy) |
||
(17 intermediate revisions by 13 users not shown) | |||
Line 5:
<br>where <big>'''n < 1,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}}==
<
org 100h
section .text
Line 58 ⟶ 92:
section .data
db '*****'
dbuf: db 13,10,'$'</
{{out}}
Line 109 ⟶ 143:
=={{header|Action!}}==
<
BYTE d
INT tmp,prod
Line 137 ⟶ 171:
FI
OD
RETURN</
{{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]
Line 146 ⟶ 180:
=={{header|Ada}}==
<
with Ada.Integer_Text_Io;
Line 184 ⟶ 218:
end if;
end loop;
end Numbers_Divisible;</
{{out}}
<pre> 22 33 44 48 55 66 77 88 99 122 124 126 155 162 168
Line 191 ⟶ 225:
=={{header|ALGOL 68}}==
<
INT max number = 999;
INT number count := 0;
Line 215 ⟶ 249:
FI
OD
END</
{{out}}
<pre>
Line 224 ⟶ 258:
=={{header|ALGOL-M}}==
<
integer function mod(a, b);
integer a, b;
Line 263 ⟶ 297:
end;
write("");
end</
{{out}}
<pre> 22 33 44 48 55 66 77 88 99 122
Line 272 ⟶ 306:
=={{header|ALGOL W}}==
<
% returns true if n is divisible by its digits but not the product of its %
% digits, false otherwise %
Line 306 ⟶ 340:
end if_divisibleByDigitsButNotDigitProduct__i
end for_i
end.</
{{out}}
<pre>
Line 317 ⟶ 351:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
{{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
Line 345 ⟶ 418:
return(n % p)
}
</syntaxhighlight>
{{out}}
<pre>
Line 357 ⟶ 430:
=={{header|BASIC}}==
<
20 FOR I=1 TO 999
30 N=I: P=1
Line 367 ⟶ 440:
90 IF N THEN 40
100 IF I MOD P <> 0 THEN PRINT I,
110 NEXT I</
{{out}}
<pre> 22 33 44 48 55
Line 380 ⟶ 453:
=={{header|BCPL}}==
<
let divisible(n) = valof
Line 404 ⟶ 477:
$)
wrch('*N')
$)</
{{out}}
<pre> 22 33 44 48 55 66 77 88 99 122
Line 413 ⟶ 486:
=={{header|C}}==
<
int divisible(int n) {
Line 440 ⟶ 513:
return 0;
}</
{{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|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
Line 451 ⟶ 557:
=={{header|COBOL}}==
<
PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD.
Line 500 ⟶ 606:
MULTIPLY DIGIT(D) BY NDIV.
IF NDIV IS NOT EQUAL TO N SET OK TO 0.
NOPE. EXIT.</
{{out}}
<pre style='height: 50ex;'> 22
Line 549 ⟶ 655:
=={{header|Cowgol}}==
<
sub divisible(n: uint16): (r: uint8) is
Line 585 ⟶ 691:
n := n + 1;
end loop;
print_nl();</
{{out}}
Line 594 ⟶ 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#}}==
<
// 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>
{{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}}
<
math.functions math.ranges math.text.utils prettyprint sequences ;
Line 618 ⟶ 829:
} 3&& ;
1000 [1..b] [ needle? ] filter 9 group simple-table.</
{{out}}
<pre>
Line 629 ⟶ 840:
=={{header|FOCAL}}==
<
01.20 Q
Line 645 ⟶ 856:
02.75 S Z=I/P
02.80 I (FITR(Z)-Z)2.85,2.65
02.85 T %4,I,!</
{{out}}
Line 697 ⟶ 908:
=={{header|Forth}}==
{{works with|Gforth}}
<
1 { p }
n
Line 725 ⟶ 936:
main
bye</
{{out}}
Line 738 ⟶ 949:
=={{header|FreeBASIC}}==
This function does a bit more than the task asks for, just to make things interesting.
<
'returns 1 if the number is divisible by its digits
' 2 if it is NOT divisible by the product of its digits
Line 756 ⟶ 967:
for i as uinteger = 1 to 999
if divdignp(i) = 3 then print i;" ";
next i : print</
{{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
Line 764 ⟶ 975:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 800 ⟶ 1,011:
}
fmt.Printf("\n%d such numbers found\n", len(res))
}</
{{out}}
Line 815 ⟶ 1,026:
=={{header|Haskell}}==
<
import Text.Printf
Line 834 ⟶ 1,045:
where
n = takeWhile (< 1000) numbers
split = chunksOf 10 n</
{{out}}
Line 846 ⟶ 1,057:
and another approach might be to obtain (unordered) digit lists numerically, rather than by string conversion.
<
import Data.List (unfoldr)
import Data.List.Split (chunksOf)
Line 882 ⟶ 1,093:
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</
{{Out}}
<pre> 22 33 44 48 55 66 77 88 99 122
Line 891 ⟶ 1,102:
=={{header|J}}==
<syntaxhighlight lang="j">
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'''
<
tostring | explode | map( [.] | implode | tonumber);
Line 910 ⟶ 1,126:
| digits
| all( unique[]; $n % . == 0)
and ($n % prod != 0);</
'''The Task'''
<
(range(1; 1000)
| select(is_divisible_by_digits_but_not_product))</
{{out}}
<pre>
Line 967 ⟶ 1,183:
=={{header|Julia}}==
<
foreach(p -> print(rpad(p[2], 5), p[1] % 15 == 0 ? "\n" : ""), enumerate(filter(isonlydigdivisible, 1:1000)))
</
<pre>
22 33 44 48 55 66 77 88 99 122 124 126 155 162 168
Line 978 ⟶ 1,194:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 1,012 ⟶ 1,228:
(( ! 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}}==
<
PRINT COMMENT $ $
Line 1,039 ⟶ 1,255:
VECTOR VALUES FMT = $I4*$
END OF PROGRAM </
{{out}}
<pre style="height: 50ex;"> 22
Line 1,086 ⟶ 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}}==
<
iterator digits(n: Positive): int =
Line 1,107 ⟶ 1,360:
echo "Found ", result.len, " matching numbers."
for i, n in result:
stdout.write ($n).align(3), if (i + 1) mod 9 == 0: '\n' else: ' '</
{{out}}
Line 1,116 ⟶ 1,369:
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}}===
<
program DivByDgtsNotByProdOfDgts;
Line 1,161 ⟶ 1,429:
writeln;
writeln(' count : ',cnt);
END.</
{{out}}
<pre>
Line 1,171 ⟶ 1,439:
=={{header|Perl}}==
<
use strict;
Line 1,182 ⟶ 1,450:
} 1 .. 999;
print @numbers . " numbers found\n\n@numbers\n" =~ s/.{25}\K /\n/gr;</
{{out}}
<pre>
Line 1,197 ⟶ 1,465:
=={{header|Phix}}==
<!--<
<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 1,210 ⟶ 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>
<!--</
{{out}}
<pre>
Line 1,217 ⟶ 1,485:
=={{header|PL/M}}==
<
/* CHECK NUMBER */
Line 1,262 ⟶ 1,530:
CALL BDOS(0,0);
EOF</
{{out}}
<pre style="height:50ex;">22
Line 1,311 ⟶ 1,579:
=={{header|Plain English}}==
<
Start up.
Loop.
Line 1,332 ⟶ 1,600:
Repeat.
If the number is evenly divisible by the digit product, say no.
Say yes.</
{{out}}
<pre>
Line 1,339 ⟶ 1,607:
=={{header|Python}}==
<
from functools import reduce
Line 1,391 ⟶ 1,659:
if __name__ == '__main__':
main()
</syntaxhighlight>
{{Out}}
<pre>45 matching numbers:
Line 1,402 ⟶ 1,670:
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ dup 0 = iff
[ 2drop false ] done
mod 0 = ] is divisible ( n n --> b )
Line 1,425 ⟶ 1,692:
drop ] is meetscriteria ( n n --> b )
1000 times [ i^ meetscriteria if [ i^ echo sp ] ]</
{{out}}
Line 1,432 ⟶ 1,699:
=={{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 1,445 ⟶ 1,711:
=={{header|REXX}}==
<
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
Line 1,477 ⟶ 1,743:
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 ?</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,493 ⟶ 1,759:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,531 ⟶ 1,797:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,544 ⟶ 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}}==
<
n.digits.all {|d| d `divides` n } && !(n.digits.prod `divides` n)
}.say</
{{out}}
<pre>
Line 1,556 ⟶ 1,897:
=={{header|Snobol}}==
<
divis p = 1
i = n
Line 1,568 ⟶ 1,909:
loop output = divis(n) n
n = lt(n,1000) n + 1 :s(loop)
end</
{{out}}
Line 1,620 ⟶ 1,961:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./
var res = []
Line 1,635 ⟶ 1,974:
}
System.print("Numbers < 1000 divisible by their digits, but not by the product thereof:")
System.print("\n%(res.count) such numbers found")</
{{out}}
Line 1,651 ⟶ 1,990:
=={{header|XPL0}}==
<
\Return 'true' if N is divisible by its digits and not by the product of its digits
int N, M, Digit, Product;
Line 1,677 ⟶ 2,016:
Text(0, " such integers found below 1000.
");
]</
{{out}}
|