DEV Community

Discussion on: Daily Challenge #277 - Over the Road

Collapse
 
bubbler4 profile image
Bubbler • Edited

APL (using Dyalog APL):

   ⍝ left(⍺):address, right(⍵):n
   OverTheRoad ← {⍺-⍨1+2×⍵}
   1 OverTheRoad 3
6
   3 OverTheRoad 3
4
   3 OverTheRoad 5
8
   7 OverTheRoad 11
16

   ⍝ Short, "tacit" form
   OverTheRoad ← -⍨+1+⊢
   ⍝ Arithmetic automatically maps over multiple numbers!
   1 3 3 7 OverTheRoad 3 3 5 11
6 4 8 16

(Use the bookmarklet on this post to see the code with APL font and syntax highlighting.)

Explanation: The sum of two houses facing each other is always the same for given n, which is 2n+1. So the opposite house number becomes 2n+1-address.