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
//Pinstats. | |
//Fetch the pinterest front page. Extract all the name elements | |
//and keep track of the gender of what you find | |
package main | |
import ( | |
"code.google.com/p/go-html-transform/html/transform" | |
"fmt" |
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 Main where | |
-- Q1. Write a function that looks up a hash table value that uses the Maybe Monad. (IMHO this | |
-- question is kinda sloppily written, does the hash table use the maybe monad or the function?). | |
-- Write a hash that stores other hashes, several levels deep. Use the Maybe monad to retrieve | |
-- an element several levels deep. (wtf does this even mean? is the maybe monad going to do the | |
-- retrieving for me?) | |
-- What I am going to attempt to do (my interpretation of the above): | |
-- 1. Write a function that looks up a value by key (in a collection of key value pairs) | |
-- and returns a result wrapped in the Maybe monad. |
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
-- Q4 Write a function that takes an argument x and returns a lazy sequence that has | |
-- every third number, starting with x. Then write a second function that includes every fifth | |
-- number beginning with y. Combine these functions through composition to return every eighth | |
-- number beginning with x + y. | |
-- sooooo... the first solution to the first two was kind of given in the book (the myrange | |
-- function) and i don't fully get the third part. From what i understand about function composition | |
-- the return type of first function must match the argument type of the second function in the chain | |
-- this makes complete sense; if f . g = \x -> f (g x), the (g x) must result in something f can take | |
-- in this case both functions takes a number but returns a sequence. This sequence cannot be an |
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
-- Q3 Write a function that converts a string to a numerical type. The string is in the form | |
-- $2,345,678.99 and can have leading zeroes. | |
-- I'm not going to be doing error checking on the format btw | |
strToNum :: Fractional a => [Char] -> a | |
strToNum str = let | |
-- remove the '$' and ',' | |
plain = filter (\x -> x /= '$' && x /= ',') str | |
whole = takeWhile (\x -> x /= '.') plain |
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
-- Q1 Write a function to sort a list | |
--Trying out bubble sort just to see how i would approach it in haskell | |
--recursve sorts like quicksort would likely be more natural to express | |
--helper function does one iteration of the bsort algorithm | |
bsorthelper [] = [] | |
bsorthelper [a] = [a] | |
bsorthelper lst = let | |
(f:s:rest) = lst |
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 Main where | |
-- Q1. How many different ways can you write the function allEven? | |
-- allEven using built in higher order functions | |
ae1 :: [Integer] -> Bool | |
ae1 x = all even x | |
-- allEven with recursion | |
ae2 [] = True | |
ae2 (h:t) = if even h then ae2 t else 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
(ns day-3 | |
(:use clojure.contrib.pprint)) | |
;Q1 use refs to create a vector of accounts in memory. Create debit and credit | |
; functions to change the balance of an account | |
; Note: I'm going to use a map instead of a vector so that accounts can have names | |
(def bank (ref { })) | |
(defn make-account [bank account-name balance] |
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
;The sleeping barber problem http://en.wikipedia.org/wiki/Sleeping_barber_problem | |
; Q. Calculate how many haircuts can be done in 10 seconds | |
; One barber, one barber chair | |
; Three chairs in waiting room | |
; Customers arrive at random intervals 10-30ms apart | |
; Haircuts take 20ms | |
; (ns day-3 | |
; (:use clojure.contrib.pprint)) | |
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
;standard stack consuming fib | |
(defn fib [n] | |
(cond | |
(= 0 n) 0 | |
(= 1 n) 1 | |
:else (+ (fib (- n 1)) (fib (- n 2))))) | |
;tail recursive fib using loop-recur | |
;loop-recur allow you to rebind variables each |
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
(ns day1.core) | |
(defn big [str n] | |
"Returns true if string [str] is longer than [n] | |
false otherwise" | |
(> (count str) n)) | |
;usage | |
(big "hello" 2) |