Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users

Dashboard
Notifications
Mark all as read
Challenges

Really Cool Numbers

+3
−0

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.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comments

3 answers

+3
−0

BQN, 25 bytesSBCS

⌊⊸≡(/0=↕⊸|){(+´÷≠)∘𝔽¨«⟜𝔽}

Run online!

This expression has a complicated structure. This link uses BQN's explain feature to show the order in which everything is applied. It's split into two expressions, where the { on the left indicates to apply the modifier on the right.

⌊⊸≡(/0=↕⊸|){(+´÷≠)∘𝔽¨«⟜𝔽}
   (/0=↕⊸|){            }  # Operand 𝔽 to block modifier: proper divisors
       ↕                   #   Range 0,…,n-1
        ⊸|                 #   before modular division
     0=                    #   equals zero
    /                      #   Indices of ones
                       𝔽   # Apply the operand
                     «⟜    # Shift in the number itself
                    ¨      # On each divisor:
                  ∘𝔽       #   Apply the operand again, then
            (+´÷≠)         #     Mean (sum divided by length)
⌊⊸≡                        # Floor matches argument

Much of the structure is composed of Before and After (⊸⟜) and trains, with one block modifier. Note that Modulus (|) has its arguments reversed relative to the modular division operator % in many languages: 3|5 is 2, for example. The function /0=↕⊸| gives proper divisors including 1, but for testing which divisors are cool we want to include the number itself and exclude 1 (we know it's cool). Shifting in the original number on the right side accomplishes this.

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comments

@user But 206 itself isn’t cool, since 106 isn’t divisible by 3 Quintec‭ about 2 months ago

@Quintec Oh, I just realized that the really cool definition includes all divisors, not just the proper divisors. user‭ about 2 months ago

+1
−0

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←∪⊢∨⍳)⍵}

Try it online!

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←∪⊢∨↓∘⍳)⊢

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment

-1 simplifying the inner function. You can also get -2 by converting to a tradfn, since ⍵ is used only once. Razetime‭ about 2 months ago

+1
−0

Husk, 9 bytes

ΛöS=⌊AhḊḊ

Try it online! or Verify all testcases

returns number of divisors + 1 for true and 0 for false.

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comments

First link goes to the APL solution. Marshall Lochbaum‭ about 2 months ago

whoops sorry bout that Razetime‭ about 2 months ago

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!