Instantly share code, notes, and snippets.

😆

# someodd someodd

😆
Last active August 23, 2022 23:03
Longest binary gap coding puzzle
View BinaryGap.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 {- # PROBLEM A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary
Created August 23, 2022 23:01
Challenge I saw on HackerNews, "Most candidates cannot solve this interview problem."
View MostCandidatesFail.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 {- I saw this posted on HackerNews: "Most candidates cannot solve this interview problem." https://twitter.com/Al_Grigor/status/1357028887209902088 > Most candidates cannot solve this interview problem: > Input: "aaaabbbcca" > Output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)]
Created August 23, 2022 23:04
Challenge in parsing math expressions from some kinda AST.
View MathExpr.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import Control.Monad.Reader import Data.Map as Map data Expr = Lit Int | Var String | Add Expr Expr | Let (String, Expr) Expr eval :: Expr -> Reader (Map String Int) Int eval (Lit i) = pure i eval (Var s) = do varMap <- ask case Map.lookup s varMap of
Created August 23, 2022 23:06
Advent of Code 2020: Day 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 {- Advent of Code: Day 2 Part 1 & 2 https://adventofcode.com/2020/day/2 -} type PasswordData = ((Int, Int, Char), String)
Created August 23, 2022 23:07
Advent of Code 2020: Day 1