# Generate Monday Numbers

Monday numbers, as defined by Gamow in this question over on Puzzling, are positive integers N with the following three properties:

• The decimal representation of N does not contain the digit 0
• The decimal representation of N does not contain any digit twice
• N is divisible by every digit D that occurs in its decimal representation

Note that these are alternatively known, in the OEIS, as Lynch-Bell numbers.

### Examples:

• 15 is a Monday number, as it's divisible by both 1 and 5 and satisfies the other two conditions
• 16 is not, because it's not divisible by 6.
• The number 22 is not, because though it satisfies conditions 1 and 3, it fails condition 2.

Here's the list of the first 25 Monday numbers to get you started (there are 548 total):

1 2 3 4 5 6 7 8 9 12 15 24 36 48 124 126 128 132 135 162 168 175 184 216 248

The challenge here is to write the shortest code that generates the full sequence of Monday numbers, from 1 up to 9867312 (proven on that question to be the largest possible).

Your code should take no input, and output should be to STDOUT or equivalent, with your choice of delimiter. All the usual code-golf rules apply, and Standard Loopholes are prohibited.

• Related – FryAmTheEggman Sep 29 '15 at 15:03
• Also known as Lynch-Bell numbers. – Geobits Sep 29 '15 at 15:21
• @Geobits Thanks - I couldn't find it on OEIS for some reason. – AdmBorkBork Sep 29 '15 at 15:23
• You should have posted this challenge yesterday... – mbomb007 Sep 29 '15 at 16:42
• @mbomb007 I would have - didn't see Gamow's question until this morning, though! – AdmBorkBork Sep 29 '15 at 16:44

# Japt, 21 17 bytes

-4 thanks to Shaggy

1e7õ fÈ¥ì_â f myX

Try it online!

