janAkali

joined 2 years ago
[–] janAkali@lemmy.one 1 points 2 years ago* (last edited 2 years ago)

It's Nim, but I have no idea why you can't do this in Rust:

var seeds = lines[0].split(": ")[1].splitWhitespace().mapIt(it.parseInt)

Full solution: https://codeberg.org/Archargelod/aoc23-nim/src/branch/master/day_05/solution.nim

[–] janAkali@lemmy.one 39 points 2 years ago* (last edited 2 years ago) (24 children)

I would accept discord/irc over mailing list. But nothing beats a proper forum website.
And no, subreddit is not a proper forum.

[–] janAkali@lemmy.one 10 points 2 years ago

He's a redneck, but in a good way.

[–] janAkali@lemmy.one 22 points 2 years ago (3 children)

In theory this issue can be solved with LD_PRELOAD trick. E.g. redirect all/most/some fopen calls to "$HOME" to some other directory. But before I try to tackle it myself: is there already a similar solution like that?

[–] janAkali@lemmy.one 28 points 2 years ago (3 children)

I thought about this for some time. An anarchy would always collapse into governed state.

First, imagine the perfect scenario where there no authority and world is just a lot of tiny city-sized communities. It would take just a single bad actor to form a state, start invading neighboring communities and growing in power. In response - other communities would be forced to group into increasingly bigger states to have a chance to oppose influence from bigger/richer states.

This thought experiment also works if violent takeover is replaced by economic one. Think of cartels and monopolies.

[–] janAkali@lemmy.one 9 points 2 years ago (1 children)

Reminds me of mongolian tea: VERY strong, 70/30 milk and water, teaspoon of butter and a pinch of salt (enough to taste it and a little more).

I don't drink it often, because it's reallly unhealthy. But it's really good beverage for cold winter nights or after tiring work. It gives you a boost of energy, without the usual sugar fatigue that comes after drinking sweetened coffee/energy drinks.

[–] janAkali@lemmy.one 5 points 2 years ago* (last edited 2 years ago) (1 children)

That ad is targeted to Dragons.

[–] janAkali@lemmy.one 4 points 2 years ago

I guess it's just a real handwriting on a note with everything around inpainted.

[–] janAkali@lemmy.one 0 points 2 years ago* (last edited 2 years ago) (1 children)

Yes the compiler/interpreter can figure it out on the fly, that's what we mean by untyped languages.

Are there untyped languages? You probably meant 'dynamically typed languages'.

But even statically typed languages can figure out most types for you from the context - it's called 'type inference'.

[–] janAkali@lemmy.one 4 points 2 years ago* (last edited 2 years ago) (2 children)

RunnerUp and Another Activity Tracker seem like your best options.

[–] janAkali@lemmy.one 2 points 2 years ago* (last edited 2 years ago)

Nim

My whole solution can be expressed in just two words: Ordered HashTable

Total runtime: 0.068 line-seconds (40 LOC * 1.7 ms)
Puzzle rating: exceptionally confusing description 4/10
Code: cleaned up solution with types
Snippet:

proc getHash(s: string): int =
  for c in s:
    result = ((result + c.ord) * 17) mod 256

proc solve(lines: seq[string]): AOCSolution[int] =
  var boxes: array[256, OrderedTable[string, int]]
  for line in lines:
    block p1:
      result.part1 += line.getHash()

    block p2:
      if line.endsWith('-'):
        var name = line.strip(leading=false, chars={'-'})
        boxes[getHash(name)].del(name)
      else:
        let (name, _, value) = line.partition("=")
        boxes[getHash(name)][name] = value[0].ord - '0'.ord

  for bi, box in boxes:
    if box.len < 1: continue
    for vi, val in enumerate(box.values):
      result.part2 += (bi+1) * (vi+1) * val
view more: ‹ prev next ›