Post History
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...
Answer
#2: Post edited
- # [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
# [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.