Monday, October 14, 2013

Problem 52, now in APL

So, APL is an interesting. It is quite an old language, having secured for itself the excellent title of "A Programming Language." It is the language off of which J, which I like so much, is based, so it seemed only proper that I finally getting around to solving a problem in it. I ran into quite a few difficulties related to lack of decent, findable documentation, but once I could actually find out how to do things in APL, it wasn't that bad, and from here forward I would be relatively capable of writing code in APL. For those who don't know, one main cause of APL's lack of popularity is its heavy reliance on non-ASCII characters. Comments start with a ⍝, the and operator is ∧, division is performed with an actual ÷, function definitions begin with a ∇ - all sorts of fun characters that no one really wants to deal with. However, once I set up my keyboard, it wasn't too bad, and it can be kind of fun getting to, for example, actually write ← for assignment. Anyway, here is my code, which has now, yet again, freed up Squirrel for use.
∇Z ← sd x
l← 10 10 10 10 10 10
d← l⊤ x
Z← d[⍋d]
∇

∇Y ← ans x
s← sd x
Y← (s,s,s,s,s) ≡ ((sd 2×x), (sd 3×x), (sd 4×x), (sd 5×x), (sd 6×x))
∇
⍝ Look only up to largest 6-digit candidate
(ans ¨ ⍳166666) ⍳ 1
)OFF

No comments:

Post a Comment