apl APL Hacking: Project Euler (#30) I figure it's about time I posted another Project Euler.Problem #30: ∇Z←PETHIRTY;M [1] ⍝ Find the sum of all the numbers that can be written as [2] ⍝ the sum of fifth powers of their decimal digits. [3] Z←+/1↓((⍳M)=+⌿(((1+⌊10⍟M)⍴10)⊤⍳M)*5)

apl Revisiting Send + More = Money In my last post I attempted to solve the Send + More = Money Cryptarithmetic problem. I didn't quite understand how I could do this quickly using a better algorithm, so I tried to find a simple brute force solution. As it turns out, that solution is actually reasonably fast,

apl Send + More = Money After talking with Prof. Friedman, he gave me an interesting constraint problem. This is a well known example of a problem well suited to constrain based techniques. The goal is to figure out what number to assign to each letter to make the equation "send + more = money" true.

apl APL Hacking: Project Euler (#29) Problem #29:∇Z←PETWENTYNINE;⎕IO ⎕IO←1 ⍝ Compute the cardinality of the set ⍝ {a*b | 2≤a≤100 ^ 2≤b≤100} ⍝ Easy to do by computing the sequence, ⍝ ordering it, and then removing duplicates. Z←⍴(-1⌽1↓(Z≠-1⌽Z),1)/Z←Z[⍋Z←,(1↓⍳100)∘.*(1↓⍳100)] ∇Another easy

apl APL Hacking: Project Euler (#28) Problem #28:Z←PETWENTYEIGHT ⍝ Sum of the diagonals of a 1001 by 1001 spiral Z←+/+1,4/2×⍳500 This one is too easy to talk about. Basically, we can realize the nature of the spiral and the diagonals is easy to think about without generating the spiral.On the

apl APL Hacking; Project Euler (#27) Problem #27:∇Z←PETWENTYSEVEN;A;B;X;P ⍝ Find the product of the coefficients A and B ⍝ that have the longest consecutive n values from 0 ⍝ for the quadratic formula. ⍝ P is the prime table used by CONS∆PRMS. ⍝ Seed it with the primes we use for B since we

apl APL Hacking: Project Euler (#26) Problem #26:∇Z←CYCLE∆LENGTH N;A;I;R ⍝ Find the length of the cycle of 1÷N. Z←0 ⋄ I←0 ⋄ A←N⍴0 ⋄ R←1 LP:I←I+1 ⋄ Z←I-A[R] ⋄ →(0≠A[R])/0 A[R]←I ⋄ R←N|R×10 ⋄ →(0=R)/Z←0 →LP

apl APL Hacking: Project Euler (#25) Problem #25:∇R←PETWENTYFIVE;I;A;X;⎕IO;B;D ⎕IO←1 ⍝ What is the first fibonnacci term to contain 1,000 digits? D←1000000000 ⍝ Use nine-digit numbers. A←B←X←¯112↑1 ⍝ Need 112 9-digit numbers to get 1,000 digits. I←2 LP:A←B ⋄ B←X ⋄ I←

apl APL Hacking: Project Euler (#24) Problem #24:∇R←PETWENTYFOUR;N;A;I ⍝ Compute the 1,000,000th Lexicographic Permutation of ⍝ 0 through 9. N←10 →(N≥3 2 1)/C3,C2,C1 R←1 0⍴0 ⋄ →0 C1:R←1 1⍴⎕IO ⋄ →0 C2:R←2 2⍴⎕IO+0 1 1 0 ⋄ →0 C3:R←

apl APL Hacking: Project Euler (#23) Problem #23:∇R←PETWENTYTHREE;ABDP;N;X ⍝ Find the sum of all the positive integers ⍝ which cannot be written as the sum ⍝ of two abundant numbers. ⊣⎕FX 'R←ABDP N' 'R←N<+/(0=(⍳N-1)|N)/⍳N-1' R←+/(~N∊X∘.+X←(ABDP¨N)/N)/N←⍳28123 ∇Alright, I admit it,

apl APL Hacking: Project Euler (#22) Problem 22:∇R←PETWENTYTWO NAMES;X ⍝ Receiving a 1×N matrix of name vectors, ⍝ sort the names alphabetically, and then compute the ⍝ total of their numeric counts times their sorted ⍝ positions. R←+/(⍳↑⍴X)×+/X×~((⍴X)⍴27)=X←⎕AV[97+⍳26]⍳X[⍋X;]⊣X←⊃NAMES[⎕IO;] ∇This is another one liner.

apl APL Hacking: Project Euler (#21) Problem #21:∇R←PETWENTYONE;X;Y;Z ⍝ Compute the sum of amicable numbers under 10000. R←+/(∨/X^⍉X)/Y⊣X←(~Z)^Y∘.=Y+.×(0=Y∘.|Y)≠Z←Y∘.=Y⊣Y←⍳10000 ∇Ah, back to the nice one liners. I like this one because it made me think a lot about

apl.euler APL Hacking: Project Euler (#20) I was avoiding this one for a while simply because I wanted to have a better carry algorithm in mind. On the other hand, it does not seem to matter if I have a bad carry algorithm, because the program runs fairly quickly regardless. I was aiming for a CARRY

apl APL Hacking: Project Euler (#19) I didn't really have a good idea of how to solve this one until I started playing around with some things on the APL session. Actually, what do you call the APL REPL, anyways?At any rate, it turned out to be a really easy solution once I

apl Histograms in APL/Scheme Eric gave a talk today about the Connection Machines and CM Lisp. One of the examples was of a way to compute the histogram of a set of numbers:(β+ X ⍺1)The basic idea here is that given a Xector X (e.g. -- [5 5 2 5 3

apl APL Hacking: Project Euler (#18) You notice that these are not daily anymore. :)For this one, I took advantage of the ability to rotate vectors to get the job done. I am confused about the use of the bracket indexing though, and I do not quite understand why I needed to use ⊃ and ⊂ as much

apl APL Hacking: Project Euler Daily (#17) This one I did the old fashioned way at first, with a loop and a lot of cases and branching. Either with branch arrows or with Control Structures, it felt wrong. In the end, I realized that I could condense things down a bit if I removed most of the

apl APL Hacking: Project Euler Daily (#16) For this problem, I could have reused my CARRY function from before, but it seemed like it would only make things more difficult. Instead, I realized that there was a really simple carry algorithm that I could use for this problem. I also did not want to use the Java

apl APL Hacking: Project Euler Daily (#15) This was a problem to find all of the forward searching paths in a 20 by 20 grid. This is one that we actually use a lot in our introductory programming courses, but I did not want to do it the way that we do it in those classes, where

apl APL Hacking: Project Euler Daily (#14) This problem was interesting in all different ways. It asks for Collatz Sequence counts. First, I tried to do the naive way, and discovered how that won't work. I then tried to find a more sophisticated algorithm, and realized that I wouldn't find one that suited

apl APL Hacking: Project Euler Daily (#13) So, this is actually my post for Friday, but since I was traveling, I was not able to post anything for that day.This one was pretty fun. The problem is that the input to the incoming function was a series of 100 50-digit numbers. Now, this won't

apl APL Hacking: Project Euler Daily (#12) This was the first problem that I had to deal with that didn't work right or quickly if I used the standard operators the way that I was used to using them. Instead, I had to create some helper functions that made sense. In this case, they were

apl APL Hacking: Project Euler Daily (#11) I really liked doing this one. I had no idea how to approach this idea at first. I couldn't think of any simple approach to it at all. I decided to look at the APLX Scrapbook and see if I could glean any inspiration from there. Lo, and

apl APL Hacking: Project Euler Daily (#10) This was a bit of a fun one, since I had trouble trying to get the result into a 32-bit integer. I had to do a bit of math to get that to work. This one I did a while back, actually, so I am not sure that it contains

apl APL Hacking: Project Euler Daily (#9) Finally, we get an interesting one. In this problem, I struggled with a desire to express the solution simply, and to also make it computable in a reasonable amount of time. To make things worse, the simplest approach also uses the most memory. I had to figure out a way