• 1e5o fÈ¥ì â ¬k_¥0ªX%Z is faster, but sadly returns 0 :( – ASCII-only Feb 26 '19 at 1:13
• I think this works for 18. – Shaggy Feb 26 '19 at 8:43
• @Shaggy Huh, I swear !<whatever> never works when I try it. Also, huh... didn't realize those had no-op as the default function (basically) – ASCII-only Feb 26 '19 at 9:38
• 17 bytes – Shaggy Feb 26 '19 at 10:09

# PowerShell (reference implementation)

Whoops! Forgot to post this right when I asked the question! I meant to post this as an example / reference implementation, as it's pseudocode-y enough that people should be able to follow the logic. Doesn't seem to serve much purpose now, given the plethora of other answers, but I might as well still post it.

for($i=1;$I -le 9867312; $i++){$monday=$true$index=0
$num=[char[]]$i.ToString()
$digits=@() while($monday -and $index -lt$num.length){
switch($num[$index]){
'0'{$a=0} '1'{$a=1}
'2'{$a=2} '3'{$a=3}
'4'{$a=4} '5'{$a=5}
'6'{$a=6} '7'{$a=7}
'8'{$a=8} '9'{$a=9}
}
if([array]::IndexOf($digits,$a) -ge 0){ $monday=$false }
if($a -eq 0){$monday=$false } elseif(($i%$a) -gt 0){$monday=$false }$index++
$digits+=$a
}
if($monday){$i}
}

# CJam, 23 bytes

1e7{_Ab___|=+:df%:+!},p

That's far too slow for the online interpreter, but you can it for a subset: Chrome | Firefox

### Test run

$cjam <(echo '1e7{_Ab___|=+:df%:+!},p') # Output [1 2 3 4 5 6 7 8 9 12 15 24 36 48 124 126 128 132 135 162 168 175 184 216 248 264 312 315 324 384 396 412 432 612 624 648 672 728 735 784 816 824 864 936 1236 1248 1296 1326 1362 1368 1395 1632 1692 1764 1824 1926 1935 1962 2136 2184 2196 2316 2364 2436 2916 3126 3162 3168 3195 3216 3264 3276 3492 3612 3624 3648 3816 3864 3915 3924 4128 4172 4236 4368 4392 4632 4872 4896 4932 4968 6132 6192 6312 6324 6384 6432 6912 6984 8136 8496 8736 9126 9135 9162 9216 9315 9324 9432 9612 9648 9864 12384 12648 12768 12864 13248 13824 13896 13968 14328 14728 14832 16248 16824 17248 18264 18432 18624 18936 19368 21384 21648 21784 21864 23184 24168 24816 26184 27384 28416 29736 31248 31824 31896 31968 32184 34128 36792 37128 37296 37926 38472 39168 39816 41328 41832 42168 42816 43128 43176 46128 46872 48216 48312 61248 61824 62184 64128 68712 72184 73164 73248 73416 73962 78624 79128 79632 81264 81432 81624 81936 82416 84216 84312 84672 87192 89136 89712 91368 91476 91728 92736 93168 93816 98136 123648 123864 123984 124368 126384 129384 132648 132864 132984 134928 136248 136824 138264 138624 139248 139824 142368 143928 146328 146832 148392 148632 149328 149832 162384 163248 163824 164328 164832 167328 167832 168432 172368 183264 183624 184392 184632 186432 189432 192384 193248 193824 194328 194832 198432 213648 213864 213984 214368 216384 218736 219384 231648 231864 231984 234168 234816 236184 238416 239184 241368 243168 243768 243816 247968 248136 248976 261384 263184 273168 281736 283416 284136 291384 293184 297864 312648 312864 312984 314928 316248 316824 318264 318624 319248 319824 321648 321864 321984 324168 324816 326184 328416 329184 341928 342168 342816 346128 348192 348216 348912 349128 361248 361824 361872 362184 364128 364728 367248 376824 381264 381624 382416 384192 384216 384912 391248 391824 392184 394128 412368 413928 416328 416832 418392 418632 419328 419832 421368 423168 423816 427896 428136 428736 431928 432168 432768 432816 436128 438192 438216 438912 439128 461328 461832 463128 468312 469728 478296 478632 481392 481632 482136 483192 483216 483672 483912 486312 489312 491328 491832 493128 498312 612384 613248 613824 613872 614328 614832 618432 621384 623184 623784 627984 631248 631824 632184 634128 634872 641328 641832 643128 648312 671328 671832 681432 684312 689472 732648 732816 742896 746928 762384 768432 783216 789264 796824 813264 813624 814392 814632 816432 819432 823416 824136 824376 831264 831624 832416 834192 834216 834912 836472 841392 841632 842136 843192 843216 843912 846312 849312 861432 864312 873264 891432 894312 897624 912384 913248 913824 914328 914832 918432 921384 923184 927864 931248 931824 932184 934128 941328 941832 943128 948312 976248 978264 981432 984312 1289736 1293768 1369872 1372896 1376928 1382976 1679328 1679832 1687392 1738296 1823976 1863792 1876392 1923768 1936872 1982736 2137968 2138976 2189376 2317896 2789136 2793168 2819376 2831976 2931768 2937816 2978136 2983176 3186792 3187296 3196872 3271968 3297168 3298176 3619728 3678192 3712968 3768912 3796128 3816792 3817296 3867192 3869712 3927168 3928176 6139728 6379128 6387192 6389712 6391728 6719328 6719832 6731928 6893712 6913872 6971328 6971832 7168392 7198632 7231896 7291368 7329168 7361928 7392168 7398216 7613928 7639128 7829136 7836192 7839216 7861392 7863912 7891632 7892136 7916328 7916832 7921368 8123976 8163792 8176392 8219736 8312976 8367912 8617392 8731296 8796312 8912736 8973216 9163728 9176328 9176832 9182376 9231768 9237816 9278136 9283176 9617328 9617832 9678312 9718632 9723168 9781632 9782136 9812376 9867312]$ cjam <(echo '1e7{_Ab___|=+:df%:+!},,') # Count
548

%DẸ<DQƑ$µ548# (Language is newer than the challenge.) Try it online! # Explanation %DẸ<DQƑ$       Helper function: is this a Monday number?
<             Acts as a “not P and Q” gate here, between:
%D                 Take N modulo each of its digits.
Ẹ                  Is any truthy? (NaN is truthy.)
And:
DQƑ$Are the digits are unique (0/1)? µ548# Find the first 548 matches. • %D<ŒQẠµ100# should be equivalent. – Dennis Jan 1 '19 at 2:18 # APL (Dyalog Unicode), 27 bytesSBCS Full program. ⍸(∧/'0'∘∊<≡∘∪⍨>⍎¨|⍎)∘⍕¨⍳1E9 Try it online! (only up to 10⁵ due to run time — change 1E5 to 1E9 for full list) ⍳1E9integers from 1 to a 10⁹ ()∘⍕¨ on the string representation of each: execute it (giving the original integer back) ⍎¨| division remainders of that when divided by the execution of each character of that …> mask for whether the following is greater than each of those: ≡∘∪⍨ is the character list identical to the unique characters in itself? …< mask for whether the following is less than each of those: '0'∘∊ is the character zero a member of the string representation? ∧/ are those all true? (lit. AND-reduction) indices where true # Common Lisp, 146 bytes (dotimes(i 1e8)(and(equal(setq a(format()"~d"i))(remove-duplicates a))(not(find #\0 a))(every(lambda(x)(=(mod i(-(char-code x)48))0))a)(print i))) Try it online! (where it stops at 3928176 after 60 seconds). # C, 111 h(){int i=0,k,z,m,j;for(;i++<1E7;){for(m=-1,k=i;(z=k%10)&&m&(j=1<<z)&&i%z==0;k/=10,m&=~j);k||printf("%u ",i);}} ungolfed, and partial test: h() {int i=0,k,z,m,j; for(;i++<1E7;) {for(m=-1,k=i;(z=k%10)&&m&(j=1<<z)&&i%z==0;k/=10,m&=~j); k||printf("%u ",i); } } main(){h();printf("\n");} 1 2 3 4 5 6 7 8 9 12 15 24 36 48 124 126 128 132 135 162 168 175 184 216 248 264 312 315 324 384 396 412 432 612 624 648 672 728 735 784 816 824 864 936 1236 1248 1296 1326 1362 1368 1395 1632 1692 1764 1824 1926 1935 1962 2136 2184 2196 2316 2364 2436 2916 3126 3162 3168 3195 3216 3264 3276 3492 3612 3624 3648 3816 3864 3915 3924 4128 4172 4236 4368 4392 4632 4872 4896 4932 4968 6132 6192 ... 9283176 9617328 9617832 9678312 9718632 9723168 9781632 9782136 9812376 9867312 Easy in C... • 103 bytes – ceilingcat Jan 2 '19 at 17:53 • @ceilingcat I use some your suggestions... It is ok or I came back with the previous saved post? I do not use variables without "int" because here it doesn't compile – RosLuP Jan 3 '19 at 10:34 # Coffeescript, 83 bytes No merit for this answer (and therefore no upvote please), this is a translation to coffeescript of @ETHproductions solution /(.).*\1|0/.test(i)||+(""+i).replace(/./g,(j)=>i%j)||console.log i for i in[0..1e7] Thanks for your implementation, it helped me to understand some tricks under the hood that can be useful. Wanted to comment your solution but not enough reputation to do that. Hereafter is also the ES5 solution (101 bytes), running on node.js for(i=1;i<=1e7;i++)/(.).*\1|0/.test(i)||+(""+i).replace(/./g,function(j){return i%j})||console.log(i) # Retina, 77 bytes Language postdates challenge 24+%$
$$"$_ %(~.+ ^¶$.&
\d
*_
)|'0L$ (?!(_+)\b.* \1+$)
$.' A0|(.).*\1 Try it online! Note: The TIO link only checks up to 8191, but that is taking 40+ seconds already and the algorithm is at least quadratic in the biggest number it checks in both time and memory. The solution shown above would theoretically check up to 224-1, which includes all Lynch-Bell numbers # PHP, 140 bytes for(;;$p=1,$n++)if(!in_array(0,$a=str_split($n))&&count($a)==count(array_unique($a))){foreach($a as$b)if($n%$b!=0)$p=0;echo$p==1?"$n ":'';}

