Skip to content

Instantly share code, notes, and snippets.

View dhanji's full-sized avatar

Dhanji R. Prasanna dhanji

View GitHub Profile
-- 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
-- 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
-- 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
-- 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
module gigi.pizzeria
verb makePizza {
data {
in
Order(..)
out
Pizza(..)
}
val notifyCustomerSchema = Ftl.schema {
verb(::notifyCustomer)
connectors {
http {
routes("/notify", "/notify-customer")
formats(Format.JSON)
}
grpc()