코드 20일째 도착
나는 유튜브 채널에서 이 코드를 상세하게 설명했다. ()
reuse [L42.is/AdamsTowel]
Fs = Load:{reuse[L42.is/FileSystem]}
Point = Data.AddList:Data:{ I x, I y
method Point +(Point that) =
\(x=this.x()+that.x(),y=this.y()+that.y())
method Point max(Point that)=(
(x0,y0) = this
(x1,y1) = that
Point(x=x0.max(x1),y=y0.max(y1))
)
method Point min(Point that) =
this.with(x=\x.min(that.x()))<:This.with(y=\y.min(that.y()))
}
Map = Data:{
M = Collection.map(key=Point,val=Bool)
mut M map=\()
var Bool outer=Bool.false()
var Point topLeft = Point(x=0I,y=0I)
var Point bottomRight = Point(x=0I,y=0I)
mut method Void put(Point key, Bool val) = (
\#map.put(key=key,val=val)
\topLeft(\topLeft.min(key))
\bottomRight(\bottomRight.max(key))
)
read method Bool val(Point key) =
\map.val(key=key).val(orElse=this.outer())
read method I nearBin(Point that) = 0I.acc()((
var n = 512I
for xi in Range(I"-1" to=2I), for yi in Range(I"-1" to=2I) (
n/=2I
if this.val(key=Point(x=xi,y=yi)+that) \add(n)
)
))
read method mut This step(Key that) = (
mut This new = This()
(x0,y0) = \topLeft
(x1,y1) = \bottomRight
for x in Range(x0-1I to=x1+2I), for y in Range(y0-1I to=y1+2I) (
key=Point(x=x,y=y)
i=\nearBin(key)
X[i.isInRange(0I to=512I)] // is my binary conversion correct?
new.put(key=key,val=that.val(i))
)
new.outer(if this.outer() that.right() else that.left())
new
)
}
Key = Collection.list(Bool)
Main=(
input = Fs.Real.#$of().read(\"input").split(S.nl()++S.nl())
imm key = Key()( for i in input().split() \add(i==S"#") )
X[key.size()==512I]
var map = Map()
for line in input().split(S.nl()), li in Range.unbounded() (
for c in line.split(), ci in Range.unbounded() (
map.put(key=\(x=li,y=ci),val=c==S"#")
)
)
for i in Range(2I) ( map:=map.step(key) ) //50I
tot = 0I.acc()(for (val) in map.map() \addIf(val))
Debug(tot)
)
Reference
이 문제에 관하여(코드 20일째 도착), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/marcoservetto/advent-of-code-day-20-1n10텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)