# Is it a Lynch-Bell number?

You will be given a positive, whole number (that will never contain a 0) as input. Your task is to check whether it is a Lynch-Bell number or not.

A number is a Lynch-Bell number if all of its digits are unique and the number is divisible by each of its digits.

In fact, there are actually only 548 Lynch-Bell numbers, so hard-coding is a possibility, but will almost certainly be longer.

126 is a Lynch-Bell number because all of its digits are unique, and 126 is divisible by 1, 2, and 6.

You can output any truthy and falsy value.

## Examples:

7 -> truthy
126 -> truthy
54 -> falsy
55 -> falsy
3915 -> truthy


This is OEIS A115569.

• Related. (Asks for all the numbers instead of posing a decision problem.) Jul 4, 2017 at 11:54
• Can I take input as a string? Jul 4, 2017 at 12:38
• @TheLethalCoder Of course you can, that's a silly question.
– Okx
Jul 4, 2017 at 12:40
• @Okx Not all challenge posters are as flexible in their allowed inputs as you so always worth an ask. Jul 4, 2017 at 12:41

# Perl 5-p, 34 29 bytes

$_=!grep$k{$_}++|"@F"%$_,/./g


Try it online!

# 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.

Try it online!

# R, 62 bytes

Golf by Giuseppe

all(table(d<-utf8ToInt(x<-scan(,''))-48)<2)&all(!strtoi(x)%%d)


Try it online!

• Mar 23, 2021 at 18:53
• @Giuseppe How you do it I'll never know... Mar 23, 2021 at 20:01
• Practice, haha. I started with minor golfs like substituting strtoi for as.double, then noticed that digits were being extracted twice (once with utf8ToInt and once with strsplit), so I got them once at the beginning (with strsplit), then tried to get rid of the strtoi entirely by using utf8ToInt()-48 (which I didn't notice before, but that's also shorter than strsplit), but I wasn't able to get it down all the way. Mar 23, 2021 at 20:51
• Another failed approach was to try to collapse the all(...)&all(...) into one all(...&...), which errored out. I did manage to find 62 bytes by better in-lining of assignments, though, so that's neat. Mar 23, 2021 at 20:53

# Nekomata + -e, 3 bytes

Ɗ¦ů


Attempt This Online!

Ɗ¦ů
Ɗ       Decimal digits
¦      Divided by, and check if the result are integers
ů     Check if all elements are unique

• Q: Is there a way that you could adjust this so it doesn't need a flag? Or is the existence/nonexistence of the non-deterministic solutions 'invisible' from within the program? Oct 20, 2023 at 15:41
• @DominicvanEssen Nekomata doesn't have truthy/falsy. so the flag -e is needed for every decision-problem challenge. Oct 21, 2023 at 0:12
• @DominicvanEssen You can add an n (\countValue) to the end of the code so that it returns 1 and 0 (Attempt This Online!). But they are not truthy/falsy by this definition on meta. Oct 21, 2023 at 0:20
• Surely 'non-fail' and 'fail' could be considered to be analogous to 'truthy' and 'falsy'? So andThen behaves as "if X doesn't fail, then ..." like this, and if behaves as "if X fails, then ..." like this... Oct 21, 2023 at 8:00
• (in which case, Ɗ¦ů is already valid as a decision function as-is, returning 'non-fail' or 'fail', and the -e flag is just for pretty output, and not really required...) Oct 21, 2023 at 8:02

# Neim, 9 bytes

𝐮ℚ₁𝐅₁𝕌₁ℚ𝕒


Try it online!

-2 thanks to Okx.

Hmm, there's a nice symmetry... oO.O.O.Oo

• You can golf 𝐂D𝐮𝔼 to 𝐮ℚ (uniquify, check for equality ignoring types)
– Okx
Jul 4, 2017 at 12:11
• Still room for golfing there ;)
– Okx
Jul 4, 2017 at 12:19
• @Okx Hmm...I don't see anything particularly interesting there. Jul 4, 2017 at 12:26

# Perl 6, 27 bytes

{$_%%.comb.all&&[!=] .comb}  Try it online! • .comb is a method which, when given no arguments, splits a string into its individual characters. A number is implicitly converted into a string, and so .comb returns its digits. • .comb.all is an and-junction of all of the digits. • $_ %% .comb.all is an and-junction of the divisibility of the input argument $_ by all of its digits. For example, if $_ is 123, the junction is all(True, False, True), which collapses to False in a truthy context.
• [!=] .comb reduces the digits of the input argument with the != operator, which evaluates to True if the digits are all different.

# Ruby 2.4, 42 bytes

->x{(r=x.digits)|[]==r&&r.none?{|f|x%f>0}}


(No TIO yet, sorry)

# PHP, 51 bytes

prints zero for true and one for false

for(;$c=$argn[$i++];$$c=1)t|=$$c||$argn%$c;echo$t;


Try it online!

# 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;


Try it online!

# Kotlin 1.1, 9866 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")
}


# 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.

Try it online!

# PowerShell, 95 bytes

param($n)$a="$n"|% t*y;if($n-eq([int](($a|gu)-join''))){ ($a|%{12%[int]"\$_"})-contains0}else{0}


Try it online!

• 54 and 1232 should be falsy Apr 10, 2021 at 11:31

# 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


Try it online!

# 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)))


View it in Desmos

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.

# 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

• Welcome to Code Golf! Your version without whitespace doesn't work, but it's an easy fix and golf Apr 10, 2021 at 20:40
• @cairdcoinheringaahing Thanks for checking, is there a syntax guide anywhere for writing functions without whitespace without messing them up and having them not run? Apr 10, 2021 at 20:49
• Not sure about a syntax guide but feel free to check out our New users guide for golfing in Python for more info Apr 10, 2021 at 20:50
• @cairdcoinheringaahing Okay thanks. What actually is it about the syntax that isn't allowed? Apr 10, 2021 at 20:52
• So long as the program runs as is, it's a valid submission. As the program doesn't run when you remove the newlines, it isn't a valid submission Apr 10, 2021 at 20:53

# JavaScript (Node.js), 33 bytes

s=>[...s].every(y=e=>y[e]^=s%e<1)


Try it online!

If an e appears twice then s%e<1 is still true, and y[e]^= returns 0