This file contains hidden or 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
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE InstanceSigs #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE Rank2Types #-} | |
| module Stack where | |
| data Nat = Zero | Succ Nat |
This file contains hidden or 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
| {-# LANGUAGE BangPatterns #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE Rank2Types #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# OPTIONS_GHC -fno-warn-orphans #-} | |
| module Main (main) where | |
| import Control.Applicative |
This file contains hidden or 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 Main (main) where | |
| main :: IO () | |
| main = print . length $ filter ((== 10) . sum . map points . divisors) [1..1000000] | |
| divisors :: Int -> [(Int, Int)] | |
| divisors n = [(t, n `quot` t) | t <- [1 .. round (sqrt (fromIntegral n))], n `rem` t == 0] |
This file contains hidden or 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 Main (main) where | |
| import Control.Applicative | |
| import Data.Function (on) | |
| import Data.List (sort, subsequences) | |
| import Data.Attoparsec.ByteString.Char8 hiding (take) | |
| import qualified Data.ByteString as B | |
| import Data.ByteString (ByteString) | |
| import qualified Data.Set as S |
This file contains hidden or 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 Main (main) where | |
| import Data.Function (on) | |
| import Data.List (minimumBy, sort, subsequences) | |
| import qualified Data.Set as S | |
| main :: IO () | |
| main = putStrLn . concatMap show . minimumBy (compare `on` sum) . |
This file contains hidden or 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 Main (main) where | |
| import Data.Packed.Matrix | |
| import qualified Data.Packed.Vector as V | |
| import Numeric.LinearAlgebra.Algorithms (inv) | |
| import Numeric.Container | |
| type Dimension = Int | |
| type Point = Int |
This file contains hidden or 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
| {-# LANGUAGE DeriveGeneric #-} | |
| module Main where | |
| import Control.Applicative | |
| import Control.Monad (replicateM) | |
| import GHC.Generics (Generic) | |
| import Control.Lens | |
| import Control.Monad.State.Strict (State, evalState, get, modify) | |
| import Data.Array |
This file contains hidden or 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 Main where | |
| import Control.Applicative | |
| import Control.Monad (replicateM) | |
| import Data.Array | |
| import Data.Attoparsec | |
| import Data.Attoparsec.ByteString.Char8 | |
| import qualified Data.ByteString as B |
This file contains hidden or 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
| (define nil (λ (f) (λ (t) t))) | |
| (define cons (λ (h) (λ (t) (λ (f) (λ (z) ((f h) ((t f) z))))))) | |
| (equal? ((nil +) 3) 3) | |
| (equal? ((((cons 1) ((cons 2) ((cons 3) ((cons 4) nil)))) (λ (x) (λ (y) (+ x y)))) 0) 10) | |
| (equal? ((((cons 1) ((cons 2) ((cons 3) ((cons 4) nil)))) (λ (x) (λ (y) (* x y)))) 1) 24) | |
| (define isnil? (λ (xs) ((xs (λ (x) (λ (y) false))) true))) | |
| (equal? (((isnil? nil) 4) 7) 4) |
This file contains hidden or 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
| Inductive natlist : Type := | |
| | nil : natlist | |
| | cons : nat -> natlist -> natlist. | |
| Definition bag := natlist. | |
| Fixpoint count (v : nat) (s : bag) : nat := | |
| match s with | |
| | p :: ps => if beq_nat p v then 1 + count v ps else count v ps | |
| | nil => 0 |