Project Euler (APL)

unimplemented! (keyword){:type "keyword", :affiliated {}, :key "PROPERTY", :value "header-args :session *new*", :position {:start {:line 6, :column 1, :offset 125}, :end {:line 7, :column 1, :offset 164}}}

This is an attempt to learn APL. }:)

Problems

1. Multiples of 3 or 5

βŽ•IO←1
+/⍸∨⌿0=3 5∘.|⍳999
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "233168\n", :position {:start {:line 22, :column 1, :offset 391}, :end {:line 23, :column 2, :offset 401}}}

2. Even Fibonacci

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first terms will be 1, 2, 3, 5, 8, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

{+/⍡[⍸~2|⍡]}({⍡,+/Β―2↑⍡}⍣{4e6<Β―1↑⍡})0 1
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "4613732\n", :position {:start {:line 38, :column 1, :offset 825}, :end {:line 39, :column 2, :offset 836}}}

3. Largest prime factor

The prime factors of 13 915 are 5, 7, 13, and 29.

What is the largest prime factor of 600 851 475 143?

f←{⍺←2β‹„(⍺×⍺)>βŠƒβ΅:βŠƒβ΅β‹„0=⍺|βŠƒβ΅:βΊβˆ‡((βŠƒβ΅)÷⍺),⍺,1↓⍡⋄({2=⍡:3⋄⍡+2}⍺)βˆ‡β΅}
f 600851475143
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "6857\n", :position {:start {:line 55, :column 1, :offset 1119}, :end {:line 56, :column 2, :offset 1127}}}

4. Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 91 Γ— 99.

Find the largest palindrome made from the product of two 3-digit numbers.

First solution

I wrote this before learning I could use Format (⍕) in place of d.

βŽ•IO←0
d←{⍡<10:⍡⋄(βˆ‡βŒŠβ΅Γ·10),(10|⍡)}
p←{{∧/=βŒΏβ†‘β΅ (⌽⍡)}d⍡}
{{⌈/⍡[⍸p¨⍡]}⍡∘.×⍡}100+⍳899
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "906609\n", :position {:start {:line 78, :column 1, :offset 1608}, :end {:line 79, :column 2, :offset 1618}}}

Second solution

βŽ•IO←0
p←{{∧/=βŒΏβ†‘β΅(⌽⍡)}⍕⍡}
{⌈/⍡[⍸p¨⍡]}∘.×⍨100+⍳899 ⍝ 10+⍳89
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "906609\n", :position {:start {:line 90, :column 1, :offset 1745}, :end {:line 91, :column 2, :offset 1755}}}

5. Smallest Multiple

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Using the built-in LCM function

This is a bit too easy. }:P

βŽ•IO←1
∧/⍳20
unimplemented! (fixed-width){:type "fixed-width", :affiliated {:results ""}, :value "232792560\n", :position {:start {:line 111, :column 1, :offset 2139}, :end {:line 112, :column 2, :offset 2152}}}

Handmade LCM

⍝ Modified from function used in the "Largest Prime Factor"
⍝ problem.
f←{⍺←2β‹„(⍺×⍺)>βŠƒβ΅:⍡⋄0=⍺|βŠƒβ΅:βΊβˆ‡((βŠƒβ΅)÷⍺),⍺,1↓⍡⋄({2=⍡:3⋄⍡+2}⍺)βˆ‡β΅}

uhhhh longest mountain pass lol

https://www.codewars.com/kata/660595d3bd866805d00ec4af

References