ShareMyScreen/ProjectEuler/0012

From J Wiki
Jump to navigation Jump to search

The count of factors of n can be found using , where p is the prime factors of n and k is the length of p, or in J */ 1 + _ q: n. It is generally common to see some form of brute-force approach with these problems, so my initial idea was to find i where A000217(i) is the answer. I generally reach for the Do-While construct because it is fairly easy to use. u^:v^:_ executes u so long as the boolean condition v returns a 1.

   A000217 =. -: * >:   NB. closed form to find +/ >: i. n
   cond =. 500 > [: */ 1 + _ q: A000217
   >:^:cond^:_ [ 8   NB. the first 7 triangular numbers can't be it so let's start at 8
12375
   A000217 12375x   NB. the answer
76576500