Skip to content

Instantly share code, notes, and snippets.

@ap29600
Created June 5, 2024 11:39
Show Gist options
  • Save ap29600/635caa045da0e58aab3ba75bca29fe70 to your computer and use it in GitHub Desktop.
Save ap29600/635caa045da0e58aab3ba75bca29fe70 to your computer and use it in GitHub Desktop.
A solution to project euler 61 in BQN
n6
k4
dn
poly ← (0.5×d+1)¨(-0.5×d-1)
limits{abc: (2×a)÷˜-b-√(טb)-4×a×c}¨ poly -10k-10
valuespoly {+´𝕨×(ט𝕩)‿𝕩}¨ {ab:<a+↕b-a}˘limits # the numbers to be tested
perm ← (n-1) ˘˜ (≍↕0){˝(0˘1+𝕩)˘˘=⌜˜𝕨}´-n-1 # distinct cycles of number class
{
x𝕩
w/ 00 ˝1´ mx {(100|𝕨)=𝕩÷100}¨ 1x # adjacency matrices of consecutive number classes
(×≠w)@‿{𝕩# is a cycle possible?
path ← ⟨w
reach ← (w) ˘¨ 1mc˝1˜` m # progressive reachability
reach {path ⊑/𝕨(´path)𝕩}¨ ¯1m # find path backwards
•Show +´ path ¨ x
} @
}¨ <˘permvalues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment