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
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Really Cool Numbers

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

posted 3y ago by Marshall Lochbaum‭  ·  edited 3y ago by Marshall Lochbaum‭

Answer
#2: Post edited by user avatar Marshall Lochbaum‭ · 2021-04-21T14:10:15Z (over 3 years ago)
  • # [BQN](https://mlochbaum.github.io/BQN/), 25 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
  • ```
  • ⌊⊸≡(/0=↕⊸|){(+´÷≠)∘𝔽¨«⟜𝔽}
  • ```
  • [Run online!](https://mlochbaum.github.io/BQN/try.html#code=UkMg4oaQIOKMiuKKuOKJoSgvMD3ihpXiirh8KXsoK8K0w7fiiaAp4oiY8J2UvcKowqvin5zwnZS9fQoK4omN4p+cKFJDwqgpIDHigL8z4oC/NeKAvzEw4oC/MTXigL8yMDbigL8yMDc=)
  • This expression has a complicated structure. [This link](https://mlochbaum.github.io/BQN/try.html#code=4oyK4oq44omhKC8wPeKGleKKuHwpeygrwrTDt+KJoCniiJjwnZS9wqjCq+KfnPCdlL19&explain) 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](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after) (`⊸⟜`) and [trains](https://mlochbaum.github.io/BQN/doc/train.html), with one [block modifier](https://mlochbaum.github.io/BQN/doc/block.html#operands). 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](https://mlochbaum.github.io/BQN/doc/shift.html) in the original number on the right side accomplishes this.
  • # [BQN](https://mlochbaum.github.io/BQN/), 25 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
  • ```
  • ⌊⊸≡(/0=↕⊸|){(+´÷≠)∘𝔽¨«⟜𝔽}
  • ```
  • [Run online!](https://mlochbaum.github.io/BQN/try.html#code=UkMg4oaQIOKMiuKKuOKJoSgvMD3ihpXiirh8KXsoK8K0w7fiiaAp4oiY8J2UvcKowqvin5zwnZS9fQoK4omN4p+cKFJDwqgpIDHigL8z4oC/NeKAvzEw4oC/MTXigL8yMDbigL8yMDc=)
  • This expression has a complicated structure. [This link](https://mlochbaum.github.io/BQN/try.html#code=4oyK4oq44omhKC8wPeKGleKKuHwpeygrwrTDt+KJoCniiJjwnZS9wqjCq+KfnPCdlL19&explain) 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](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after) (`⊸⟜`) and [trains](https://mlochbaum.github.io/BQN/doc/train.html), with one [block modifier](https://mlochbaum.github.io/BQN/doc/block.html#operands). 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](https://mlochbaum.github.io/BQN/doc/shift.html) in the original number on the right side accomplishes this.
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-21T14:02:49Z (over 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 25 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>

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

[Run online!](https://mlochbaum.github.io/BQN/try.html#code=UkMg4oaQIOKMiuKKuOKJoSgvMD3ihpXiirh8KXsoK8K0w7fiiaAp4oiY8J2UvcKowqvin5zwnZS9fQoK4omN4p+cKFJDwqgpIDHigL8z4oC/NeKAvzEw4oC/MTXigL8yMDbigL8yMDc=)

This expression has a complicated structure. [This link](https://mlochbaum.github.io/BQN/try.html#code=4oyK4oq44omhKC8wPeKGleKKuHwpeygrwrTDt+KJoCniiJjwnZS9wqjCq+KfnPCdlL19&explain) 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](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after) (`⊸⟜`) and [trains](https://mlochbaum.github.io/BQN/doc/train.html), with one [block modifier](https://mlochbaum.github.io/BQN/doc/block.html#operands). 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](https://mlochbaum.github.io/BQN/doc/shift.html) in the original number on the right side accomplishes this.