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
{-# LANGUAGE OverloadedStrings #-} | |
-- Ignore all the redundant string conversions | |
-- There's probably a better way to do it | |
import Control.Applicative | |
import qualified Data.Text as Text | |
import Data.ByteString.Lazy.Char8 (unpack) | |
import Web.Spock.Safe |
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
fn main() { | |
let program_data = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; | |
let mut program = Program::from_chars(program_data); | |
program.step(); | |
println!("OUTPUT:"); | |
println!(" pointer: {}", program.pointer); | |
println!(" data: {:?}", program.data); | |
} | |
#[derive(Debug)] |
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.Map (Map) | |
import qualified Data.Map as Map | |
import Control.Monad | |
-- | Returns a Map with counts of items in a list | |
count :: (Ord a, Integral b) => [a] -> Map a b | |
count = | |
foldr updateMap Map.empty | |
where updateMap v counts | |
| Map.member v counts = Map.adjust succ v counts |
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"database/sql" | |
_ "github.com/lib/pq" | |
) |
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 EvaluateSandwich | |
( SandwichComponent | |
, Sandwich | |
, validateSandwich | |
, indicesSeparated | |
) where | |
import Data.List (elemIndices) | |
-- | Components of a sandwich |
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
mapM_ putStrLn $ map (\x -> case (x `rem` 3, x `rem` 5) of (0, 0) -> "FizzBuzz"; (0, _) -> "Fizz"; (_, 0) -> "Buzz"; (_, _) -> show x) [1..100] | |
-- Alternatively | |
import Data.Function ((&)) | |
[1..100] & map (\x -> case (x `rem` 3, x `rem` 5) of (0, 0) -> "Fizzbuzz"; (0, _) -> "Fizz"; (_, 0) -> "Buzz"; (_, _) -> show x) & mapM_ putStrLn |
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
-- This module demonstrates two key principles: | |
-- 1. A general method of traversing neighboring elements in lists | |
-- 2. Appropriate and understandable abstractions are always your friends | |
module ReferenceSurroundings where | |
-- | Returns sublists from xs of length `size` | |
-- i.e. chunkIntoSize 3 [1..5] == | |
-- [[1, 2, 3], [2, 3, 4], [3, 4, 5]] | |
chunkInto :: Int -> [b] -> [[b]] |
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 Result where | |
import Control.Monad | |
import Data.Monoid | |
data Result a b | |
= Failure a | |
| Success b | |
deriving (Show) | |
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 HashMap where | |
import Prelude hiding (lookup) | |
-- | HashMap backed by a binary tree. Most operations are O(log(n)) | |
data HashMap k v = EmptyMap | Map (k, v) (HashMap k v) (HashMap k v) deriving (Read, Show) | |
-- | Apply fmap over all values | |
instance (Ord k) => Functor (HashMap k) where |
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
// | |
// LazySquares.swift | |
// SwiftBook | |
// | |
// Created by William Davenport on 12/10/15. | |
// Copyright © 2015 William Davenport. All rights reserved. | |
// | |
import Foundation |
OlderNewer