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
| (defn hamming-distance [s1 s2] | |
| (if (not= (count s1) (count s2)) | |
| (throw (Exception. "Lengths are not equal")) | |
| (->> (map = s1 s2) | |
| (remove true?) | |
| (count)))) |
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
| ;;Exercise 1.31, generate Pi via wallis formula | |
| ;; recognize pi = * 4 (2 * (1/3)* 4 * (1/5) ...) * ((1/3) * 4 * (1/5)...) | |
| ;; arithmetic progression formula was used to find out the ending term | |
| ;; a_k = a_1 + (n-1)d | |
| (define (pi-prod n) | |
| (define (inv k) | |
| (if (even? k) | |
| k | |
| (/ 1 k))) |
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
| import Control.Monad.Trans.State | |
| import System.Random | |
| data Tree a = Empty | Node a (Tree a) (Tree a) deriving Show | |
| makeRandomTree :: Int -> State StdGen (Tree Int) | |
| makeRandomTree 0 = return Empty | |
| makeRandomTree x = get >>= \gen -> ( | |
| let (randVal, newGen) = randomR (1,6) gen | |
| in put newGen >> makeRandomTree (x-1) >>= |
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
| import System.Random | |
| import Control.Monad.State | |
| -- given a [Int] add random numbers to it | |
| a :: [Int] | |
| a = [3, 1, 6, 7, 9] | |
| myFunc :: Int -> State StdGen Int | |
| myFunc x = do | |
| gen <- get |
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
| import System.Random | |
| import Control.Monad.State | |
| diceRange :: (Int, Int) | |
| diceRange = (1,6) | |
| diceThrow :: State StdGen Int | |
| diceThrow = do | |
| gen <- get | |
| let (a,newGen) = randomR diceRange gen |
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 OverloadedStrings #-} | |
| {-# LANGUAGE DeriveGeneric #-} | |
| module Main where | |
| import Web.Scotty | |
| import qualified Network.Wreq as W | |
| -- import Data.Aeson | |
| import GHC.Generics | |
| import qualified Data.Text.Lazy as L |
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
| class Node: | |
| def __init__(self,val,parent=None): | |
| self.val = val | |
| self.children = [] | |
| self.parent = parent | |
| def __eq__(self,other): | |
| if self.val == other.val: | |
| return True |
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
| import Data.Time | |
| import Data.Time.Clock | |
| import Control.Monad | |
| import Control.Concurrent | |
| import Data.Maybe | |
| data Job = Job { date :: UTCTime, message :: String } | |
| timeFormat :: String | |
| timeFormat = "%Y-%m-%dT%H:%M:%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
| {-# LANGUAGE OverloadedStrings #-} | |
| import Control.Concurrent | |
| import Control.Concurrent.Async | |
| import Control.Monad | |
| import Web.Scotty | |
| asyncPrint :: IO () | |
| asyncPrint = forever $ putStrLn "Hello" >> threadDelay (1000000) |
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
| package com.example | |
| import java.io._ | |
| import org.http4s._ | |
| import org.http4s.client.blaze._ | |
| object Hello { | |
| def writeToFile (content: String): Unit = { |