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
| use rdkafka::admin::{AdminClient, AdminOptions, AlterConfig, ResourceSpecifier}; | |
| use rdkafka::client::DefaultClientContext; | |
| use rdkafka::ClientConfig; | |
| use tokio; | |
| #[tokio::main] | |
| async fn main() { | |
| let topic = ResourceSpecifier::Topic("accounts_log_changes"); | |
| // kafka-configs.sh --zookeeper zookeeper:2181 --entity-type topics --entity-name accounts_log_changes --describe | |
| // let config = [AlterConfig::new(topic).set("message.timestamp.type", "CreateTime")]; |
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
| defmodule Day23 do | |
| def p2 do | |
| i = "389547612" | |
| cups = String.split(i, "", trim: true) |> Enum.map(&String.to_integer/1) | |
| start = hd(cups) | |
| max = 1_000_000 | |
| steps = 10_000_000 | |
| mem = :atomics.new(max, []) | |
| Enum.each(Enum.zip(cups, tl(cups) ++ [10]), fn {i, next} -> :atomics.put(mem, i, next) end) | |
| Enum.each(10..max, &:atomics.put(mem, &1, &1 + 1)) |
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
| defmodule Day15Part2 do | |
| def go do | |
| 261_214 = solve([1, 2, 3]) | |
| end | |
| defp solve(already_spoken) do | |
| start = Enum.count(already_spoken) + 1 | |
| stop = 30_000_000 | |
| spoken = :atomics.new(stop, []) |
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
| defmodule Day15Part2 do | |
| def go do | |
| 261_214 = solve([1, 2, 3]) |> elem(0) | |
| end | |
| defp solve(already_spoken) do | |
| start = Enum.count(already_spoken) + 1 | |
| stop = 30_000_000 | |
| # Assumes last spoken was spoken for the first time. |
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
| defmodule Day10P2 do | |
| def run do | |
| data = "data/10" |> File.read!() |> String.split() |> Enum.map(&String.to_integer/1) | |
| [0 | data] | |
| |> Enum.sort(:desc) | |
| |> Enum.reduce([{hd(data) + 3, 1}], &[{&1, sum3(&1, &2)} | &2]) | |
| |> hd() | |
| |> elem(1) | |
| 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
| defmodule Day16 do | |
| def part2(data) do | |
| signal = parse(data) | |
| signal | |
| |> Enum.reverse() | |
| |> Stream.cycle() | |
| |> Stream.take(length(signal) * 10000 - offset(data)) | |
| |> Stream.iterate(fn signal -> Stream.scan(signal, &rem(&1 + &2, 10)) end) | |
| |> Enum.at(100) |
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
| defmodule Day08 do | |
| @x 25 | |
| @y 6 | |
| def part1 do | |
| read_layers() | |
| |> Enum.min_by(fn layer -> length(Enum.filter(layer, &(&1 == ?0))) end) | |
| |> Enum.group_by(& &1) | |
| |> Map.take([?1, ?2]) | |
| |> Map.values() |
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
| defmodule Day06 do | |
| def part01 do | |
| sum_tree(data()) | |
| end | |
| def part02 do | |
| distance(data(), "YOU", "SAN") | |
| end | |
| defp data do |