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 Are they abundant, deficient or perfect?

BQN, 21 bytesSBCS (¬·×-+´·/0=↕⊸|)¨⊸⊔1+↕ Run online! Mostly one big train used to find the appropriate group for each number, to be used with Group (⊔). The combining functions in a train norma...

posted 3y ago by Marshall Lochbaum‭

Answer
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-06-16T20:25:49Z (almost 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 21 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>

```
(¬·×-+´·/0=↕⊸|)¨⊸⊔1+↕
```

[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RuKGkCjCrMK3w5ctK8K0wrcvMD3ihpXiirh8KcKo4oq44oqUMSvihpUKCj5GwqggNDnigL8zMuKAvzE24oC/MjnigL8yMw==)

Mostly one big [train](https://mlochbaum.github.io/BQN/doc/train.html) used to find the appropriate group for each number, to be used with [Group](https://mlochbaum.github.io/BQN/doc/group.html) (`⊔`). The combining functions in a train normally have two arguments, but Nothing (`·`) can be used on the left to not pass a left argument. See also [Indices](https://mlochbaum.github.io/BQN/doc/replicate.html#indices) (`/`), and note that Modulus (`|`) is backwards relative to C-like `%`.

```
(¬·×-+´·/0=↕⊸|)¨⊸⊔1+↕
                  1+↕  # One plus range: 1…𝕩
(             )¨       # On each of these (n):
           ↕           #   Range 0…n-1
            ⊸|         #   Remainder dividing into n
         0=            #   Equals zero
       ·/              #   Indices where true: proper divisors
    -+´                #   Sum with initial value -n
  ·×                   #   Sign
 ¬                     #   One minus that
                ⊸⊔     # Use to group 1+↕
```

There might be a better solution based on taking the modulus on all pairs instead of one at a time. `(¬·×-+˝(⊣×≠>|)⌜˜)⊸⊔1+↕` is close at 22 bytes.