Comments on Really Cool Numbers
Parent
Really Cool Numbers
Define a cool number as a number whose proper divisors (all except for the number itself) have an integral mean. Define a really cool number as a number whose divisors (including itself) are all cool. (We explicitly define 1 to be both cool and really cool.) Given a positive integer, determine whether or not it is really cool.
Examples
Prime numbers are both cool and really cool, since 1 is defined as cool. 15 is really cool, because $\frac{1+3+5}{3} = 3$ and primes/1 are cool. 30 is cool, since $\frac{1+2+3+5+6+10+15}{7} = 6$, but not really cool, since 10 is not cool.
Here is a short list of really cool numbers for testing: $2, 5, 6, 9, 25, 207$
This is code-golf, so shortest code wins.
BQN, 25 bytesSBCS ``` ⌊⊸≡( …
3y ago
[Husk], 9 bytes ΛöS=⌊Ah …
3y ago
[APL (Dyalog Unicode)], 30 29 …
3y ago
Post
APL (Dyalog Unicode), 30 29 bytes
Saved 1 byte thanks to Razetime (could've saved 1 more with a tradfn, but I didn't feel like it)
{∧/(0=1|+/÷≢)¨1↓¨g¨(g←∪⊢∨⍳)⍵}
This answer was incorrect before because it only checked if the number's proper divisors were cool, but it should work now.
Requires zero-indexing.
Explanation (to be updated):
{∧/(0=1|+/÷≢)¨1g¨0(g←∪⊢∨↓∘⍳)⍵}
(g←∪⊢∨↓∘⍳) ⍝ Define g to find divisors
⍳ ⍝ Make a range [0,n)
↓∘ ⍝ Drop the amount given on the left
⍝ Dropping 1 results in proper divisors,
⍝ dropping 0 results in all divisors
⊢∨ ⍝ GCD(n, x) for all x's in the range,
⍝ leaving us with divisors and a bunch of 1s
∪ ⍝ Remove duplicates
0 ⍵ ⍝ Apply this to ⍵ to get all divisors
¨ ⍝ For each of these divisors
1g ⍝ Find the proper divisors
(∧/(0=1|+/÷≢)¨) ⍝ Check if divisors of divisors meet criteria
¨ ⍝ For every divisor's list of divisors
+/÷≢ ⍝ Calculate mean:
+/ ⍝ Sum
÷ ⍝ Divided by
≢ ⍝ Count
1| ⍝ Mod 1
0= ⍝ Is that 0? (0<x<1 if not integral)
∧/ ⍝ Is this true for all lists of divisors?
With trains, 30 bytes
(∧/(0=1|+/÷≢)¨)1g¨0(g←∪⊢∨↓∘⍳)⊢
0 comment threads