- buckle my shoe
sdf What do we think about French cheeses?
require 'wordlist' # Get evil idea and swap in code words print "Enter your new idea: " idea = gets code_words.each do |real, code| idea.gsub!( real, code ) end # Save the jibberish to a new file print "File encoded. Please enter a name for this idea: " idea_name = gets.strip File::open( "idea-" + idea_name + ".txt", "w" ) do |f| f << idea end
import System.IO main = do handle <- openFile "girlfriend.txt" ReadMode contents <- hGetContents handle putStr contents hClose handle
Running it, we get the expected result:
$ runhaskell girlfriend.hs Hey! Hey! You! You! I don't like your girlfriend! No way! No way! I think you need a new one!
-- Let's use a fold to implement searching a list for a sublist. search :: (Eq a) => [a] -> [a] -> Bool search needle haystack = foldl length_test False (tails haystack) where length_test bool x = if take needle_length x == needle then True else bool needle_length = length needle declaration :: String declaration = "We hold these truths to be self-evident, " ++ "that all men are created equal"
Here we get the result:
ghci> search "elf" declaration True ghci> search "eat" declaration True
With some inline: , and some displayed:
Doesn’t work yet in the S5 slide show, only plain webpages – need to add a link to jsMath!
Thanks for random snippets to