Skip to content

Instantly share code, notes, and snippets.

View abradley2's full-sized avatar
🌳
https://elm-lang.org/

Tony Bradley abradley2

🌳
https://elm-lang.org/
  • Washington, DC
View GitHub Profile
@abradley2
abradley2 / day-6.hs
Created December 8, 2020 13:05
day-6.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.List
import qualified Data.Text as T
getGroupTotal g = Sum . length $ foldr intersect (mconcat g) g
solvePartTwo = readFile "./input.txt" >>= print . mconcat . fmap getGroupTotal . parseInput
@abradley2
abradley2 / day-7.hs
Created December 8, 2020 13:04
day-7.hs
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Graph as Graph
import Text.ParserCombinators.Parsec as P
sumEdges :: InputGraph -> [InputEdge] -> Maybe (Sum Int)
sumEdges input edges =
mconcat <$>
mapM
( \(key_, count_) ->
@abradley2
abradley2 / day-4.hs
Created December 5, 2020 19:20
day-4.hs
{-# LANGUAGE OverloadedStrings #-}
import Text.ParserCombinators.Parsec as P
import Data.List (nub)
type PassportField = (String, String)
type Passport = [PassportField]
hexParser :: Parser String
@abradley2
abradley2 / day-5.hs
Created December 5, 2020 19:19
day-5.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Main where
import Text.ParserCombinators.Parsec as P
type SeatingChart = [(Int, [Int])]
splitLeft :: [a] -> [a]
@abradley2
abradley2 / day-3.hs
Created December 3, 2020 15:09
day-3.hs
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
import Text.ParserCombinators.Parsec as P
data Slope = Tree | Snow deriving (Show)
type InputLines = [[Slope]]
traverseSlope :: (Int, Int) -> (Int, Int) -> [[Slope]] -> Int
@abradley2
abradley2 / day-2.hs
Created December 3, 2020 15:08
day-2.js
{-# LANGUAGE OverloadedStrings #-}
import Text.ParserCombinators.Parsec as P
data InputLine = InputLine
{ range :: (Int, Int),
charRequirement :: Char,
content :: String
}
deriving (Show)
@abradley2
abradley2 / day-1.hs
Last active December 2, 2020 13:51
Advent of Code 2020 Day 1
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (pack, splitOn, unpack)
findMatchPartTwo :: Int -> [Int] -> Maybe Int
findMatchPartTwo total (x : xs) =
case (* x) <$> findMatchPartOne (total - x) xs of
Just m -> Just m
Nothing -> findMatchPartTwo total xs
findMatchPartTwo _ [] = Nothing
@abradley2
abradley2 / app.tsx
Last active November 16, 2020 14:05
Reactive Programming with React and Most.js
import { startWith, map, constant, merge, combineArray, runEffects, tap } from '@most/core'
import { newDefaultScheduler } from '@most/scheduler'
const textVal$ = startWith(
'',
map(
(e) => (e.target as HTMLInputElement).value,
sources.fromDOMEvent('#text-input', 'input')
)
)
@abradley2
abradley2 / style.md
Last active October 8, 2020 15:29
style-guide

Suggested Style Guide

Prefer a newline+indent and then a newline for each parameter following a tag

avoid

div []
    []
@abradley2
abradley2 / Shpa.hs
Last active August 26, 2020 15:35
Being silly with Shpadoinkle
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Shpadoinkle as S
import Shpadoinkle.Backend.ParDiff
import Shpadoinkle.Html as H
import Data.Text