http://csunplugged.org/sorting-networks
communication
| locals { | |
| most_calories = reverse([for elf_calories in sort([for elf_calories in split(" ", replace(file("input1.txt"), "\n", " ")) : format("%08d", sum([for food_calories in split(" ", elf_calories) : food_calories == "" ? 0 : parseint(food_calories, 10)]))]) : tonumber(elf_calories)])[0] | |
| } | |
| output "answer" { | |
| value = local.most_calories | |
| } |
http://csunplugged.org/sorting-networks
communication
https://pwlconf.org/2018/roopsha-samanta/
Processes are Finite-state synchronization skeletons - supress details about synchronization Communication model: Shared memory, interleaving based - one thread takes a step at a time Specification: Temporal logic Synchronization: Guarded commands
| {-# LANGUAGE FlexibleContexts #-} | |
| module Main where | |
| import Java | |
| import Java.Do | |
| main :: IO () | |
| main = putStrLn $ | |
| mconcat $ | |
| fmap (\x -> let _ = x :: JInteger in show x) $ |
| data Sh = Sh1 {name :: String} | Sh2 {name :: String, age :: Int} | |
| instance shIsForeign :: IsForeign Sh where | |
| read x = do | |
| name <- readProp "name" x | |
| case (readProp "age" x) of | |
| Left _ -> pure $ Sh1 {name:name} | |
| Right age -> pure $ Sh2 {name: name, age: age} | |
| frug :: Foreign -> String |
| ;; A protocol with a single method | |
| (defprotocol Waggable | |
| (wag [x])) | |
| ;; A record that implements that protocol | |
| (defrecord Dog [name] | |
| Waggable | |
| (wag [x] | |
| (prn (str (:name x) | |
| " wagged their tail")))) |
| (let [input (take 1000 (repeatedly #(rand-int 10))) | |
| n 3] | |
| (take 10 | |
| (reverse (sort-by second | |
| (frequencies (mapcat #(partition n (drop % input)) | |
| (range n))))))) |
| NB. Turn on tree formatting of sentences: | |
| (9!:3) 4 | |
| 1;2;3;4 | |
| NB. ┌─┬─┬─┬─┐ | |
| NB. │1│2│3│4│ | |
| NB. └─┴─┴─┴─┘ |