Skip to content

Instantly share code, notes, and snippets.

@mem-memov
mem-memov / insertInOrder
Created October 6, 2019 13:54
insertInOrder
insertInOrder :: Int -> Tree -> Tree
insertInOrder x Leaf = Node x Leaf Leaf
insertInOrder x node@(Node y _ _)
| x == y = node
insertInOrder x (Node y left@(Node ly _ _) Leaf)
| x > ly && x < y = Node x left Leaf
| x < ly = Node y (insertInOrder x left) Leaf
| x > y = Node y left (insertInOrder x Leaf)
insertInOrder x (Node y Leaf right@(Node ry _ _))
| x > y && x < ry = Node x Leaf right
let fltr = f :: (a -> Bool) -> [a] -> [a] where f _ [] = []; f p (x:xs) = if (p x) then x:(f p xs) else f p xs in fltr (<5) [2,44,1,32]
let length = l where l [] = 0; l (x:xs) = 1 + l xs;
@mem-memov
mem-memov / starman.hs
Created September 18, 2019 16:07
guess dog or cat
import System.Random
starman :: Int -> IO ()
starman n = do
let allWords = ["cat", "dog"]
index <- randomRIO(0, (length allWords) - 1)
let word = allWords !! index
turn word ['-' | x <- word] n
turn :: String -> String -> Int -> IO ()
@mem-memov
mem-memov / semantic_javascript
Last active August 22, 2018 20:27
Semantic JavaScript is a new way of inteacting in the web. In this simple example two men give information about birds using cybe language. Semantic graph is created authomatically. The machine asks the second man questions about birds.
var ai = (function() {
var ai = {
phrases: {},
phraseIds: {},
nextPhraseId: 1,
authors: {},
authorIds: {},