Post History
APL (Dyalog Unicode), 32 bytes (SBCS) {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} Try it online! {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} ⍳⍵ ⍝ Range from 1 to n ...
Answer
#1: Initial revision
# [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 ```