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

60%
+1 −0
Challenges Really Cool Numbers

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

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

Answer
#4: Post edited by user avatar user‭ · 2021-04-22T15:55:15Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], 30 bytes
  • <!-- language-all: lang-apl -->
  • {∧/(0=1|+/÷≢)¨1g¨0(g←∪⊢∨↓∘⍳)⍵}
  • [Try it online!][TIO-knrnm1lu]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnm1lu]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OAZPWjjuX6Gga2hjXa@oe3P@pcpHlohWH6oRUGGulA2Ucdqx51LXrUseJR2@RHHTMe9W7WfNS7tfb//zSgKgUjBVMFMwVLBSNTBSMDcy6gmLEBkGUGxBYA "APL (Dyalog Unicode) – 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, also 30 bytes
  • <!-- language-all: lang-apl -->
  • (∧/(0=1|+/÷≢)¨)1g¨0(g←∪⊢∨↓∘⍳)⊢
  • [Try it online!][TIO-knrnofx0]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnofx0]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApMajjuX6Gga2hjXa@oe3P@pcpHlohaZh@qEVBhrpQOlHHasedS161LHiUdvkRx0zHvVu1gTy//9PO7TCUMFIwVTBTMFSwchUwcjAnAsoZmwAZJkBsQUA "APL (Dyalog Unicode) – Try It Online"
  • # [APL (Dyalog Unicode)], <s>30</s> 29 bytes
  • Saved 1 byte thanks to Razetime (could've saved 1 more with a tradfn, but I didn't feel like it)
  • <!-- language-all: lang-apl -->
  • {∧/(0=1|+/÷≢)¨1↓¨g¨(g←∪⊢∨⍳)⍵}
  • [Try it online!][TIO-knt2e200]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knt2e200]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OAZPWjjuX6Gga2hjXa@oe3P@pcpHloheGjtsmHVqQfWqGRDlTxqGPVo65FjzpWPOrdrPmod2vt//9pQDUKRgqmCmYKlgpGpgpGBuZcQDFjAyDLDIgtAA "APL (Dyalog Unicode) – 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
  • <!-- language-all: lang-apl -->
  • (∧/(0=1|+/÷≢)¨)1g¨0(g←∪⊢∨↓∘⍳)⊢
  • [Try it online!][TIO-knrnofx0]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnofx0]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApMajjuX6Gga2hjXa@oe3P@pcpHlohaZh@qEVBhrpQOlHHasedS161LHiUdvkRx0zHvVu1gTy//9PO7TCUMFIwVTBTMFSwchUwcjAnAsoZmwAZJkBsQUA "APL (Dyalog Unicode) – Try It Online"
