Skip to content

Instantly share code, notes, and snippets.

@kiran-kp
kiran-kp / aoc_2022.rkt
Last active December 16, 2022 21:55
Advent of Code 2022
#lang racket
(module day1 racket
(provide part1 part2 get-input debugging?)
(require threading)
(define (get-input)
(file->string "day1.txt"))
@kiran-kp
kiran-kp / 2020.rkt
Last active January 23, 2021 00:05
Advent of Code 2020
#lang racket
(require (prefix-in data: "2020_data.rkt"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module+ day1
(define expenses (map string->number (string-split (data:day1) #:trim? #t #:repeat? #t)))
(define sum-is-2020? (compose (curry = 2020) (curry apply +)))
(define (part1)
@kiran-kp
kiran-kp / trackball_hack.cpp
Created September 4, 2020 05:19
Hack trackball to simulate mousewheel
#include <Windows.h>
#include <iostream>
#include <chrono>
HHOOK mhook;
MSG msg;
bool forwardButtonHeld = false;
long mouseX = 0;
long mouseY = 0;
@kiran-kp
kiran-kp / 7.rs
Created December 12, 2015 03:50
Solution for Day 7
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
#[derive(Debug)]
enum Op {
Value(String),
And(String, String),
Or(String, String),
Not(String),
RShift(String, String),
@kiran-kp
kiran-kp / 5.hs
Last active December 7, 2015 01:58
Day 5 solution
#!/usr/bin/env runhaskell
{-# LANGUAGE QuasiQuotes #-}
import Data.List.Split
import Data.List
import Text.RawString.QQ
main = print $ numNiceStrings1 input
where
@kiran-kp
kiran-kp / 3.hs
Last active December 3, 2015 23:46
Solution for day 3
import Data.Set (fromList)
newPos '^' (x, y) = (x, y+1)
newPos '<' (x, y) = (x-1, y)
newPos '>' (x, y) = (x+1, y)
newPos 'v' (x, y) = (x, y-1)
curPos = head . reverse
moveSanta acc d = acc ++ [newPos d (curPos acc)]
@kiran-kp
kiran-kp / 2.hs
Last active December 3, 2015 07:38
Solution for day 2
#!/usr/bin/env runhaskell
{-# LANGUAGE QuasiQuotes #-}
import Data.List.Split
import Text.RawString.QQ
main = print $ (totalPaperRequired, totalRibbonRequired)
where
boxes = splitOn "\n" input
@kiran-kp
kiran-kp / 1.hs
Last active December 3, 2015 04:55
Haskell solution for Day1
direction '(' = 1
direction ')' = (-1)
direction x = 0
checkBasement (-1) oldPos pos = min pos oldPos
checkBasement currentFloor oldPos pos = oldPos
stepFn (curFloor, minFloor, curPos) y = ((curFloor + direction y), (checkBasement (curFloor + direction y) minFloor curPos), curPos + 1)
main = print $ foldl stepFn (0, 7000, 1) "((((()(()(((((((()))(((()((((()())(())()(((()((((((()((()(()(((()(()((())))()((()()())))))))))()((((((())((()))(((((()(((((((((()()))((()(())()((())((()(()))((()))()))()(((((()(((()()))()())((()((((())()())()((((())()(()(()(((()(())(()(())(((((((())()()(((())(()(()(()(())))(()((((())((()))(((()(()()(((((()()(()(((()(((((())()))()((()(()))()((()((((())((((())(()(((())()()(()()()()()(())((((())((())(()()))()((((())))((((()())()((((())((()())((())(())(((((()((((()(((()((((())(()(((()()))()))((((((()((())()())))(((()(()))(()()(()(((()(()))((()()()())((()()()(((())())()())())())((()))(()(()))(((((()(()(())((()(())(())()((((()())()))((((())(())((())())((((()(((())(())((()()((((()((((((()(()