Usage

php -r file.php

Output terminal

1 2 3 4 5 6 7 8 9 12 15 24 36 48 124 126 128 132 135 162 168 175 184 216 248 264 312 315 324 384 396 412 432 612 624 648 672 728 735 784 816 824 864 936 1236 1248 1296 1326 1362 1368 1395 1632 1692 1764 1824 1926 1935 1962 2136 2184 2196 2316 2364 2436 2916 3126 3162 3168 3195 3216 3264 3276 3492 3612 3624 3648 3816 3864 3915 3924 4128 4172 4236 4368 4392 4632 4872 4896 4932 4968 6132 6192 6312 6324 6384 6432 6912 6984 8136 8496 8736 9126 9135 9162 9216 9315 9324 9432 9612 9648 9864 12384 12648 12768 12864 13248 13824 13896 13968 14328 14728 14832 16248 16824 17248 18264 18432 18624 18936 19368 21384 21648 21784 21864 23184 24168 24816 26184 27384 28416 29736 31248 31824 31896 31968 32184 34128 36792 37128 37296 37926 38472 39168 39816 41328 41832 42168 42816 43128 43176 46128 46872 48216 48312 61248 61824 62184 64128 68712 72184 73164 73248 73416 73962 78624 79128 79632 81264 81432 81624 81936 82416 84216 84312 84672 87192 89136 89712 91368 91476 91728 92736 93168 93816 98136 123648 123864 123984 124368 126384 129384 132648 132864 132984 134928 136248 136824 138264 138624 139248 139824 142368 143928 146328 146832 148392 148632 149328 149832 162384 163248 163824 164328 164832 167328 167832 168432 172368 183264 183624 184392 184632 186432 189432 192384 193248 193824 194328 194832 198432 213648 213864 213984 214368 216384 218736 219384 231648 231864 231984 234168 234816 236184 238416 239184 241368 243168 243768 243816 247968 248136 248976 261384 263184 273168 281736 283416 284136 291384 293184 297864 312648 312864 312984 314928 316248 316824 318264 318624 319248 319824 321648 321864 321984 324168 324816 326184 328416 329184 341928 342168 342816 346128 348192 348216 348912 349128 361248 361824 361872 362184 364128 364728 367248 376824 381264 381624 382416 384192 384216 384912 391248 391824 392184 394128 412368 413928 416328 416832 418392 418632 419328 419832 421368 423168 423816 427896 428136 428736 431928 432168 432768 432816 436128 438192 438216 438912 439128 461328 461832 463128 468312 469728 478296 478632 481392 481632 482136 483192 483216 483672 483912 486312 489312 491328 491832 493128 498312 612384 613248 613824 613872 614328 614832 618432 621384 623184 623784 627984 631248 631824 632184 634128 634872 641328 641832 643128 648312 671328 671832 681432 684312 689472 732648 732816 742896 746928 762384 768432 783216 789264 796824 813264 813624 814392 814632 816432 819432 823416 824136 824376 831264 831624 832416 834192 834216 834912 836472 841392 841632 842136 843192 843216 843912 846312 849312 861432 864312 873264 891432 894312 897624 912384 913248 913824 914328 914832 918432 921384 923184 927864 931248 931824 932184 934128 941328 941832 943128 948312 976248 978264 981432 984312 1289736 1293768 1369872 1372896 1376928 1382976 1679328 1679832 1687392 1738296 1823976 1863792 1876392 1923768 1936872 1982736 2137968 2138976 2189376 2317896 2789136 2793168 2819376 2831976 2931768 2937816 2978136 2983176 3186792 3187296 3196872 3271968 3297168 3298176 3619728 3678192 3712968 3768912 3796128 3816792 3817296 3867192 3869712 3927168 3928176 6139728 6379128 6387192 6389712 6391728 6719328 6719832 6731928 6893712 6913872 6971328 6971832 7168392 7198632 7231896 7291368 7329168 7361928 7392168 7398216 7613928 7639128 7829136 7836192 7839216 7861392 7863912 7891632 7892136 7916328 7916832 7921368 8123976 8163792 8176392 8219736 8312976 8367912 8617392 8731296 8796312 8912736 8973216 9163728 9176328 9176832 9182376 9231768 9237816 9278136 9283176 9617328 9617832 9678312 9718632 9723168 9781632 9782136 9812376 9867312

