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
function global:prompt | |
{ | |
$global:GitPromptSettings.DefaultPromptSuffix = "" | |
Update-ZLocation $pwd | |
"╭─ $(ZLocationOrigPrompt) $('+' * ($nestedPromptLevel))`n╰─$ "; | |
#"╭─ PS $($executionContext.SessionState.Path.CurrentLocation) $('+' * ($nestedPromptLevel))`n╰─$ "; | |
} |
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
from ortools.sat.python import cp_model | |
from typing import NamedTuple | |
class Box(NamedTuple): | |
weight: int | |
class Truck(NamedTuple): | |
capacity: int | |
trucks = [Truck(3000), Truck(5000), Truck(8000)] |
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
-- ref: https://www.youtube.com/watch?v=k-QwBL9Dia0&ab_channel=SkillsMatter%28formerlyYOW%21Conferences%29 | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TupleSections #-} | |
import Data.Functor.Identity | |
import Data.Functor.Const | |
type Lens s t a b = forall f . Functor f => (a -> f b) -> (s -> f t) | |
type Lens' s a = Lens s s a a |
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 Data.List | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
frequencyOfElt xs = [ (c, length $ filter (== c) xs) | c <- nub xs] | |
type Rule = (String,Char) | |
parseFile :: [String] -> (String, [Rule]) | |
parseFile (r1:_:rs) = |
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
# v <- c(3,4,3,1,2) | |
v <- c(5,3,2,2,1,1,4,1,5,5,1,3,1,5,1,2,1,4,1,2,1,2,1,4,2,4,1,5,1,3,5,4,3,3,1,4,1,3,4,4,1,5,4,3,3,2,5,1,1,3,1,4,3,2,2,3,1,3,1,3,1,5,3,5,1,3,1,4,2,1,4,1,5,5,5,2,4,2,1,4,1,3,5,5,1,4,1,1,4,2,2,1,3,1,1,1,1,3,4,1,4,1,1,1,4,4,4,1,3,1,3,4,1,4,1,2,2,2,5,4,1,3,1,2,1,4,1,4,5,2,4,5,4,1,2,1,4,2,2,2,1,3,5,2,5,1,1,4,5,4,3,2,4,1,5,2,2,5,1,4,1,5,1,3,5,1,2,1,1,1,5,4,4,5,1,1,1,4,1,3,3,5,5,1,5,2,1,1,3,1,1,3,2,3,4,4,1,5,5,3,2,1,1,1,4,3,1,3,3,1,1,2,2,1,2,2,2,1,1,5,1,2,2,5,2,4,1,1,2,4,1,2,3,4,1,2,1,2,4,2,1,1,5,3,1,4,4,4,1,5,2,3,4,4,1,5,1,2,2,4,1,1,2,1,1,1,1,5,1,3,3,1,1,1,1,4,1,2,2,5,1,2,1,3,4,1,3,4,3,3,1,1,5,5,5,2,4,3,1,4) | |
n <- 80 | |
for(i in 1:n) { | |
v1 <- v[v == 0] + 8 | |
v2 <- v[v == 0] + 6 | |
v3 <- v[v > 0] - 1 | |
v <- c(v1, v2, v3) | |
#print(length(v)) |
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
input <- read.table("input.txt", header = FALSE) # the input was sligtly adjusted to be accepted by read.table | |
n <- dim(input)[1] | |
xs <- input[c(1, 3)] | |
xs <- xs - min(xs) + 1 | |
ys <- input[c(2, 4)] | |
ys <- ys - min(ys) + 1 | |
m <- matrix(0, max(ys), max(xs)) |
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
-- https://bartoszmilewski.com/2017/01/02/comonads/ | |
-- https://hackage.haskell.org/package/comonad-5.0.8/docs/Control-Comonad.html | |
import Control.Comonad | |
import Debug.Trace (trace) | |
data Stream a = Cons a (Stream a) | |
instance Functor Stream where | |
fmap f (Cons a as) = Cons (f a) (fmap f as) |
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
-- https://adventofcode.com/2020/day/20 | |
{-# LANGUAGE DeriveFunctor #-} | |
{-# OPTIONS_GHC -Wno-incomplete-patterns #-} | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import Data.Maybe (Maybe) | |
import qualified Data.Maybe as Maybe | |
import Data.Set (Set) | |
import qualified Data.Set as Set |
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
-- https://adventofcode.com/2017/day/24 | |
-- https://bartoszmilewski.com/2017/12/29/stalking-a-hylomorphism-in-the-wild/amp/ | |
{-# LANGUAGE DeriveFunctor #-} | |
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import qualified Data.List as List | |
import Data.List.Split (splitOn) | |
import Data.Function ((&)) |
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
-- https://chrispenner.ca/posts/representable-discrimination | |
{-# LANGUAGE TypeFamilies, FlexibleContexts, DeriveFunctor #-} | |
import Data.Monoid (Sum(..)) | |
class Representable f where | |
type Rep f :: * | |
tabulate :: (Rep f -> a) -> f a | |
index :: f a -> Rep f -> a |
NewerOlder