| Bytes | Lang | Time | Link |
|---|---|---|---|
| 091 | AWK | 250729T145803Z | xrs |
| 060 | Dyalog APL | 250728T230141Z | Aaron |
| 009 | 05AB1E | 170927T074345Z | Adnan |
| 017 | Japt | 170927T094933Z | Shaggy |
| 115 | Haskell | 171003T042104Z | Sherlock |
| 022 | Pyth | 170927T050703Z | user7468 |
| 016 | Actually | 170927T020100Z | user4594 |
| 013 | Husk | 170927T013826Z | H.PWiz |
| 015 | Jelly | 170927T003829Z | fireflam |
| 085 | Mathematica | 170927T004912Z | Misha La |
AWK, 91 bytes
{for(;i++<$1;)if(0~$1%i)for(j=1;j++<i;)if(0~i%j){for(k=1;j%++k;);k~j&&x+=j}}$0=$1%(x+1)?0:1
Feels clunky. Prints 1 for true or nothing for false.
{for(;i++<$1;)if(0~$1%i) # check divisors
for(j=1;j++<i;)if(0~i%j){ # check those for divisors
for(k=1;j%++k;);k~j&&x+=j} # primality
}$0=$1%(x+1)?0:1 # set output
Dyalog APL, 60
{0{⍵=0:⍺-1⋄(⍺+1)∇⍵-{⍵(⌊=∨)+/1,{⊃⌽⍵/⍨2=≢⍵}¨(∪⊢∨⍳)¨∘∊⍣3⊢⍵}⍺}⍵}
So my biggest win was realizing that my primality check was finding the divisors a third time, so prefixing my find-divisors train with enlist and then applying to each argument, I could call the same thing 3 times in a row which I do with the power operator.
Explanation
{0{⍵=0:⍺-1⋄(⍺+1)∇⍵-{⍵(⌊=∨)+/1,{⊃⌽⍵/⍨2=≢⍵}¨(∪⊢∨⍳)¨∘∊⍣3⊢⍵}⍺}⍵}
{0{⍵=0:⍺-1 }⍵} To find the Nth number, return when we have counted down that many times
{⍵(⌊=∨)+/1,{⊃⌽⍵/⍨2=≢⍵}¨(∪⊢∨⍳)¨∘∊⍣3⊢⍵}⍺ Test if the left arg is a BUI number
(∪⊢∨⍳)¨∘∊⍣3⊢⍵ Flatten and get list of divisors of each input 3 times (the divisors of the divisors of the original input plus another for the primality test)
{⊃⌽⍵/⍨2=≢⍵}¨ For each of them, see if count of divisors is 2 which means its prime, then take the last element as that will be my actual prime number
+/1, Tack on 1 and sum
⍵(⌊=∨) Test if this sum divides the original (a BUI number)
⍵- If all that was true (1), subtract 1 from the count of numbers I'm looking for
(⍺+1)∇ And run again on the next increment of the left arg
Japt, 22 21 17 bytes
I feel like the Nope! Wrong method! But, in my defense, the g function method should lead to a shorter solution, but I can't figure out how it works!i method didn't exist at the time.
1-indexed.
ÈvXâ mk câ x Ä}iU
ÈvXâ mk câ x Ä}iU :Implicit input of integer U
È :Function taking an integer X as argument
v : Test X for divisibility by
Xâ : Divisors of X
m : Map
k : Prime factors
c : Flatten after
â : Deduplicating
x : Reduce by addition
Ä : Add 1
} :End function
iU :Get the Uth integer that returns true
Haskell, 115 bytes
All of the list comprehensions here can probably be golfed down, but I'm not sure how. Golfing suggestions welcome! Try it online!
x!y=rem x y<1
b n=[a|a<-[1..],a!(1+sum[sum[z|z<-[2..m],m!z,and[not$z!x|x<-[2..z-1]]]|m<-[x|x<-[2..a],a!x]])]!!(n-1)
Ungolfing
This answer is actually three functions mashed together.
divisors a = [x | x <- [2..a], rem a x == 0]
sumPrimeDivs m = sum [z | z <- [2..m], rem m z == 0, and [rem z x /= 0 | x <- [2..z-1]]]
biu n = [a | a <- [1..], rem a (1 + sum [sumPrimeDivs m | m <- divisors a]) == 0] !! (n-1)
Pyth, 22 bytes
e.f|qZ1!%Zhssm{Pd*M{yP
This is my first ever Pyth solution, I began learning it thanks to the recommendations of some very kind users in chat :-)... Took me about an hour to solve.
Explanation
e.f|qZ1!%Zhssm{Pd*M{yP - Whole program. Q = input.
.f - First Q integers with truthy results, using a variable Z.
qZ1 - Is Z equal to 1?
| - Logical OR.
{yP - Prime factors, powerset, deduplicate.
*M - Get the product of each. This chunck and ^ are for divisors.
m}Pd - Get the unique prime factors of each.
ss - Flatten and sum.
h - Increment (to handle that 1, bah)
%Z - Modulo the current integer by the sum above.
! - Logical negation. 0 -> True, > 0 -> False.
e - Last element.
Actually, 16 bytes
u⌠;÷♂y♂iΣu@%Y⌡╓N
Explanation:
u⌠;÷♂y♂iΣu@%Y⌡╓N
u⌠;÷♂y♂iΣu@%Y⌡╓ first n+1 numbers x starting with x=0 where
÷ divisors
♂y prime factors of divisors
♂iΣu sum of prime factors of divisors, plus 1
; @% x mod sum
Y is 0
N last number in list
Husk, 13 bytes
!fṠ¦ö→ΣṁoupḊN
Explantaion
Ṡ¦ö→ΣṁoupḊ Predicate: returns 1 if BIU, else 0.
Ḋ List of divisors
ṁ Map and then concatenate
oup unique prime factors
Σ Sum
ö→ Add one
Ṡ¦ Is the argument divisible by this result
f N Filter the natural numbers by that predicate
! Index
Jelly, 16 15 bytes
ÆDÆfQ€SS‘ḍ
1Ç#Ṫ
Woohoo for builtins (but they mysteriously hide from me sometimes so -1 byte thanks to @HyperNeutrino)
How it Works
ÆDÆfQ€SS‘ḍ - define helper function: is input a BIU number?
ÆD - divisors
Æf - list of prime factors
Q€ - now distinct prime factors
SS - sum, then sum again ('' counts as 0)
‘ - add one (to account for '')
ḍ - does this divide the input?
1Ç#Ṫ - main link, input n
# - starting at
1 - 1
- get the first n integers which meet:
Ç - helper link
Ṫ - tail
Mathematica, 85 bytes
If[#<2,1,n=#0[#-1];While[Count[(d=Divisors)@++n,1+Tr@Cases[d/@d@n,_?PrimeQ,2]]<1];n]&