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