Skip to content

Instantly share code, notes, and snippets.

View jeremysinger's full-sized avatar

Jeremy Singer jeremysinger

View GitHub Profile
import Data.Char
x = "the quick brown fox jumps over the lazy dog"
y = "it was the best of times, it was the worst of times"
z = "to be or not to be"
bigrams :: [Char] -> [(Char,Char)]
-- generate a list of bigram pairs for a string
bigrams sentence = removeNonAlphaChars $ zip sentence $ tail sentence
@jeremysinger
jeremysinger / SJF.java
Created March 7, 2017 11:22
shortest job first example code
package os.coursework;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
/**
* Shortest Job First (SJF) scheduling model
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BOOT_SECTOR_OFFSET 0
typedef struct {
unsigned char jmp[3];
char oem[8];
unsigned short sector_size;
#include <stdio.h>
#include <unistd.h>
#define END_OF_LIST (void *)-1
typedef union FreeListCell {
union FreeListCell *next;
char str[CELL_SIZE_IN_BYTES];
} cell;
mysequence :: (Num a, Ord a) => a -> a -> [a] -> [a]
mysequence lower upper accum_list =
if upper<lower
then accum_list
else mysequence lower (upper-1) (upper:accum_list)
f = open('/usr/share/dict/words')
# this is where my dictionary lives on my Mac
words = f.read().splitlines()
# one word per line
f.close()
# OS complains if we don't close files
def spotTheDifference(myword, properword):
import string
import urllib.request
# download the data from the internet
url = 'https://sherlock-holm.es/stories/plain-text/cano.txt'
response = urllib.request.urlopen(url)
data = response.read() # read the raw bytes
text = data.decode('utf-8') # turn the raw data into a Python string
words = text.split()
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
if length args /= 2
then do
putStrLn "usage: starman WORD NUM_GUESSES"
else
let word = args!!0
-- | The 'wordPhrase' function spells out an individual word
-- For example, "a is for apple"
wordPhrase :: String -> String
wordPhrase x = (head x) : " is for " ++ x
-- | The 'speller' function generates text for a spelling book
-- from a list of words
speller :: [String] -> String
speller [] = []
@jeremysinger
jeremysinger / output.txt
Created November 12, 2018 10:40
Ideal output from FP Receipts exercise
<start>
* Items Purchased
+ 1 Apple 0.50
+ 2 Apple 0.50
+ 3 Apple 0.50
+ 4 Apple 0.50
+ 5 Apple 0.50
+ 6 Watermelon 3.00
+ 7 Sumatran Coffee Beans 6.00