Test Online

# C# (Visual C# Interactive Compiler), 103 bytes

for(int i=0;++i<1e7;)if((i+"").GroupBy(c=>c).All(g=>g.Count()<2&g.Key>48&&i%(g.Key-48)<1))Write(i+" ");

Try it online!

To be fair, this started off as RobIII's answer, but it has improved quite a bit.

-5 bytes thanks to @EmbodimentOfIgnorance!

This answer also uses the C# REPL which wasn't quite released at the time that this question was asked.

Less golfed code...

// iterate all possible numbers
for(int i=0;++i<1e7;)
// convert number to string
if((i+"")
// group by digits
.GroupBy(c=>c)
// ensure each digit only occurs
// once, the current number is
// divisible by each digit, and that
// there are no zeros
.All(g=>g.Count()<2&
g.Key>48&&
i%(g.Key-48)<1
)
)
// print current number if tests pass
Write(i+" ");

# Perl 6, 42 bytes

put grep {!/(.).*$0/&&$_%%+.comb.all},^1e7

Try it online!

A full program that creates a bunch of warnings, but eventually goes through. Times out on TIO, but you can test it by changing the final range, for example 1000.

### Explanation:

grep {                          },^1e7    # Filter from the range 0 to 10000000
!/(.).*$0/ # The number does not contain duplicate digits && # And$_%%             # The number is divisible by
.all  # all of
+.comb      # The digits of the number
# Note that \$_%%0 is False
put  # And print the list

# APL(NARS), 43 chars, 86 bytes

{x/⍨{{0∊⍵:0⋄⍵≢∪⍵:0⋄∧/0=⍵∣w}⍎¨⍕w←⍵}¨x←⍳⍵}1E7

here in 45 seconds arrive to 1E5 (not 1E7 as example would pretend) This below would be the translation of one C solution in APL... in 50 seconds it arrive to 3E5

r←h;i;j;k;z;m
i←0⋄r←⍬
→0×⍳3E7<i+←1⋄m←9⍴1⋄k←i
→4×⍳0=z←10∣k⋄→2×⍳0=z⊃m⋄→2×⍳0≠z∣i⋄k←⌊k÷10⋄m[z]←0⋄→3
→2×⍳k≠0⋄r←r,i⋄→2

in 50 seconds 1..297864 it seems 3 time faster of first function, it would arrive to 1E7 in 28 minutes here.

If it is written the function for doing combination:

c←{0≥k←⍺-1:,¨⍵⋄k≥i←≢w←⍵:,¯1⋄↑,/{w[⍵],¨k c w[(⍳i)∼⍳⍵]}¨⍳i-k}

and the function for doing permutation:

q←{1≥k←≢w←,⍵:⊂,⍵⋄a←⍳k⋄↑,/{w[⍵],¨q w[a∼⍵]}¨a}

for build the code for doing the result:

↑,/{10⊥¨↑,/(0≠≢¨v)/v←{b/⍨z←{∧/0=⍵∣10⊥⍵}¨b←q⍵}¨⍵ c⍳9}¨⍳7

but it runs only in 1 minute and 33 seconds for 1..1E7 it seems the algorithm is faster than the one used above functions (but it not goes below 1 minute, at last here)

# C# (Visual C# Interactive Compiler), 85 bytes

for(int i=1;i<1e7;i++)if((i+"").All(c=>i%(c-48d)<1&(i+"").Count(x=>x==c)<2))Print(i);

Try it online!

## K 44 Bytes

&{(&/x=b*_x%b)&(b~?b)&x&~0 in b:10\:x}'!_1e7
• _1e7 generates 0..9999999

• &{..}'!_1e7 applies lambda to each 0.9999999 and prints indexes where lambda is true

• Lambda has four expressions (..)&(..)&..&.. and return true if each .. is true (& is and)

• b:10\:x set b to decimal digits of argument x

• ~0 in b reads "not 0 in b"

• x&~0 in b true if x is not 0 and not 0-digit in b. x& is necessary because 10:0 generates empty digits list instead of list with digit 0

• b~?b reads as "b match unique b", and its true iff non-repeated digits in b

• _x%b reads as "floor of x dividedBy each item of b"

• &/x=b*_x%b reads "all x = digits * quotient of integer divission"

# Charcoal, 23 bytes

ΦＥＸχ⁷Ｉι∧Πι¬Φι∨⁻μ⌕ιλ﹪κＩλ

Try it online! for numbers of up to five digits (too slow for larger numbers). Explanation:

χ                    Predefined variable 10
Ｘ                     Raised to power
⁷                   Literal 7
Ｅ                      Map over implicit range
ι                 Current value
Ｉ                  Cast to string
Φ                       Filter over list of strings
ι              Current string
Π               Digital product (is nonzero)
∧                Logical And
¬             Logical Not
ι           Current string
Φ            Filter over digits as characters
μ         Inner index
⁻          Minus
⌕        First position of
λ      Current character in
ι       Current string
∨          Logical Or
κ   Outer index
﹪    Modulo
λ Current character
Ｉ  Cast to integer