Here's a simple problem which I found quite fun to implement.
Suggested hoodlums problem (beginner level):
Context:
In the game of dungeons and dragons, an example damage expression might be:
| #!/bin/bash | |
| #Script to test puppet files have valid syntax. | |
| #Intended for use with hudson/jenkins. | |
| set -e | |
| set -u | |
| fail=0 | |
| #TODO: Run these in parallel - we have 4 cores. | |
| #TODO: Control the environment (through the config dir?). |
| echo -n | |
| #quote-escaping removed from the following json | |
| " | |
| {"version": "1.1.0","host": "maps.google.com","request_address": true,"address_language": "en_GB", "wifi_towers": | |
| [ | |
| `iwlist scan 2> /dev/null | | |
| tr -d '\n' | | |
| sed -e 's/Cell [0-9]* - Address: \([0-9A-Z:]*\)[^C]*Channel:\([0-9]*\)[^S]*Signal level=\([0-9-]*\) dBm[^E]*E[^E]*ESSID:"\([^"]*\)"/\{"mac_address": "\1","signal_strength": \3,"age": 0,"channel": \2,"ssid": "\4"}/g' | |
| -e 's/[^{]*{/{/' | |
| -e 's/}[^{]*{/},{/g' |
| object P1 { | |
| def sampleList() = List(1, 10, 100, 2, 20, 200, 5) | |
| def last[A](xs: List[A]): A = | |
| xs match { | |
| case Nil => sys.error("last on empty list") | |
| case x :: Nil => x | |
| case x :: rest => last(rest) | |
| } |
| import Data.List (elemIndex, sortBy, group, sort) | |
| import Data.Ord (comparing) | |
| import Data.Maybe (fromJust) | |
| main = print demo | |
| demo = lsort ["", "ab3","r3","fg3","d3","ijk1","mn","1", "abcdef1"] | |
| lsort :: (Ord a) => [[a]] -> [[a]] | |
| lsort xs = sortBy (comparing lfreq) xs | |
| where |
| main = print $ demo | |
| demo = isSym tree1 | |
| -- test data | |
| tree1 = (Branch 'x' (Branch 'x' Empty Empty) (Branch 'x' Empty Empty)) | |
| tree2 = (Branch 'x' (Branch 'x' Empty Empty) Empty) | |
| data Tree = Branch Char Tree Tree | Empty | |
| isSym :: Tree -> Bool |
| -- Naive attempt at functional parsing | |
| -- (so there is lots of plumbing in each combinator) | |
| -- | |
| -- NOTE: This is NOT a good example of haskell to learn from. | |
| -- | |
| import qualified Data.Map as M | |
| import Prelude hiding ( (>>=), (>>), return) | |
| main = interact $ unlines . map runTest . tail . lines |
| class Generator a where | |
| generate :: [a] | |
| data Media = Book | Video deriving (Enum, Bounded, Show) | |
| data Category = Fiction | NonFiction deriving (Enum, Bounded, Show) | |
| data Item = Item Media Category deriving (Show) | |
| instance Generator Media where | |
| generate = [minBound..maxBound] |
Topics for Dev Journal and Presentation
| function trim(str){ | |
| return str.replace(/^\s*((?:.|\n)*?)\s*$/, "$1"); | |
| } | |
| var testCases = [ | |
| [" a" , "a"], | |
| ["A " , "A"], | |
| [" a " , "a"], | |
| ["a b! " , "a b!"], |