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

75%
+4 −0
Challenges Are they abundant, deficient or perfect?

APL (Dyalog Unicode), 21 bytes {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳ Try it online! Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the thi...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#2: Post edited by user avatar user‭ · 2021-06-16T15:23:22Z (almost 3 years ago)
  • # [APL (Dyalog Unicode)], 21 bytes
  • <!-- language-all: lang-apl -->
  • {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳
  • [Try it online!][TIO-kpzmat5b]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-kpzmat5b]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Tqw9Mf9W7V1dZ/1LEKyHjUseLQesNHbZMf9W4GcmsPrXjUMQPE7lr0qGcHkAHUpWBkDAA "APL (Dyalog Unicode) – Try It Online"
  • Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the third is abundant numbers. Explanation coming soon.
  • # [APL (Dyalog Unicode)], 21 bytes
  • <!-- language-all: lang-apl -->
  • {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳
  • [Try it online!][TIO-kpzmat5b]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-kpzmat5b]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Tqw9Mf9W7V1dZ/1LEKyHjUseLQesNHbZMf9W4GcmsPrXjUMQPE7lr0qGcHkAHUpWBkDAA "APL (Dyalog Unicode) – Try It Online"
  • Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the third is abundant numbers.
  • ```
  • {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳
  • ⍳ ⍝ Make a range [1, input]
  • ¨ ⍝ For every ⍵ in that range
  • ⍳⍵ ⍝ Make a range [1, ⍵]
  • ¯1↓ ⍝ Drop the last number (⍵)
  • ⍵∨ ⍝ GCD all numbers in that range with ⍵
  • ∪ ⍝ The previous step gave proper divisors, this removes duplicates
  • +/ ⍝ Sum proper divisors
  • ⍵- ⍝ Subtract from ⍵
  • × ⍝ Get the sign
  • ⍳ ⍝ Make another range [1, input]
  • ⌸ ⍝ Group by the signs of the differences we got earlier
  • ```
#1: Initial revision by user avatar user‭ · 2021-06-16T15:18:41Z (almost 3 years ago)
# [APL (Dyalog Unicode)], 21 bytes

<!-- language-all: lang-apl -->

    {×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳

[Try it online!][TIO-kpzmat5b]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-kpzmat5b]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Tqw9Mf9W7V1dZ/1LEKyHjUseLQesNHbZMf9W4GcmsPrXjUMQPE7lr0qGcHkAHUpWBkDAA "APL (Dyalog Unicode) – Try It Online"

Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the third is abundant numbers. Explanation coming soon.