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 annealing | |
import java.awt.* | |
import java.awt.geom.Ellipse2D | |
import javax.swing.JFrame | |
import java.util.Random | |
import kotlin.math.pow | |
import kotlin.math.roundToInt |
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 java.io.File | |
val dictionary = "/usr/share/dict/words" | |
val minimumLength = 5 | |
fun main(args: Array<String>) { | |
val words = File(dictionary).readLines() | |
val output = File("/Users/william/Desktop/words.txt").bufferedWriter() | |
words.forEach { word -> |
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
fun main(args: Array<String>) | |
{ | |
val users = listOf( | |
User(username = "will", isAdmin = true), | |
User(username = "james", isAdmin = true), | |
User(username = "aneesh", isAdmin = true), | |
User(username = "usain"), | |
User(username = "michael") | |
) |
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
open System | |
type Point = { x : double; y : double } | |
let distance (start : Point) (finish : Point) : double = | |
let x = finish.x - start.x | |
let y = finish.y - start.y | |
sqrt (x * x + y * y) | |
[<EntryPoint>] |
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
using System; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
namespace ConsoleApplication | |
{ | |
class Program | |
{ |
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
// Automatically responds to changes in `value` property | |
class Observable<Value, Return> { | |
// Contents of observable | |
var value: Value | |
// Run whenever value changes | |
let onChange: Value -> Return | |
init(withInitial value: Value, onChange change: Value -> Return) { |
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 Either where | |
import Prelude hiding (Either, Left, Right) | |
data Either failure success = Left failure | Right success | |
deriving (Show, Read, Eq) | |
instance Functor (Either failure) where | |
fmap _ (Left x) = Left x | |
fmap f (Right x) = Right (f x) |
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 |
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
module Result where | |
import Control.Monad | |
import Data.Monoid | |
data Result a b | |
= Failure a | |
| Success b | |
deriving (Show) | |
NewerOlder