@Jummit@lemmy.one
@Jummit@lemmy.one avatar

Jummit

@Jummit@lemmy.one

Software developer and artist.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

Jummit, (edited )
@Jummit@lemmy.one avatar

This isn’t Lua code, Lua requires commas as separators for table items.

EDIT: Retracted, it seems like Lua allows this madness

Jummit,
@Jummit@lemmy.one avatar

Wow. Seems like I will never stop learning new things about Lua.

Jummit,
@Jummit@lemmy.one avatar

I hope it’s going to be used instead of machine learning. Seems much more correct, secure and efficient to me.

Jummit,
@Jummit@lemmy.one avatar

Nice and easy.

::: spoiler Lua


<span style="font-style:italic;color:#969896;">-- SPDX-FileCopyrightText: 2023 Jummit
</span><span style="font-style:italic;color:#969896;">--
</span><span style="font-style:italic;color:#969896;">-- SPDX-License-Identifier: GPL-3.0-or-later
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">local function </span><span style="font-weight:bold;color:#795da3;">nums</span><span style="color:#323232;">(str)
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> res </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> {}
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> num </span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;"> str:gmatch(</span><span style="color:#183691;">"%d+"</span><span style="color:#323232;">) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">		res[num] </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">true
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">return</span><span style="color:#323232;"> res
</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> cards </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> {}
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> points </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> line </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">io.open</span><span style="color:#323232;">(</span><span style="color:#183691;">"4.input"</span><span style="color:#323232;">):lines() </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> winning, have </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> line:match(</span><span style="color:#183691;">"Card%s*%d+: (.*) | (.*)"</span><span style="color:#323232;">)
</span><span style="color:#323232;">	winning </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> nums(winning)
</span><span style="color:#323232;">	have </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> nums(have)
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> first </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">true
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> score </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> matching </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> num </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">pairs</span><span style="color:#323232;">(have) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">		</span><span style="font-weight:bold;color:#a71d5d;">if</span><span style="color:#323232;"> winning[num] </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">			matching </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> matching </span><span style="font-weight:bold;color:#a71d5d;">+ </span><span style="color:#0086b3;">1
</span><span style="color:#323232;">			</span><span style="font-weight:bold;color:#a71d5d;">if</span><span style="color:#323232;"> first </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">				first </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">false
</span><span style="color:#323232;">				score </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> score </span><span style="font-weight:bold;color:#a71d5d;">+ </span><span style="color:#0086b3;">1
</span><span style="color:#323232;">			</span><span style="font-weight:bold;color:#a71d5d;">else
</span><span style="color:#323232;">				score </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> score </span><span style="font-weight:bold;color:#a71d5d;">* </span><span style="color:#0086b3;">2
</span><span style="color:#323232;">			</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">		</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">	points </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> points </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> score
</span><span style="color:#323232;">	</span><span style="color:#62a35c;">table.insert</span><span style="color:#323232;">(cards, {have</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">have, wins</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;">matching, count</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#0086b3;">1</span><span style="color:#323232;">})
</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#62a35c;">print</span><span style="color:#323232;">(points)
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> cardSum </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> i, card </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">ipairs</span><span style="color:#323232;">(cards) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">	cardSum </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cardSum </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> card.count
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> n </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> i </span><span style="font-weight:bold;color:#a71d5d;">+ </span><span style="color:#0086b3;">1</span><span style="color:#323232;">, i </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> card.wins </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">		cards[n].count </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> cards[n].count </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> card.count
</span><span style="color:#323232;">	</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#62a35c;">print</span><span style="color:#323232;">(cardSum)
</span>
Jummit,
@Jummit@lemmy.one avatar

Input parsing AGAIN?

Lualua – SPDX-FileCopyrightText: 2023 Jummit – – SPDX-License-Identifier: GPL-3.0-or-later local lines = {} for line in io.open(“3.input”):lines() do table.insert(lines, “.”…line…“.”) end local width = #lines[1] local height = #lines local function at(x, y, w) if y &lt; 1 or y > height then return nil end return lines[y]:sub(x, x + w - 1) end local sum = 0 local gears = {} for y, line in ipairs(lines) do local start = 1 local outLine = line while true do local newStart, numEnd = line:find(“%d+”, start) if not newStart then break end local symbol = false local num = tonumber(line:sub(newStart, numEnd)) for y = y - 1, y + 1 do local surrounding = at(newStart - 1, y, numEnd - newStart + 3) if surrounding then if surrounding and surrounding:match(“[^.%d]”) then symbol = true end for i = 1, #surrounding do local gear = surrounding:sub(i, i) == “*” if gear then if not gears[y] then gears[y] = {} end local x = i + newStart - 2 if not gears[y][x] then gears[y][i + newStart - 2] = {} end table.insert(gears[y][x], num) end end end end if symbol then sum = sum + num end start = numEnd + 1 end end print(sum) local ratio = 0 for _, line in pairs(gears) do for _, gears in pairs(line) do if #gears == 2 then ratio = ratio + gears[1] * gears[2] end end end print(ratio)

Hare (Part one only)hare // SPDX-FileCopyrightText: 2023 Jummit // // SPDX-License-Identifier: GPL-3.0-or-later use strings; use regex; use fmt; use os; use bufio; use io; use strconv; use types; fn star_in(lines: []str, x: uint, y: uint, w: uint) bool = { let start = y; if (start > 0) start -= 1; let end = y + 1; if (end >= len(lines)) end -= 1; const re = regex::compile([^.0-9])!; for (let h = start; h &lt;= end; h += 1) { fmt::println(strings::sub(lines[h], x, x + w))!; if (regex::test(&amp;re, strings::sub(lines[h], x, x + w))) { fmt::println(“”)!; return true; }; }; fmt::println(“”)!; return false; }; export fn main() void = { const file = os::open(“3.input”)!; defer io::close(file)!; const buf = bufio::newscanner(file, types::SIZE_MAX); let lines: []str = []; defer strings::freeall(lines); for (true) { match (bufio::scan_line(&amp;buf)!) { case io::EOF => break; case let line: const str => append(lines, strings::dup(line)); }; }; const height = len(lines); const width = len(lines[0]); let sum: uint = 0; let gears: [](uint, uint) = []; const num_re = regex::compile([0-9]+)!; for (let y = 0u; y &lt; len(lines); y += 1) { let nums = regex::findall(&amp;num_re, lines[y]); defer regex::result_freeall(nums); for (let i = 0z; i &lt; len(nums); i += 1) { for (let j = 0z; j &lt; len(nums[i]); j += 1) { const find = nums[i][j]; const num = strconv::stou(find.content)!; let start = find.start: uint; let w = len(find.content): uint + 2; if (start > 0) { start -= 1; } else { w -= 1; }; if (star_in(lines, start, y, w)) { sum += num; }; }; }; }; fmt::printfln(“{}”, sum)!; };

Jummit,
@Jummit@lemmy.one avatar

Mostly an input parsing problem this time, but it was fun to use Hares tokenizer functions:

:::spoiler lua


<span style="font-style:italic;color:#969896;">-- SPDX-FileCopyrightText: 2023 Jummit
</span><span style="font-style:italic;color:#969896;">--
</span><span style="font-style:italic;color:#969896;">-- SPDX-License-Identifier: GPL-3.0-or-later
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> colors </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> {</span><span style="color:#183691;">"blue"</span><span style="color:#323232;">, </span><span style="color:#183691;">"red"</span><span style="color:#323232;">, </span><span style="color:#183691;">"green"</span><span style="color:#323232;">}
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> available </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> {red </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">12</span><span style="color:#323232;">, blue </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">14</span><span style="color:#323232;">, green </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">13</span><span style="color:#323232;">}
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> possible </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> id </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> min </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> game </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">io.open</span><span style="color:#323232;">(</span><span style="color:#183691;">"2.input"</span><span style="color:#323232;">):lines() </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">  id </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> id </span><span style="font-weight:bold;color:#a71d5d;">+ </span><span style="color:#0086b3;">1
</span><span style="color:#323232;">  game </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> game:gsub(</span><span style="color:#183691;">"Game %d+: "</span><span style="color:#323232;">, </span><span style="color:#183691;">""</span><span style="color:#323232;">)</span><span style="font-weight:bold;color:#a71d5d;">..</span><span style="color:#183691;">"; "
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> max </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> {red </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, blue </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, green </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">0</span><span style="color:#323232;">}
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> show </span><span style="font-weight:bold;color:#a71d5d;">in</span><span style="color:#323232;"> game:gmatch(</span><span style="color:#183691;">".-; "</span><span style="color:#323232;">) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> _, color </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">ipairs</span><span style="color:#323232;">(colors) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> num </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#62a35c;">tonumber</span><span style="color:#323232;">(show:match(</span><span style="color:#183691;">"(%d+) "</span><span style="font-weight:bold;color:#a71d5d;">..</span><span style="color:#323232;">color))
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#a71d5d;">if</span><span style="color:#323232;"> num </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">        max[color] </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#62a35c;">math.max</span><span style="color:#323232;">(max[color], num)
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">  min </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> min </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> max.red </span><span style="font-weight:bold;color:#a71d5d;">*</span><span style="color:#323232;"> max.blue </span><span style="font-weight:bold;color:#a71d5d;">*</span><span style="color:#323232;"> max.green
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">local</span><span style="color:#323232;"> thisPossible </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">true
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> _, color </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#62a35c;">ipairs</span><span style="color:#323232;">(colors) </span><span style="font-weight:bold;color:#a71d5d;">do
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">if</span><span style="color:#323232;"> max[color] </span><span style="font-weight:bold;color:#a71d5d;">></span><span style="color:#323232;"> available[color] </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">      thisPossible </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">false
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#a71d5d;">break
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if</span><span style="color:#323232;"> thisPossible </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">    possible </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> possible </span><span style="font-weight:bold;color:#a71d5d;">+</span><span style="color:#323232;"> id
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="font-weight:bold;color:#a71d5d;">end
</span><span style="color:#323232;">
</span><span style="color:#62a35c;">print</span><span style="color:#323232;">(possible)
</span><span style="color:#62a35c;">print</span><span style="color:#323232;">(min)
</span>

:::

:::spoiler hare


<span style="color:#323232;">// SPDX-FileCopyrightText: 2023 Jummit
</span><span style="color:#323232;">//
</span><span style="color:#323232;">// SPDX-License-Identifier: GPL-3.0-or-later
</span><span style="color:#323232;">
</span><span style="color:#323232;">use strconv;
</span><span style="color:#323232;">use types;
</span><span style="color:#323232;">use strings;
</span><span style="color:#323232;">use io;
</span><span style="color:#323232;">use bufio;
</span><span style="color:#323232;">use os;
</span><span style="color:#323232;">use fmt;
</span><span style="color:#323232;">
</span><span style="color:#323232;">const available: []uint = [12, 13, 14];
</span><span style="color:#323232;">
</span><span style="color:#323232;">fn color_id(color: str) const uint = {
</span><span style="color:#323232;">	switch (color) {
</span><span style="color:#323232;">	case "red" => return 0;
</span><span style="color:#323232;">	case "green" => return 1;
</span><span style="color:#323232;">	case "blue" => return 2;
</span><span style="color:#323232;">	case => abort();
</span><span style="color:#323232;">	};
</span><span style="color:#323232;">};
</span><span style="color:#323232;">
</span><span style="color:#323232;">export fn main() void = {
</span><span style="color:#323232;">	const file = os::open("2.input")!;
</span><span style="color:#323232;">	defer io::close(file)!;
</span><span style="color:#323232;">	const scan = bufio::newscanner(file, types::SIZE_MAX);
</span><span style="color:#323232;">	let possible: uint = 0;
</span><span style="color:#323232;">	let min: uint = 0;
</span><span style="color:#323232;">
</span><span style="color:#323232;">	for (let id = 1u; true; id += 1) {
</span><span style="color:#323232;">		const line = match(bufio::scan_line(&amp;scan)!) {
</span><span style="color:#323232;">		case io::EOF =>
</span><span style="color:#323232;">			break;
</span><span style="color:#323232;">		case let line: const str =>
</span><span style="color:#323232;">			yield strings::sub(
</span><span style="color:#323232;">					line,
</span><span style="color:#323232;">					strings::index(line, ": ") as size + 2,
</span><span style="color:#323232;">					strings::end);
</span><span style="color:#323232;">		};
</span><span style="color:#323232;">		let max: []uint = [0, 0, 0];
</span><span style="color:#323232;">		let tok = strings::rtokenize(line, "; ");
</span><span style="color:#323232;">		for (true) {
</span><span style="color:#323232;">			const show = match(strings::next_token(&amp;tok)) {
</span><span style="color:#323232;">			case void =>
</span><span style="color:#323232;">				break;
</span><span style="color:#323232;">			case let show: str =>
</span><span style="color:#323232;">				yield show;
</span><span style="color:#323232;">			};
</span><span style="color:#323232;">			const pairs = strings::tokenize(show, ", ");
</span><span style="color:#323232;">			for (true) {
</span><span style="color:#323232;">				const pair: (str, str) = match(strings::next_token(&amp;pairs)) {
</span><span style="color:#323232;">				case void =>
</span><span style="color:#323232;">					break;
</span><span style="color:#323232;">				case let pair: str =>
</span><span style="color:#323232;">					let tok = strings::tokenize(pair, " ");
</span><span style="color:#323232;">					yield (
</span><span style="color:#323232;">						strings::next_token(&amp;tok) as str,
</span><span style="color:#323232;">						strings::next_token(&amp;tok) as str
</span><span style="color:#323232;">					);
</span><span style="color:#323232;">				};
</span><span style="color:#323232;">				let color = color_id(pair.1);
</span><span style="color:#323232;">				let amount = strconv::stou(pair.0)!;
</span><span style="color:#323232;">				if (amount > max[color]) max[color] = amount;
</span><span style="color:#323232;">			};
</span><span style="color:#323232;">		};
</span><span style="color:#323232;">		if (max[0] &lt;= available[0] &amp;&amp; max[1] &lt;= available[1] &amp;&amp; max[2] &lt;= available[2]) {
</span><span style="color:#323232;">			fmt::printfln("{}", id)!;
</span><span style="color:#323232;">			possible += id;
</span><span style="color:#323232;">		};
</span><span style="color:#323232;">		min += max[0] * max[1] * max[2];
</span><span style="color:#323232;">	};
</span><span style="color:#323232;">	
</span><span style="color:#323232;">	fmt::printfln("{}", possible)!;
</span><span style="color:#323232;">	fmt::printfln("{}", min)!;
</span><span style="color:#323232;">};
</span>

:::

Jummit,
@Jummit@lemmy.one avatar

Trickier than expected! I ran into an issue with Lua patterns, so I had to revert to a more verbose solution, which I then used in Hare as well.

Lua:

lualua – SPDX-FileCopyrightText: 2023 Jummit – – SPDX-License-Identifier: GPL-3.0-or-later local sum = 0 for line in io.open(“1.input”):lines() do local a, b = line:match(“^.-(%d).*(%d).-$”) if not a then a = line:match(“%d+”) b = a end if a and b then sum = sum + tonumber(a…b) end end print(sum) local names = { [“one”] = 1, [“two”] = 2, [“three”] = 3, [“four”] = 4, [“five”] = 5, [“six”] = 6, [“seven”] = 7, [“eight”] = 8, [“nine”] = 9, [“1”] = 1, [“2”] = 2, [“3”] = 3, [“4”] = 4, [“5”] = 5, [“6”] = 6, [“7”] = 7, [“8”] = 8, [“9”] = 9, } sum = 0 for line in io.open(“1.input”):lines() do local firstPos = math.huge local first for name, num in pairs(names) do local left = line:find(name) if left and left &lt; firstPos then firstPos = left first = num end end local last for i = #line, 1, -1 do for name, num in pairs(names) do local right = line:find(name, i) if right then last = num goto found end end end ::found:: sum = sum + tonumber(first * 10 + last) end print(sum)

Hare:

harehare // SPDX-FileCopyrightText: 2023 Jummit // // SPDX-License-Identifier: GPL-3.0-or-later use fmt; use types; use bufio; use strings; use io; use os; const numbers: [](str, int) = [ (“one”, 1), (“two”, 2), (“three”, 3), (“four”, 4), (“five”, 5), (“six”, 6), (“seven”, 7), (“eight”, 8), (“nine”, 9), (“1”, 1), (“2”, 2), (“3”, 3), (“4”, 4), (“5”, 5), (“6”, 6), (“7”, 7), (“8”, 8), (“9”, 9), ]; fn solve(start: size) void = { const file = os::open(“1.input”)!; defer io::close(file)!; const scan = bufio::newscanner(file, types::SIZE_MAX); let sum = 0; for (let i = 1u; true; i += 1) { const line = match (bufio::scan_line(&amp;scan)!) { case io::EOF => break; case let line: const str => yield line; }; let first: (void | int) = void; let last: (void | int) = void; for (let i = 0z; i &lt; len(line); i += 1) :found { for (let num = start; num &lt; len(numbers); num += 1) { const start = strings::sub(line, i, strings::end); if (first is void &amp;&amp; strings::hasprefix(start, numbers[num].0)) { first = numbers[num].1; }; const end = strings::sub(line, len(line) - 1 - i, strings::end); if (last is void &amp;&amp; strings::hasprefix(end, numbers[num].0)) { last = numbers[num].1; }; if (first is int &amp;&amp; last is int) { break :found; }; }; }; sum += first as int * 10 + last as int; }; fmt::printfln(“{}”, sum)!; }; export fn main() void = { solve(9); solve(0); };

Nach emotionaler Debatte: Grüne stützen verschärfte Asylpolitik (www.tagesschau.de) German

Vor allem junge Delegierte üben in der Debatte scharfe Kritik an der Asylpolitik der Ampelregierung. “Es ist unehrlich über Begrenzung zu reden, während die Welt in Flammen steht”, sagt Vasili Franco, Delegierter aus Berlin. “Liebe Freundinnen und Freunde, ich bitte Euch. Lasst uns nicht schon auf diesem Parteitag einen...

Jummit,
@Jummit@lemmy.one avatar

Ich weiß, das kommt hier nicht gut an, aber meiner Meinung nach hat sich schon länger erwiesen dass Wählen allein keine ausreichende Lösung für Probleme die mit Menschenrechten, Umwelt oder Lebensqualität zu tun haben ist. (Ich meine nicht Demokratie oder Wahlen generell, sondern unsere Bundestagswahl). Wir sind zwar besser dran als viele andere, aber ich denke Emma Goldman hatte mehr Recht als man zugeben möchte: “If voting changed anything, they’d make it illegal”

Opinion | Relax, Electric Vehicles Really Are the Best Choice for the Climate (www.nytimes.com)

We got the first to replace our 10-year-old, gas-powered Subaru, and after only two years of driving, the E.V. has created fewer emissions over its lifetime than if we had kept the old car. It will take our second E.V. only four years to create fewer emissions over its lifetime than the 2005 hybrid Prius it replaced. That’s...

Jummit,
@Jummit@lemmy.one avatar

and fuck people selling technology as a solution instead of system change.

Jummit,
@Jummit@lemmy.one avatar

It’s also called depression. (I think, don’t quote me on that.)

Greenhouse gas emissions in the Netherlands in 2021 were 25% lower than in 1990 (www.rivm.nl)

In 2021, total GHG emissions (including indirect CO2 emissions and including emissions from Land use, land use change and forestry (LULUCF)) in the Netherlands amounted to 172 Tg CO2 eq. This is approximately 24.9 percent below the emissions in the base year 1990 (228.9 Tg CO2 eq.).

Jummit,
@Jummit@lemmy.one avatar

Any time I see graphs or statistics which cut of at 2020 to 2021 I get the feeling that the trend is being misrepresented, maybe deliberately.

Nations Are Getting Serious About Climate Action. Just Not Serious Enough. There’s a lot more work to do to keep global temperatures at relatively safe levels (www.nytimes.com)

If every single country were to follow through on its stated plans (a big if) then global greenhouse gas emissions would be 2 percent to 9 percent lower at the end of the decade than they are today....

Jummit,
@Jummit@lemmy.one avatar

But that would still put Earth on track to heat up roughly 2.5 to 2.9 degrees Celsius over preindustrial levels by the century’s end, the report found

Doesn’t that still mean extinction of nearly all life on earth? What’s with the headline saying “safe levels”?

Jummit,
@Jummit@lemmy.one avatar

I think we have underestimated how much progress has been made on killing the planet.

Jummit,
@Jummit@lemmy.one avatar

I doubt TCP/UDP or basic HTTP requests will change much, but I guess it depends on how high-level the API is.

Jummit,
@Jummit@lemmy.one avatar

Same here. Sounds pretty sustainable to me!

Jummit,
@Jummit@lemmy.one avatar

It was always self defense. Just not as justified as it is now.

Jummit,
@Jummit@lemmy.one avatar

I’m going to use harelang.org to get more comfortable in it, and maybe my own languages, Otomescript and Hase.

Jummit,
@Jummit@lemmy.one avatar

Of course the most productive comment is the least upvoted one. EDIT: After thinking about it, maybe it’s best to add an explanation to bare links.

Jummit,
@Jummit@lemmy.one avatar

It’s double speak. The translation is “We are evil and if you say something about what you see, we will silence you.”.

Jummit,
@Jummit@lemmy.one avatar

Are you beginning to see things more clearly now?

Jummit,
@Jummit@lemmy.one avatar

Actually, I like encapsulating global state in a structured and documented construct. But I guess I could see Java developers going overboard with abstraction in an imperative language.

Jummit,
@Jummit@lemmy.one avatar

Interesting, that definitely makes sense!

Jummit,
@Jummit@lemmy.one avatar

I’ve recently come to appreciate the “refactor the code while you write it” and “keep possible future changes in mind” ideas more and more. I think it really increases the probability that the system can live on instead of becoming obsolete.

Jummit,
@Jummit@lemmy.one avatar

Das ist Doppelsprech für “enorme Auswirkungen auf die Stabilität meiner Machtposition”.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • InstantRegret
  • magazineikmin
  • tester
  • Durango
  • Youngstown
  • rosin
  • khanakhh
  • slotface
  • ngwrru68w68
  • mdbf
  • thenastyranch
  • kavyap
  • DreamBathrooms
  • megavids
  • modclub
  • everett
  • Leos
  • GTA5RPClips
  • osvaldo12
  • ethstaker
  • cisconetworking
  • tacticalgear
  • normalnudes
  • anitta
  • cubers
  • provamag3
  • lostlight
  • All magazines