This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| queue = Queue.new | |
| workers = Array.new(N) do | |
| Thread.new do | |
| while record = queue.pop | |
| # insert record | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| records.each do |record| | |
| # insert record | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import strutils, tables, nre, strformat | |
| proc parseRules(rules: seq[string]): Table[string, string] = | |
| for rule in rules: | |
| var parts = rule.split(":") | |
| result[parts[0]] = parts[1].strip | |
| proc buildRegex(idx: string, rules: Table[string, string]): string = | |
| let rule = case idx: | |
| of "8": "(?:42)+" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nre, strutils | |
| proc eval(ex: string): int = | |
| if ex.contains('('): | |
| eval(ex.replace(re"\([^()]+\)", proc (match: string): string = | |
| $eval(match[1 .. ^2]))) | |
| elif ex.contains('+'): | |
| eval(ex.replace(re"(\d+) \+ (\d+)", proc (rm: RegexMatch): string = | |
| $(parseInt(rm.captures[0]) + parseInt(rm.captures[1])))) | |
| elif ex.contains('*'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Second edition of the solution using Table[int, int]. This is possible | |
| # because we only care about a repetition of the last spoken number, I | |
| # misunderstood an example as more generic than what it is, the rules of | |
| # the game are clear about this. | |
| import strutils, sequtils, tables | |
| var input = "8,11,0,19,1,2".split(',').map(parseInt) | |
| var turns: Table[int, int] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import intsets, strutils, strscans, sequtils | |
| type | |
| Opcode = enum | |
| acc = "acc" | |
| jmp = "jmp" | |
| nop = "nop" | |
| Instruction = tuple | |
| opcode: Opcode | |
| arg: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import intsets, strutils, strscans, sequtils | |
| type | |
| Opcode = enum | |
| acc = "acc" | |
| jmp = "jmp" | |
| nop = "nop" | |
| Instruction = tuple | |
| opcode: Opcode | |
| arg: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re, strutils, sequtils, tables, sets | |
| type | |
| ContainedBag = tuple | |
| number: int | |
| color: string | |
| Rule = tuple | |
| color: string | |
| contains: seq[ContainedBag] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import strutils, sequtils, sets | |
| var sum = 0 | |
| for group in readAll(stdin).strip.split("\n\n"): | |
| var answers: seq[HashSet[char]] | |
| for person in group.split("\n"): | |
| answers.add(person.toHashSet()) | |
| sum += answers.foldl(a * b).card | |
| echo sum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ubuntu:latest | |
| # See https://github.com/oracle/truffleruby/blob/master/tool/docker-configs.yaml. | |
| RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | |
| make \ | |
| gcc \ | |
| libssl-dev \ | |
| libz-dev \ | |
| ca-certificates \ | |
| aria2 |