Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,44 @@
!YS-v0
defn main(input):
say: read-string(input)
.map(best-shuffle):vec
defn best-shuffle(s):
ref =: s:group-indices:cycles
prm =: concat.apply(map(partial(rotate 1) ref))
ref =: concat(ref*)
map(vector ref prm):
.sort-by(first _)
.map(second)
.map(partial(get s))
.str(*)
.call(\([s _ s.score(_)]) _)
defn score(before after):
map(== before after)
.filter(true?).#
defn group-indices(s):
map-indexed(vector s)
.merge-vecs({}):vals
.sort-by(count _):reverse
defn cycles(coll):
n =: coll.0.#
cycle =: range(n):cycle
coll =: concat(coll*)
map(vector coll cycle):
.merge-vecs([])
defn rotate(n coll):
c =: coll.#
n =: (c + n) % c
concat coll.drop(n): coll.take(n)
defn merge-vecs(vecs init):
reduce _ init vecs:
fn(counts [index x]):
assoc counts x:
counts.$x.or([]).conj(index)