| Bytes | Lang | Time | Link |
|---|---|---|---|
| 053 | TIBASIC TI83 | 250319T155150Z | absolute |
| 007 | Vyxal 3 | 250318T103440Z | Themooni |
| 011 | Pip | 250320T191227Z | DLosc |
| 066 | C gcc | 250320T024715Z | ceilingc |
| 022 | APLNARS | 250318T102320Z | Rosario |
| 043 | AWK | 250317T193640Z | xrs |
| 033 | JavaScript Node.js | 231023T070058Z | l4m2 |
| 013 | Uiua | 231023T052555Z | Bubbler |
| 003 | Nekomata + e | 231020T135608Z | alephalp |
| 7125 | Vyxal | 231020T132105Z | pacman25 |
| 086 | Python 3 | 210410T200719Z | Symmetr1 |
| 109 | Desmos | 210410T203604Z | Ethan Ch |
| 031 | APL Dyalog Unicode | 210410T160544Z | Andrew O |
| 095 | PowerShell | 210410T043228Z | wasif |
| 249 | Scratch | 210410T033754Z | Nolan |
| 022 | K ngn/k | 210404T173256Z | coltim |
| 074 | Excel | 210323T183655Z | Axuary |
| 107 | Regex ECMAScript | 210322T032657Z | Deadcode |
| 086 | R | 190905T172835Z | Sumner18 |
| 017 | J | 210323T195506Z | Jonah |
| 029 | Perl 5 p | 170911T211257Z | Xcali |
| 050 | Python 3 | 190908T160342Z | Luciano |
| 009 | Japt | 170704T115044Z | Shaggy |
| 040 | ruby n | 190905T172515Z | histocra |
| 039 | Julia 1.0 | 190905T164542Z | gggg |
| 024 | APL Dyalog Unicode | 190905T163057Z | J. Sall& |
| 004 | 05AB1E | 190905T150425Z | Grimmy |
| 059 | Kotlin 1.1 | 170911T222215Z | jrtapsel |
| 010 | Pyth | 170911T164958Z | Mr. Xcod |
| 051 | PHP | 170704T125103Z | Jör |
| 177 | VBScript | 170708T195139Z | aAaa aAa |
| 017 | CJam | 170706T060315Z | Esolangi |
| 061 | Haskell | 170705T161952Z | Laikoni |
| 162 | Haskell | 170705T103522Z | Sergii M |
| 042 | Ruby 2.4 | 170705T110922Z | G B |
| 037 | Retina | 170705T090936Z | Neil |
| 048 | PHP | 170704T150629Z | Titus |
| 054 | Python 3 | 170704T211448Z | C McAvoy |
| 066 | Python 2 | 170704T193544Z | Mr. Xcod |
| 027 | Perl 6 | 170704T165313Z | Sean |
| 004 | Jelly | 170704T153615Z | Dennis |
| 041 | JavaScript ES6 | 170704T114827Z | Neil |
| 057 | Mathematica | 170704T144556Z | ZaMoC |
| 008 | 05AB1E | 170704T134029Z | Adnan |
| 083 | C# | 170704T123609Z | TheLetha |
| 009 | Neim | 170704T120509Z | Erik the |
| 056 | Python 3 | 170704T115909Z | Rod |
| 042 | Mathematica | 170704T120214Z | Martin E |
| 010 | Brachylog | 170704T115524Z | Fatalize |
| 008 | Jelly | 170704T115050Z | Erik the |
TI-BASIC (TI-83), 53 24 Bytes
Ans→A
int(10fPart(Ansseq(₁₀^(⁻X-1),X,0,log(Ans→A
max(seq(sum(Ans(X)=Ans),X,1,dim(Ans
Ans=not(sum(fPart(A/∟A
+29 bytes due to not accounting for digit uniqueness
Demonstration:
126:prgmCDGF2E
1
152:prgmCDGF2E
0
55:prgmCDGF2E
0
Explanation:
Ans→A ; Set A to the input for usage later
int(10fPart(Ansseq(₁₀^(⁻X-1),X,0,log(Ans→A ; Set ∟A to the digits of the input
max(seq(sum(Ans(X)=Ans),X,1,dim(Ans ; Get the maximum occurences of each
; digit in the input
not(sum(fPart(A/∟A ; Check if each digit is evenly
; divisible (1 if true, 0 if false)
Ans= ; Both results must be equal
; Implicit print of Ans
The digit extraction was derived from this routine.
Note: TI-BASIC is a tokenized language. Character count does not equal byte count.
Program size is equal to \$MEM\: byte\: count - program\: name\: length - 9\: bytes\$.
Vyxal 3, 7 bytes
u=↸f≛A∧
Vyxal It Online!
-1 byte by reordering conditions
-4 bytes by Wierd Glyphs and myself by using roll and avoiding a useless lambda declaration
u=↸f≛A∧
u= # is the number with unique digits equal to itself?
∧ # and
↸ # push number twice
f≛ # do the number's digits divide it?
A # is it true for all of them?
💎
Created with the help of Luminespire.
<script type="vyxal3">
u=↸f≛A∧
</script>
<script>
args=[["126"],["3915"],["55"],["54"],["7"],["13"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
Pip, 11 bytes
a-UQa=Ma%^a
Explanation
a-UQa=Ma%^a
= ; Test if these two results are equal:
a ; Number read from command-line argument
- ; Subtract
UQa ; The same number uniquified
; and
^a ; Split the number into a list of digits
a% ; Take the number mod each of those digits
M ; Max
The first expression is 0 if the number's digits are all unique and >= 10 if they are not. The second expression is 0 if the number is divisible by all its digits and some nonzero single digit if not. Therefore, the two expressions will only be equal if both of them are 0, satisfying the Lynch-Bell condition.
C (gcc), 66 bytes
w,y,z,i;f(x){for(z=w=x;i*=(y=x%10)&&(z*=i^=y);x/=10)z*=w%y<1;x=z;}
Returns non zero for "true" and zero for "false".
Less golfed:
w,y,z,i;
f(x){
z=w=x;
while(i*=(y=x%10)&&(z*=i^=y)){ // loop from least sig digit to most
// break loop if we see a (leading) zero
// or a duplicate digit
z*=w%y<1; // divisibility test
x/=10; // next digit
}
return z;
}
APL(NARS), 22 chars
{∧/(a≡∪a),0=⍵∣⍨a←⍎¨⍕⍵}
Here one read from lefth to right, in the code from right to left
"make the number input ⍵ one list of digits (the chars of the number) for each of them, execute them, this means we have a list
of digits now not as chars but as numbers, than assign these to a
then make 0=⍵ mod for this array of number digits, add in the list
of the boolean that the digits have to be without repetition ∧/ "
test:
f←{∧/(a≡∪a),0=⍵∣⍨a←⍎¨⍕⍵}
f¨7 126 54 55 3915
┌5─────────┐
│ 1 1 0 0 1│
└~─────────┘
AWK, 43 bytes
{for(x=1;i++<NF;)x*=!b[$i]++&&!($0%$i)}$0=x
{for(x=1; # default to yes
i++<NF;) # each digit
x*= # multiply by 1 or 0, true or false
!b[$i]++ # test uniqueness
&&!($0%$i)} # test divisibility
$0=x # set output
JavaScript (Node.js), 33 bytes
s=>[...s].every(y=e=>y[e]^=s%e<1)
If an e appears twice then s%e<1 is still true, and y[e]^= returns 0
Uiua, 13 bytes
≍⊝⌊.÷-@0$"_".
Not too bad, given the bulky syntax to convert a number into its decimal digits. The main idea is taken from alephalpha's Nekomata answer.
Note: the symbol for "match" (test if two arrays are structurally equal as a whole) has been changed from ≅ to ≍.
Also, this code doesn't work when the input contains a 0, because division by 0 gives NaN, floor of NaN is still NaN, and two NaNs are equal.
≍⊝⌊.÷-@0$"_". input: a positive integer
$"_" stringify the input
-@0 subtract '0' from each char, giving decimal digits as numbers
÷ . divide the original number by each digit
≍⊝⌊. test if this array, floored and deduplicated, still equals itself
A version that also handles zero digits (giving falsy) in 15 bytes (Try it):
≍⊚=0⊃◿⊛-@0$"_".
-@0$"_" decimal digits of input
⊃◿⊛ . push (input % digits, classification of digits)
(classify: assign a unique index to each unique element)
⊚=0 indices where input % digits == 0
≍ match?
The final match gives 1 if and only if the number is Lynch-Bell, because:
indices where input % digits == 0has the length equal to the number of digits if and only ifinput % digits == 0is all true,- its result is precisely
0 1 2 ... x-1wherexis the number of digits in that case, and - the classification is the same if and only if the digits are all unique.
Nekomata + -e, 3 bytes
Ɗ¦ů
Ɗ¦ů
Ɗ Decimal digits
¦ Divided by, and check if the result are integers
ů Check if all elements are unique
Vyxal, 57 bitsv2, 7.125 bytes
:₌Kf↔$f⁼
Bitstring:
010100100010101011101010110011110100011101011011111010110
Python 3, 88 86 bytes
def f(n):
s=""
for i in n:
if i in s or int(n)%int(i)!=0:return 0
s+=i
return 1
Fixed that it wasn't running with whitespace removed - thanks to @caird coinheringaahing
Desmos, 109 bytes
n=q-48
l=n.length
abs(\prod_{a=1}^l\prod_{b=a+1}^{l}(n[b]-n[a])(1-sign(mod(\sum_{c=1}^ln[c]10^{l-c},n).max)))
There's got to be a better way to do this, but I can't come up with it right now. This is sort of split up into a few sections:
n=q-48
This turns codepoints into digits for convenience's sake
\prod_{a=1}^l\prod_{b=a+1}^{l}(n[b]-n[a])
This checks if any two digits are equal, and if so, returns 0
\sum_{c=1}^ln[c]10^{l-c}
This turns the list of digits into the number
1-sign(mod(\sum_{c=1}^ln[c]10^{l-c},n).max)
This uses the previous section to check if any digit isn't divisible by the sum, and if so, returns 0
Then we turn this into a 1 if the result succeeds both tests and 0 if it fails one. We can cut out 5 bytes if we accept any non-zero number as true by removing the abs( from the start of the third equation and ) from the end, but I'm not sure if negative numbers really count as truthy. We can also get rid of 6 bytes if we can accept a list of digits as input rather than a string.
APL (Dyalog Unicode), 31 bytes
{∧/(0=⍺|⍨¨⍵)∧(⊢≡∪)⍵}∘(10⊥⍣¯1⊢)⍨
∧/ ⍝ reduction by logical AND
0=⍺|⍨¨⍵ ⍝ divisibility check
∧ ⍝ logical AND
(⊢≡∪)⍵ ⍝ check for unique digits
∘ ⍝ function composition operator (Beside)
10⊥⍣¯1⊢ ⍝ convert to array of digits
⍨ ⍝ commute operator (Selfie), used to copy input to left side of the composed function
PowerShell, 95 bytes
param($n)$a="$n"|% t*y;if($n-eq([int](($a|gu)-join''))){
($a|%{12%[int]"$_"})-contains0}else{0}
Scratch, 249 bytes
I feel as though this could be improved by a few bytes, but I'm not sure...
when gf clicked
ask()and wait
set[C v]to()
set[N v]to(answer
repeat(length of(n
change[C v]by(1
add(letter(C)of(N))to[B v
end
say[T
repeat(C
set[D v]to(item(1)of[B v
delete(1)of[B v
if<<[B v]contains(D)?>or<not<((N)/(D))=(round((N)/(D)))>>>then
say(
Alternatively, 34 blocks.
K (ngn/k), 22 bytes
{&/~(t*t~?t:10\x)!\:x}
(...t:10\x)get the individual digits of the input, storing int(t*t~?t...)if the digits aren't all unique, multiply them by 0 (otherwise leave them as-is)(...)!\:xmod the input by each of the digits (withx mod 0==x)&/~are all the remainders 0?
Excel, 76 74 bytes
-2 bytes using ROWS instead of COUNTA
=LET(n,LEN(A2),d,MID(A2,SEQUENCE(n),1),AND(ROWS(UNIQUE(d))=n,MOD(A2,d)=0))
LET( 'Assign Variables
n,LEN(A2) ' n = # of digits
d,MID(A2,SEQUENCE(n),1) ' d = array of digits
AND(ROWS(UNIQUE(d))=n,MOD(A2,d)=0) 'Result
ROWS(UNIQUE(d))=n ' # unique d = n
MOD(A2,d)=0 ' number mod d = 0
AND( ) ' and all tests
Original
=LET(n,LEN(A2),d,MID(A2,SEQUENCE(n),1),AND(COUNTA(UNIQUE(d))=n,MOD(A2,d)=0))
Regex (ECMAScript), 194 171 167 164 155 145 142 107 bytes
-35 bytes (142 → 107) thanks to H.PWiz; this is a complete reimplementation. The primary sources of bytes saved are using tail = floor((tail + Digit) / 10) - Digit instead of tail = floor(tail / 10) , and "factoring" the assertions – reusing the expression at the end to mean two different things.
^(?!(x{1,9})(((?=(x*)((\1\4){9}x*))\5)*(?=(x*)(\7{9}$))\8\1|(?!\1*$))((?=(x*)((\1\10){9}x*))\11)*(x{10})*$)
Takes its input in unary, as a sequence of x characters whose length represents the number.
This was an interesting challenge to solve without molecular lookahead or variable-length lookbehind. The restrictions result in a completely different algorithm being used.
Note that the above version does not reject numbers that have a zero as at least one of their digits, as per the challenge's rules. It costs 2 bytes 10 bytes to handle zero correctly, for a total of 144 117 bytes:
^(?!(x{0,9})(((?=(x*)((\1\4){9}x*))\5)*(?=(x*)(\7{9}$))\8\1|(?!\1*$))((?=(x*)((\1\10){9}x*))\11)*((x{10})+|(?!\1))$)x
The commented version below describes the 144 117 byte version:
^ # tail = N = input number
(?! # Negative lookahead - Assert that there's no way for the following to match:
(x{0,9}) # \1 = conjectured digit; tail -= \1
# Assert one of the following two alternatives:
(
# Assert that \1 occurs as a digit of N, and chop it away (and all the digits
# right of it) from tail, returning only the digits left of its found instance.
(
(?=
(x*)((\1\4){9}x*) # \4 = floor((tail + \1) / 10) - \1;
# \5 = tool to make tail = \4
)
\5 # tail = \4
)*
(?=
(x*)(\7{9}$) # assert tail % 10 == 0; \7 = tail / 10;
# \8 = tool to make tail = \7
)
\8\1 # tail = \7 - \1 (all the digits of N left of where \1
# was found, minus \1)
|
# Assert that \1 is not a divisor of N
(?!\1*$)
)
# Assert that \1 occurs as a digit in tail+\1, which will either be a second occurrence
# found further left in N of an already-found occurrence, or any occurrence of a digit
# that is not a divisor of N.
(
(?=
(x*)((\1\10){9}x*) # \10 = floor((tail + \1) / 10) - \1;
# \11 = tool to make tail = \10
)
\11 # tail = \10
)*
# Assert one of the following two alternatives:
(
# Assert tail > 0 and tail % 10 == 0, which means we've found an occurrence of \1
# that isn't the leftmost digit
(x{10})+
|
# Assert tail == 0 and tail != \1, which means we've found that \1 is the leftmost
# digit of N and \1 != 0 (which needs to be asserted, otherwise we'd always find
# a phantom occurrence of the digit 0 left of the leftmost digit of N)
(?!\1)
)$
)
x # Prevent N=0 from being matched
The version above is very slow, so I'm keeping my 144 byte solution here:
^(?!(?=(x*)\1{9})(x{0,9})(?=(x{10})*$|(.*(?=\1$)((?=(x*)(\6{9}x*))\7)*?\B(?=(x*)(\8{9}\2$))\9))((?!\2*$)|\4((?=(x*)(\12{9}x*))\13)*\2(x{10})*$))
^ # tail = N = input number
(?! # Negative lookahead - Assert that there's no way for the following to match:
(?=(x*)\1{9}) # \1 = floor(N / 10)
(x{0,9}) # \2 = take a guess at a numeral that may occur as any
# digit of N, even the rightmost one; tail -= \2
# Assert that \2 occurs as a digit in N, and if it does, identify the rest of N to
# the left of that digit, so that we can set tail equal to it later (so we can later
# assert that \2 is not duplicated).
(?=
(x{10})*$ # Skip the rest if we picked the rightmost digit of N
|
( # \4 = tool to make tail = \8
.*(?=\1$) # tail = \1
# Loop through chopping away each rightmost decimal digit of tail, one by one
(
(?=
(x*) # \6 = floor(tail / 10)
(\6{9}x*) # \7 = tool to make tail = \6
)
\7 # tail = \6
)*? # Only iterate until we find the first match of the
# following:
\B # Leave at least one digit remaining (to avoid
# thinking we've found a zero-digit when there isn't
# actually one)
(?=(x*)(\8{9}\2$)) # \8 = floor(tail/10); \9 = tool to make tail = \8;
# assert that tail % 10 == \2, i.e. that our guessed
# digit matches the current rightmost digit of tail
\9 # tail = \8
)
)
# \2 is now one of the decimal digits of N.
# Assert that either of the following two alternatives could match, and in the
# context outside of the negative lookahead, that neither of them can match:
(
# Assert tail is not divisible by \2. It doesn't matter that tail == N-\2
# instead of N, because that doesn't alter tail's divisibility by \2.
(?!\2*$)
| # or...
# Assert that \2 doesn't occur as any decimal digit left of where it was found
\4 # tail = \8 if \8 is set, otherwise no change; this
# relies on ECMAScript NPCG behavior.
# Chop away any number (minimum 0) of rightmost decimal digits of tail
(
(?=(x*)(\12{9}x*)) # \12 = floor(tail / 10);
# \13 = tool to make tail = \12
\13 # tail = \12
)* # Iterate any number of times, minimum 0
\2 # tail -= \2
(x{10})*$ # assert tail is divisible by 10
)
)
Regex (ECMAScript + (?*)), 81 bytes
^(?!(?*(((?=(x*)(\3{9}(x*)))\4)+))((?!\5+$)|\1((?=(x*)(\8{9}x*))\9)*\5(x{10})*$))
This challenge is much easier to solve with molecular lookahead; it's the version I implemented first.
Working on this alerted me to the presence of a bug in my regex engine (now fixed).
^ # tail = N = input number
(?! # Negative lookahead - Assert that there's no way for the following to match:
(?* # Molecular lookahead - cycle through all possible matches of the following:
( # \1 = tool to make tail = the final value of \3
# Loop through chopping away each rightmost decimal digit of tail, one by one
(
(?=(x*)(\3{9}(x*))) # \3 = floor(tail / 10); \4 = tool to make tail = \3;
# \5 = tail % 10
\4 # tail = \3
)+ # Iterate at least once, otherwise \5 could be unset
# The above loop relies on ECMAScript no-empty-optional behavior. This
# prevents it from matching when the final result of zero is again divided
# by 10, which would yield a value of \5 = 0, making it look like one of N's
# digits was zero and preventing all values of N from matching.
)
)
# \5 is now one of the decimal digits of N, and tail==N again
# Assert that either of the following two alternatives could match, and in the context
# outside of the negative lookahead, that neither of them can match:
(
(?!\5+$) # Assert tail is not divisible by \5
| # or...
# Assert that the \5 doesn't occur as any decimal digit left of where it was found
\1 # tail = \3
# Chop away any number (minimum 0) of rightmost decimal digits of tail
(
(?=(x*)(\8{9}x*)) # \8 = floor(tail / 10); \9 = tool to make tail = \8;
\9 # tail = \8
)* # Iterate any number of times, minimum 0
\5 # tail -= \5
(x{10})*$ # assert tail is divisible by 10
)
)
Regex (ECMAScript 2018), 85 bytes
^(?!((?=(x*)(\2{9}(x*)))\3)+((?<=(?=(?!\4+$))^.*)|((?=(x*)(\7{9}x*))\8)*\4(x{10})*$))
This is a port of the molecular lookahead version. The most direct port would be replacing (?*A)B with A(?<=(?=B)^.*), but that would result in an 89 byte regex.
^ # tail = N = input number
(?! # Negative lookahead - Assert that there's no way for the following to match:
# Loop through chopping away each rightmost decimal digit of tail, one by one
(
(?=(x*)(\2{9}(x*))) # \2 = floor(tail / 10); \3 = tool to make tail = \2;
# \4 = tail % 10
\3 # tail = \2
)+ # Iterate at least once, otherwise \4 could be unset
# The above loop relies on ECMAScript no-empty-optional behavior. This prevents it
# from matching when the final result of zero is again divided by 10, which would
# yield a value of \4 = 0, making it look like one of N's digits was zero and
# preventing all values of N from matching.
# \4 is now one of the decimal digits of N, and tail==\2
# Assert that either of the following two alternatives could match, and in the context
# outside of the negative lookahead, that neither of them can match:
(
(?<= # Variable-length lookbehind - used to go back to start
(?=
# now tail==N again
(?!\4+$) # Assert tail is not divisible by \4
)
^.* # Go back to start, then execute the above lookahead
)
| # or...
# now tail==\2
# Assert that the \4 doesn't occur as any decimal digit left of where it was found
# Chop away any number (minimum 0) of rightmost decimal digits of tail
(
(?=(x*)(\7{9}x*)) # \7 = floor(tail / 10); \8 = tool to make tail = \7;
\8 # tail = \7
)* # Iterate any number of times, minimum 0
\4 # tail -= \4
(x{10})*$ # assert tail is divisible by 10
)
)
R, 86 bytes
x=scan(,'');a=as.double;all(table(utf8ToInt(x))==1)&&all(!a(x)%%a(el(strsplit(x,""))))
Takes input as a string. I certainly feel like this is golfable.
R, 62 bytes
Golf by Giuseppe
all(table(d<-utf8ToInt(x<-scan(,''))-48)<2)&all(!strtoi(x)%%d)
J, 17 bytes
[:(<.-:~.)10&#.%]
Take input as list of digits.
10&#.%]The list of quotients. Returns floats.(<.-:~.)Does the unique of that list~.match-:the list formed by rounding every element down to an integer<.?
Python 3, 50 bytes
lambda n:all(int(n)%int(d)+n.count(d)<2for d in n)
Returns True if the (zero-free) number is a Lynch-Bell number, False otherwise.
ruby -n, 40 bytes
p gsub(/./){$'[$&]||$_.to_i%$&.hex}<?0*8
Read in the number as a string. Substitute each character (digit) with a subsequent occurrence of that character, if present, or the whole number modulo that digit. This will result in a string of only 0s if and only if this is a Lynch-Bell number. Why? If there's a repeated digit, every instance of the last stays the same, and since the input doesn't contain zeroes that means a non-zero digit. Otherwise, we're just checking whether every digit evenly divides the number.
Since there are no 8-or-more-digit Lynch-Bell numbers (formal proof: OEIS says so), checking whether the resulting string is lexicographically earlier than the string '00000000' is equivalent to checking whether it's all zeroes.
Julia 1.0, 39 bytes
f(x,d=digits(x))=rem.(x,d)==0*unique(d)
rem.(x,d) is a vector containing the remainders after dividing x by each digit in x. 0*unique(d) is a vector with length equal to the number of unique digits, with all zero values. Check if they are equal.
APL (Dyalog Unicode), 24 bytes
{((,⍵)≡∪⍵)×∧/0=(⍎¨⍵)|⍎⍵}
Simple Dfn, can probably be golfed a bit more. Yield standard APL booleans 1 for truthy, 0 for falsy.
It's worth to mention that the function takes the arguments as strings rather than ints.
How:
{((,⍵)≡∪⍵)×∧/0=(⍎¨⍵)|⍎⍵} ⍝ Dfn, argument ⍵.
⍎⍵ ⍝ Convert ⍵ to integer
| ⍝ Modulus
(⍎¨⍵) ⍝ Each digit in ⍵
0= ⍝ Equals 0? Returns a vector of booleans
∧/ ⍝ Logical AND reduction
× ⍝ multiplied by (the result of)
( ∪⍵) ⍝ unique elements of ⍵
≡ ⍝ Match
(,⍵) ⍝ ⍵ as a vector; the Match function then returns 1 iff all digits in ⍵ are unique
Kotlin 1.1, 98 66 59 bytes
{i->i.none{i.toInt()%(it-'0')>0}&&i.length==i.toSet().size}
Beautified
{i ->
// None of the digits are not factors
i.none { i.toInt() % (it-'0') > 0 }
// AND
&&
// None of the digits are repeated
i.length == i.toSet().size
}
Test
var L:(String)-> Boolean =
{i->i.none{i.toInt()%(it-'0')>0}&&i.length==i.toSet().size}
data class TestData(val input: String, val output: Boolean)
fun main(args: Array<String>) {
var inputs = listOf(
TestData("7", true),
TestData("126", true),
TestData("54", false),
TestData("55", false),
TestData("3915", true)
)
for (test in inputs) {
if (L(test.input) != test.output) {
throw AssertionError(test.toString())
}
}
println("Test Passed")
}
Pyth, 10 bytes
qiRQKjQT{K
How?
qiRQKjQT{K ~ Full program.
jQT ~ The list of decimal digits of the input.
K ~ Assign to a variable K.
iRQ ~ For each decimal digit...
i Q ~ ... Get the greatest common divisor with the input itself.
{K ~ K with the duplicate elements removed.
q ~ Is equal? Output implicitly.
Pyth, 11 bytes
&!f%sQsTQ{I
How?
&!f%sQsTQ{I ~ Full program, with implicit input.
f Q ~ Filter over the input string.
%sQsT ~ The input converted to an integer modulo the current digit.
~ Keeps it if it is higher than 0, and discards it otherwise.
! ~ Negation. If the list is empty, returns True, else False.
& {I ~ And is the input invariant under deduplicating? Output implicitly.
PHP, 51 bytes
prints zero for true and one for false
for(;$c=$argn[$i++];$$c=1)$t|=$$c||$argn%$c;echo$t;
PHP, 62 bytes
prints zero for true and one for false
for($a=$argn;$c=$a[$i];)$t|=strpos($a,$c)<+$i++||$a%$c;echo$t;
VBScript, 177 bytes
Hey all, this is my very first CG post, and first attempt, so hope I followed all the rules...
Function L(s)
dim i,j,k,m,n
j = Len(s)
redim a(j)
n = 0
for i = 0 to j-1
A(i) = Mid(s,i+1,1)
m = m + s Mod A(i)
if j = 1 then
else
for k = 0 to i - 1
if A(i) = A(k) then n = n + 1
next
end if
next
if m + n = 0 then L = "y" else L = "n"
End Function
This can be run from Notepad by adding a line at the end
Msgbox L(InputBox(""))
And then saving it as .vbs, then double click.
Explanation:
Function L(s) 'creates the function "L" taking test number as input
dim i,j,k,t,m,n 'variables
j = Len(s) '"j" gets length of test number
redim a(j) 'creates array "a", size is length of test number
n = 0 'sets repeat character counter "n" to zero
for i = 0 to j-1 'for length of string
A(i) = Mid(s,i+1,1) 'each array slot gets one test number character
m = m + s Mod A(i) '"m" accumulates moduli as we test divisibility of each digit
if j = 1 then 'if test number is of length 1, it passes (do nothing)
else 'otherwise, gotta test for repeats
for k = 0 to i - 1 'for each digit already in array, test against current digit
if A(i) = A(k) then n = n + 1
'repeat char counter "n" stores no of repeats
next 'proceed through array looking for repeat
end if
next 'test next digit for divisibility and repeats
if m + n = 0 then L = "y" else L = "n"
'check for any repeats and moduli,
'then return yes or no for LynchBelledness
End Function
VBScript is a bit of blunt instrument for golfing, but hey, I haven't learned Ruby yet...
CJam, 17 bytes
CJam is the Java of golfing languages. It's even interpreted in Java!
{_Ab__L|=@@f%:+>}
Explanation:
{ e# Stack: 3915
_ e# Duplicate: 3915 3915
Ab e# Digits in base 10: 3915 [3 9 1 5]
__ e# Duplicate twice: 3915 [3 9 1 5] [3 9 1 5] [3 9 1 5]
L| e# Remove duplicates: 3915 [3 9 1 5] [3 9 1 5] [3 9 1 5]
= e# Test equality: 3915 [3 9 1 5] 1
@@ e# Rotate twice: 1 3915 [3 9 1 5]
f% e# Modulo each: 1 [0 0 0 0]
:+ e# Sum: 1 0
> e# Greater than: 1
} e# Output: 1 (truthy)
Haskell, 61 bytes
(#)=<<show
(d:r)#n=notElem d r&&mod n(read[d])<1&&r#n
_#_=0<3
Defines an anonymous function (#)=<<show which, given a number, returns True or False.
Haskell, 260 241 201 162 bytes
f([x])=1<2
f(x:xs)=not(x`elem`xs)&&(f xs)
r n i= n`mod`(read[(show n!!i)]::Int)==0
q n 0=r n 0
q n i=r n i&&q n(i-1)
p n=length(show n)-1
s n=q n(p n)&&f(show n)
Explanation
f ([x]) = True f function checks for
f (x:xs) = not(x `elem` xs) && (f xs) repeated digits
r n i = n `mod` (read [(show n !! i)] :: Int) == 0 checks whether num is
divisible by i digit
q n 0 = r n 0 checks wether n divisible
q n i = r n i && q n (i-1) by all of its digits
p n = length (show n) - gets length of number
s n = (q n (p n)) && (f (show n)) sums it all up!!!
Have significantly shortened thanx to Laikoni
Ruby 2.4, 42 bytes
->x{(r=x.digits)|[]==r&&r.none?{|f|x%f>0}}
(No TIO yet, sorry)
Retina, 37 bytes
(.).*\1
0
.
<$&$*1>$_$*
<(1+)>\1+
^$
Try it online! Link includes test cases. Explanation: The first stage replaces any duplicate digit with a zero. The second stage replaces each digit with its unary representation followed by the unary representation of the original number. The third stage then computes the remainder of the division of original number by each non-zero digit. If the number is a Lynch-Bell number then this will delete everything and this is tested for by the final stage.
PHP, 62 48 bytes
while($i=$argn[$k++])$r|=$argn%$i|$$i++;echo!$r;
Run as pipe with -nR or test it online. Empty output for falsy, 1 for truthy.
breakdown
while($i=$argn[$k++]) # loop through digits
$r|= # set $r to true if
$argn%$i # 1. number is not divisible by $i
|$$i++; # 2. or digit has been used before
echo!$r; # print negated $r
Python 3, 54 bytes
Returns False when a number is a Lynch-Bell number. Takes strings as input. Came up with on my own but very similar to Rod's. I would've commented under his post but I don't have any reputation yet.
lambda s:len({*s})<len(s)+any(int(s)%int(c)for c in s)
Python 2, 66 bytes
This is a solution in Python 2, whose whole purpose is to output True for truthy and False for falsy:
lambda n:len(set(n))==len(n)and not any((int(n)%int(x)for x in n))
Perl 6, 27 bytes
{$_%%.comb.all&&[!=] .comb}
.combis a method which, when given no arguments, splits a string into its individual characters. A number is implicitly converted into a string, and so.combreturns its digits..comb.allis an and-junction of all of the digits.$_ %% .comb.allis an and-junction of the divisibility of the input argument$_by all of its digits. For example, if$_is123, the junction isall(True, False, True), which collapses toFalsein a truthy context.[!=] .combreduces the digits of the input argument with the!=operator, which evaluates toTrueif the digits are all different.
Jelly, 6 4 bytes
Dg⁼Q
How it works
Dg⁼Q Main link. Argument: n
D Decimal; convert n to base 10.
g Take the GCD of each decimal digit k and n.
For each k, this yields k if and only if k divides n evenly.
Q Unique; yield n's decimal digits, deduplicated.
⁼ Test the results to both sides for equality.
JavaScript (ES6), 42 41 bytes
s=>![...s].some((e,i)=>s%e|s.search(e)<i)
Takes input as a string and returns true or false as appropriate. Edit: Saved 1 byte thanks to @RickHitchcock. Other versions:
Takes input as a string and returns 0 or 1 (i.e. logical inverse) for 40 bytes:
s=>/(.).*\1/.test(s)|[...s].some(e=>s%e)
Takes input as a number and returns 0 or 1 for 43 bytes:
n=>/(.).*\1/.test(n)|[...''+n].some(e=>n%e)
Takes input as a number and returns 1 or 0 for 45 bytes:
n=>!/(.).*\1/.test(n)&![...''+n].some(e=>n%e)
Mathematica, 57 bytes
Tr@Boole[IntegerQ/@Union[s=#/IntegerDigits@#]]==Length@s&
C#, 87 83 bytes
using System.Linq;s=>s.Distinct().Count()==s.Length&s.All(c=>int.Parse(s)%(c-48)<1)
I wrote this in notepad before testing in Visual Studio, where it worked fine, so just realised I'm now that level of nerd...
Full/Formatted Version:
using System;
using System.Linq;
class P
{
static void Main()
{
Func<string, bool> f = s => s.Distinct().Count() == s.Length
& s.All(c => int.Parse(s) % (c - 48) < 1);
Console.WriteLine(f("7"));
Console.WriteLine(f("126"));
Console.WriteLine(f("54"));
Console.WriteLine(f("55"));
Console.WriteLine(f("3915"));
Console.ReadLine();
}
}
Python 3, 56 bytes
lambda n:any(int(n)%int(x)for x in n)or len(n)>len({*n})
Output False if it's IS a Lynch-Bell number, True otherwise.
Mathematica, 42 bytes
0!=##&@@d&&##&@@((d=IntegerDigits@#)∣#)&
I think 0!=##&@@d&&##&@@ is a new low in readability for Mathematica...
Explanation
Some of the basic syntactic sugar used here:
&has very low precedence and turns everything left of it into an unnamed function.&&is just theAndoperator.#is the argument of the nearest enclosing unnamed function.##is a sequence of all of the function's arguments.@is prefix notation for function calls, i.e.f@x == f[x].@@isApply, which passes the elements of a list as individual arguments to a function, i.e.f@@{a,b,c} == f[a,b,c].
With that out of the way...
(d=IntegerDigits@#)
This should be fairly self-explanatory: this gives us a list of the input's decimal digits and stores the result in d.
(...∣#)
This tests the input for divisibility by each of its digits (because the divisibility operator is Listable). This gives us a list of Trues and Falses.
...&@@...
We apply the function on the left-hand side to the list of booleans, such that each boolean is a separate argument.
...&@@d
We apply another function to d, so that the individual digits are given as separate arguments. The function is 0!=##&, i.e. Unequal[0, d1, d2, ...]. It checks that all the digits are distinct (and that they are distinct from 0 but that's given by the challenge, and if it wasn't, it wouldn't be a divisor anyway). 0!=##& is really just a 1-byte saver on using Unequal itself, and it works because there's a 1-byte element (0) that we know is not present. So this first thing checks that the digits are unique. Let's call this result U
...&&##
Again, this is really just shorthand for And[U, ##]. With ## being a sequences, the individual booleans from the initial divisibility check are expanded into the And, so we get And[U, d1∣n, d2∣n, ...] which checks that both the digits are unique and each digit divides the input.
Brachylog, 10 bytes
≠g;?z%ᵐ=h0
Explanation
≠ All digits are different
g;?z Zip the input with each of its digits
%ᵐ Map mod
= All results are equal
h0 The first one is 0