Nim, because it's fast and expressive.
janAkali
Cool to see another solution in Nim here =)
(0..<record.len).anyIt(record.dup(delete(it)).validate)
That's smart. I haven't thought of using iterators to loop over indexes (except in a for loop
).
I got stuck on part 2 trying to check everything inside a single loop, which kept getting more ugly.
Yeah I've thought of simple ways to do this and found none. And looking at the input - it's too easy to bruteforce, especially in compiled lang like Nim.
Nim
Got correct answer for part 1 on first try, but website rejected it. Wasted some time debugging and trying different methods. Only to have the same answer accepted minutes later. =(
proc isSafe(report: seq[int]): bool =
let diffs = collect:
for i, n in report.toOpenArray(1, report.high): n - report[i]
(diffs.allIt(it > 0) or diffs.allIt(it < 0)) and diffs.allIt(it.abs in 1..3)
proc solve(input: string): AOCSolution[int, int] =
let lines = input.splitLines()
var reports: seq[seq[int]]
for line in lines:
reports.add line.split(' ').map(parseInt)
for report in reports:
if report.isSafe():
inc result.part1
inc result.part2
else:
for t in 0..report.high:
var mReport = report
mReport.delete t
if mReport.isSafe():
inc result.part2
break
Hey, why isnβt China more green? Iβd think the CCP hates western spyware OSes.
Nim
I've got my first sub-1000 rank today (998 for part 2). Yay!
Simple and straightforward challenge, very fitting for 1st day. Gonna enjoy it while it lasts.
proc solve(input: string): AOCSolution[int, int] =
var l1,l2: seq[int]
for line in input.splitLines():
let pair = line.splitWhitespace()
l1.add parseInt(pair[0])
l2.add parseInt(pair[1])
l1.sort()
l2.sort()
block p1:
for i in 0..l1.high:
result.part1 += abs(l1[i] - l2[i])
block p2:
for n in l1:
result.part2 += n * l2.count(n)
Oh, and GBA rom is included with game files.
I believe for many companies, developers work on giant codebases with many hundred thousands or even millions of lines of code.
With such large codebase you have no control over any system. Because control is split between groups of devs.
If you want to refactor a single subsystem it would take coordination of all groups working on that part and will halt development, probably for months. But first you have to convince all the management people, that refactor is needed, that on itself could take eternity.
So instead you patch it on your end and call it a day.
I believe they both died after the Mountain and the Smaug part, so not really relevant.
dragon attack survivor
That's one way to describe a burglar who came with a group to kill and plunder. And succeeded in both without major troubles.
No one tell them that they can monopolize solar panels.
Meanwhile Nim:
echo "I am still worthy"
let a = r"I hate the ugly '\' at the end of " &
"multiline statements"
for x in 0..9:
if x == 6: echo x
echo x # this is error in Nim, but not in python. Insane!
assert false + 1 # this is an error (python devs in shambles)
assert true - 1 # see above
Thanks for coming to my Ted-talk.
More here: Nim for Python Programmers
Nim
From a first glance it was obviously a regex problem.
I'm using tinyre here instead of stdlib
re
library just because I'm more familiar with it.Codeberg repo