#3: Post edited by user avatar user‭ · 2021-04-21T16:14:51Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], <s>30</s> 31 bytes
  • <!-- language-all: lang-apl -->
  • {∧/(0=1|+/÷≢)¨1g¨0(g←∪⊢∨↓∘⍳)⍵}
  • [Try it online!][TIO-knrnab25]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnab25]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OAZPWjjuX6Gga2hjXa@oe3P@pcpHlohWH6oRWP2iYaaKQDFTzqWPWoa9GjDqDI5EcdMx71btZ81Lu19v//NKBCBSMFUwUzBUsFI1MFIwNzLqCYsQGQZQbEFgA "APL (Dyalog Unicode) – 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|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2
  • (∪⊢∨1,1↓⍳) ⍝ Find proper divisors
  • ⍝ Make a range [0,n)
  • 1↓ ⍝ Drop the 0
  • ⊢∨ ⍝ GCD(n, x) for all x's in the range,
  • ⍝ leaving us with divisors and a bunch of 1s
  • ⍝ Remove duplicates
  • ⍣2 ⍝ Do this twice to get divisors of divisors
  • ∘↑ ⍝ Turns into a vector first because of boxing
  • (∧/(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?
  • ```
  • # [APL (Dyalog Unicode)], 30 bytes
  • <!-- language-all: lang-apl -->
  • {∧/(0=1|+/÷≢)¨1g¨0(g←∪⊢∨↓∘⍳)⍵}
  • [Try it online!][TIO-knrnm1lu]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnm1lu]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OAZPWjjuX6Gga2hjXa@oe3P@pcpHlohWH6oRUGGulA2Ucdqx51LXrUseJR2@RHHTMe9W7WfNS7tfb//zSgKgUjBVMFMwVLBSNTBSMDcy6gmLEBkGUGxBYA "APL (Dyalog Unicode) – 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, also 30 bytes
  • <!-- language-all: lang-apl -->
  • (∧/(0=1|+/÷≢)¨)1g¨0(g←∪⊢∨↓∘⍳)⊢
  • [Try it online!][TIO-knrnofx0]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnofx0]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApMajjuX6Gga2hjXa@oe3P@pcpHlohaZh@qEVBhrpQOlHHasedS161LHiUdvkRx0zHvVu1gTy//9PO7TCUMFIwVTBTMFSwchUwcjAnAsoZmwAZJkBsQUA "APL (Dyalog Unicode) – Try It Online"
#2: Post edited by user avatar user‭ · 2021-04-21T16:05:05Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], 30 bytes
  • <!-- language-all: lang-apl -->
  • (∧/(0=1|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2
  • [Try it online!][TIO-knrlg77h]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrlg77h]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApMajjuX6Gga2hjXa@oe3P@pcpHlohSZQcNWjrkWPOlYY6hg@apv8qHczUPhRx4xHbRMf9S42@v8/7dAKQwUjBVMFMwVLBSNTBSMDMyA25wKKGxsAWRYA "APL (Dyalog Unicode) – Try It Online"
  • I'm not totally sure about the validity of this answer since the BQN answer has different results, but if it isn't right, I will correct/delete it.
  • Requires zero-indexing.
  • Explanation:
  • ```
  • (∧/(0=1|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2
  • (∪⊢∨1,1↓⍳) ⍝ Find proper divisors
  • ⍳ ⍝ Make a range [0,n)
  • 1↓ ⍝ Drop the 0
  • ⊢∨ ⍝ GCD(n, x) for all x's in the range,
  • ⍝ leaving us with divisors and a bunch of 1s
  • ∪ ⍝ Remove duplicates
  • ⍣2 ⍝ Do this twice to get divisors of divisors
  • ∘↑ ⍝ Turns into a vector first because of boxing
  • (∧/(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?
  • ```
  • # [APL (Dyalog Unicode)], <s>30</s> 31 bytes
  • <!-- language-all: lang-apl -->
  • {∧/(0=1|+/÷≢)¨1g¨↑0(g←∪⊢∨↓∘⍳)⍵}
  • [Try it online!][TIO-knrnab25]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knrnab25]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OAZPWjjuX6Gga2hjXa@oe3P@pcpHlohWH6oRWP2iYaaKQDFTzqWPWoa9GjDqDI5EcdMx71btZ81Lu19v//NKBCBSMFUwUzBUsFI1MFIwNzLqCYsQGQZQbEFgA "APL (Dyalog Unicode) – 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|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2
  • (∪⊢∨1,1↓⍳) ⍝ Find proper divisors
  • ⍳ ⍝ Make a range [0,n)
  • 1↓ ⍝ Drop the 0
  • ⊢∨ ⍝ GCD(n, x) for all x's in the range,
  • ⍝ leaving us with divisors and a bunch of 1s
  • ∪ ⍝ Remove duplicates
  • ⍣2 ⍝ Do this twice to get divisors of divisors
  • ∘↑ ⍝ Turns into a vector first because of boxing
  • (∧/(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?
  • ```
#1: Initial revision by user avatar user‭ · 2021-04-21T15:19:43Z (about 3 years ago)
# [APL (Dyalog Unicode)], 30 bytes

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

    (∧/(0=1|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2

[Try it online!][TIO-knrlg77h]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-knrlg77h]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApMajjuX6Gga2hjXa@oe3P@pcpHlohSZQcNWjrkWPOlYY6hg@apv8qHczUPhRx4xHbRMf9S42@v8/7dAKQwUjBVMFMwVLBSNTBSMDMyA25wKKGxsAWRYA "APL (Dyalog Unicode) – Try It Online"

I'm not totally sure about the validity of this answer since the BQN answer has different results, but if it isn't right, I will correct/delete it.

Requires zero-indexing.

Explanation:
```
(∧/(0=1|+/÷≢)¨)(∪⊢∨1,1↓⍳)¨∘↑⍣2
                (∪⊢∨1,1↓⍳)      ⍝ Find proper divisors
                         ⍳       ⍝ Make a range [0,n)
                       1↓       ⍝ Drop the 0
                   ⊢∨          ⍝ GCD(n, x) for all x's in the range,
                                ⍝ leaving us with divisors and a bunch of 1s
                 ∪              ⍝ Remove duplicates
                             ⍣2 ⍝ Do this twice to get divisors of divisors
                            ∘↑  ⍝ Turns into a vector first because of boxing
(∧/(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?
```