Skip to content

Instantly share code, notes, and snippets.

View hovsater's full-sized avatar
🤟

Kevin Hovsäter hovsater

🤟
View GitHub Profile
alias w 'save'
alias wq 'save; quit'
alias q 'quit'
alias q! 'quit -f'
set statusline-left ' %i%S%f%s%m%s%r%s%M'
def-mode -u vi-normal
bind -T vi-normal j down
bind -T vi-normal k up
def score(rolls) = score_helper(0, 1, rolls.reverse)
def score_helper(sum, frame, remaining)
case remaining
in 10, 10, x if frame == 10 && x <= 10 then sum + 20 + x
in 10, x, y if frame == 10 && x + y <= 10 then sum + 10 + x + y
in x, y, z if frame == 10 && x + y == 10 && z <= 10 then sum + x + y + z
in x, y if frame == 10 && x + y < 10 then sum + x + y
in 10, x, y, *rest then score_helper(sum + 10 + x + y, frame + 1, [x, y, *rest])
in x, y, z, *rest if x + y == 10 && z <= 10 then score_helper(sum + 10 + z, frame + 1, [z, *rest])
in x, y, *rest if x + y <= 10 then score_helper(sum + x + y, frame + 1, rest)
let score game =
let rec aux sum frame =
function
| 10 :: 10 :: [ x ] when frame = 10 && x <= 10 -> Some(sum + 20 + x)
| 10 :: x :: [ y ] when frame = 10 && x + y <= 10 -> Some(sum + 10 + x + y)
| x :: y :: [ z ] when frame = 10 && x + y = 10 && z <= 10 -> Some(sum + 10 + z)
| x :: [ y ] when frame = 10 && x + y < 10 -> Some(sum + x + y)
| 10 :: x :: y :: rest -> aux (sum + 10 + x + y) (frame + 1) (x :: y :: rest)
| x :: y :: z :: rest when x + y = 10 && z <= 10 -> aux (sum + 10 + z) (frame + 1) (z :: rest)
class Test
FOO = 1
BAR = 'bar'
def call
end
end
@hovsater
hovsater / day_01.clj
Created July 27, 2023 21:40
Solution to Advent of Code year 2022, day 1.
(ns advent-of-code-year-2022.day-01
"Advent of Code - Solution to year 2022, day 1."
(:require
[clojure.string :as str]))
(def sample-input
"1000
2000
3000
@hovsater
hovsater / day01.odin
Last active July 19, 2023 15:14
Solution to part 1 of Advent of Code 2018 (See https://adventofcode.com/2018/day/1)
package main
import "core:io"
import "core:strings"
import "core:testing"
freq :: proc(stream: io.Stream) -> (res: int) {
base :: 10
sign := 1
num: int
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
s := bufio.NewScanner(os.Stdin)
@hovsater
hovsater / change-theme.sh
Last active June 6, 2023 18:41
Change Zed theme automatically based on macOS appearance
#!/usr/bin/env sh
set -e
dark_theme="Andromeda"
light_theme="Solarized Light"
while true; do
if defaults read -g AppleInterfaceStyle &>/dev/null; then
if [ $(< $HOME/.current-theme) = "dark" ]; then
continue;
@hovsater
hovsater / gist:a0b1c26ead82e49bb9f07d23a1ba5f8c
Created April 29, 2023 17:21
Poor Man's version of finding dead code (specifically Ruby constants)
grep -REho --include \*.rb '\b[A-Z_]+\b\s*=' . | tr -d '=' | cut -d' ' -f1 | sort | uniq -u | xargs -I{} bash -c 'if [[ $(grep -Rhow --include \*.rb "{}" . | wc -l) -eq 1 ]] ; then echo {} ; fi'
@hovsater
hovsater / Day05.elm
Created April 22, 2023 06:57
Advent of Code 2022 - Day 5 (using `elm/parser`)
module Year2022.Day05 exposing (..)
import Aoc.Problem exposing (Answer(..), Input, Solution)
import Array exposing (Array)
import List.Extra as List
import Parser exposing ((|.), (|=), Parser, Step(..), andThen, chompIf, chompWhile, getChompedString, int, keyword, loop, map, oneOf, succeed, symbol)
type alias Crate =
String