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
-- Floyd's algorithm to detect a cycle in a linked list | |
-- Also called the "Tortoise & Hare" algorithm | |
-- This increments two pointers at different rates, if | |
-- the second laps the first, then we have a cycle. | |
cyclical pick = iterateList 0 1 pick | |
where | |
iterateList tortoise hare pick | |
| pick tortoise == -1 = False | |
| pick hare == -1 = False |
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
-- Finds the intersection of two rectangles, returned as a rectangle. | |
-- | |
data Rect = Rect { x :: Int, | |
y :: Int, | |
width :: Int, | |
height :: Int | |
} | NoRect deriving Show | |
-- Returns the intersection rectangle or NoRect if they don't intersect |
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
-- Largest interval algorithm. | |
-- "Compute the largest profit to be gained from a series of prices" | |
-- | |
profits smallest largest gains [] = gains | |
profits smallest largest gains (p:ps) | |
| p < smallest = profits p p (gains ++ [largest - smallest]) ps | |
| p > largest = profits smallest p (gains ++ [p - smallest]) ps | |
| otherwise = profits smallest largest gains ps |
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
-- Djikstra's shunting yard algorithm to parse infix notation expressions | |
-- 3 + 4 - 1 => 3 4 1 - + | |
-- https://en.wikipedia.org/wiki/Shunting-yard_algorithm | |
import Data.List | |
precedence "(" = 1 | |
precedence ")" = 1 | |
precedence "+" = 2 | |
precedence "-" = 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
module gigi.pizzeria | |
verb makePizza { | |
data { | |
in | |
Order(..) | |
out | |
Pizza(..) | |
} |
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
val notifyCustomerSchema = Ftl.schema { | |
verb(::notifyCustomer) | |
connectors { | |
http { | |
routes("/notify", "/notify-customer") | |
formats(Format.JSON) | |
} | |
grpc() |
OlderNewer