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 Solve Goldbach's Conjecture

APL (Dyalog Unicode), 32 bytes (SBCS) {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} Try it online! {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} ⍳⍵ ⍝ Range from 1 to n ...

posted 3y ago by user‭

Answer
#1: Initial revision by user avatar user‭ · 2021-04-02T20:59:49Z (over 3 years ago)
# [APL (Dyalog Unicode)], 32 bytes (SBCS)

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

    {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵}

[Try it online!][TIO-kn0s9ls0]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-kn0s9ls0]: https://tio.run/##SyzI0U2pTMzJT///P@1R24TqR13NGo@6FmnoP@pdofmod6uttv6hFZo6jzpm6OkAhUBydSDO4elA2RWGj9omP@rdDFRXC9SvYMKVpmAGxEYghqGRAYg0MDAAAA "APL (Dyalog Unicode) – Try It Online"

```
{⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵}
                               ⍳⍵ ⍝ Range from 1 to n
                             1↓   ⍝ Drop the 1st number (make 2 to n)
                    (⊢~∘.×)⍨     ⍝ Filter prime numbers
                           ⍨     ⍝ Use range as both arguments for train
                       ∘.×       ⍝ Outer product - multiply all numbers 
                                 ⍝ in [2..n] by every other number in [2..n],
                                 ⍝ giving all composite numbers up to n
                      ~          ⍝ Remove those composite numbers from
                    ⊢           ⍝ that same range (2 to n)
               ∘.,⍨             ⍝ Cartesian product with itself
              ,                 ⍝ Flatten into vector of prime pairs
  (⊢(/⍨)⍵=+/¨)                 ⍝ Filter the ones that sum to n
           +/¨                  ⍝ Map each pair to its sum
        ⍵=                      ⍝ Check if it equals n
     (/⍨)                       ⍝ Keep elements where the pair equals n in
  ⊢                            ⍝ that same vector of prime pairs
 ⊃                             ⍝ Get the first pair that works

```