Skip to content

Instantly share code, notes, and snippets.

View wasi0013's full-sized avatar
💤

Wasi wasi0013

💤
View GitHub Profile
# Compute 333.75y6 + x2(11x2y2 – y6 – 121y4 – 2) + 5.5y8 + x/(2y) where x = 77617, y = 33096
defmodule Pow do
# https://stackoverflow.com/a/32030190/3083094
require Integer
def pow(_, 0), do: 1
def pow(x, n) when Integer.is_odd(n), do: x * pow(x, n - 1)
def pow(x, n) do
result = pow(x, div(n, 2))
defmodule Solution do
def run, do: get_input() |> solve_part2()
def solve_part1(data),
do: data |> clean_ignored |> clean_garbage |> clean_comma |> count_score(1)
def count_score("", _depth), do: 0
def count_score(<<?{>> <> rest, depth), do: depth + count_score(rest, depth + 1)
def count_score(<<?}>> <> rest, depth), do: count_score(rest, depth - 1)
def clean_ignored(data), do: Regex.replace(~r/!./, data, "")
defmodule Solution do
def run, do: get_input() |> part2()
def part1([child | [meta | data]]), do: calculate(data, child, meta, 0)
def calculate([], _child, _meta, sum), do: sum
def calculate(data, 0, 0, sum), do: {data, sum}
def calculate([hd | data], 0, meta, sum), do: calculate(data, 0, meta - 1, sum + hd)
def calculate([child, meta | data], pchild, pmeta, sum) do
@wasi0013
wasi0013 / convert_ascii_to_upside_down.py
Created January 10, 2024 02:07
Convert ASCII texts to upside down text.
def flip(string):
"""Flips text upside down.
>>> flip("Hello World.")
'˙pןɹoM oןןǝH'
"""
d = {'a': 'ɐ', 'b': 'q', 'c': 'ɔ', 'd': 'p', 'e': 'ǝ', 'f': 'ɟ', 'g': 'ƃ', 'h': 'ɥ', 'i': 'ı', 'j': 'ɾ', 'k': 'ʞ', 'l': 'ן', 'm': 'ɯ', 'n': 'u', 'o': 'o', 'p': 'd', 'q': 'b', 'r': 'ɹ', 's': 's', 't': 'ʇ', 'u': 'n', 'v': 'ʌ', 'w': 'ʍ', 'x': 'x', 'y': 'ʎ', 'z': 'z', 'A': '∀', 'B': '𐐒', 'C': 'Ɔ', 'D': '◖', 'E': 'Ǝ', 'F': 'Ⅎ', 'G': '⅁', 'H': 'H', 'I': 'I', 'J': 'ſ', 'K': '⋊', 'L': '˥', 'M': 'W', 'N': 'N', 'O': 'O', 'P': 'Ԁ', 'Q': 'Ό', 'R': 'ᴚ', 'S': 'S', 'T': '⊥', 'U': '∩', 'V': 'Λ', 'W': 'M', 'X': 'X', 'Y': '⅄', 'Z': 'Z', '0': '0', '1': 'Ɩ', '2': 'ᄅ', '3': 'Ɛ', '4': 'ㄣ', '5': 'ϛ', '6': '9', '7': 'ㄥ', '8': '8', '9': '6', '.': '˙', ' ': ' ', '\n': '\n', '\t': '\t'}
return "".join(map(d.__getitem__, string))[::-1]
def unflip(string):