DEV Community

Marco Servetto
Marco Servetto

Posted on


Advent of code Day 20

Finally a day where I can feel satisfied with my code results.
I explain this code in the detail on my youtube channel, (

reuse []

Fs = Load:{reuse[]}

Point = Data.AddList:Data:{ I x, I y
  method Point +(Point that) =
  method Point max(Point that)=(
    (x0,y0) = this
    (x1,y1) = that
  method Point min(Point that) = 

Map = Data:{
  M =,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) = (
  read method Bool val(Point key) =

  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) (
      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) (
      X[i.isInRange(0I to=512I)] // is my binary conversion correct?
    new.outer(if this.outer() that.right() else that.left())
Key = Collection.list(Bool)

  input = Fs.Real.#$of().read(\"input").split(
  imm key = Key()( for i in input().split() \add(i==S"#") )
  var map = Map()
  for line in input().split(, li in Range.unbounded() (
    for c in line.split(), ci in Range.unbounded() (
  for i in Range(2I) ( map:=map.step(key) )  //50I
  tot = 0I.acc()(for (val) in \addIf(val))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.