This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns atom-cas | |
| (:require [clojure.core.async :as async])) | |
| (def a (atom 0)) | |
| (defn updater [current-value] | |
| (prn "Thread: " (Thread/currentThread)) | |
| (prn "Current: " current-value) | |
| (Thread/sleep 500) | |
| (inc current-value)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defmacro infix-math-dsl [form] | |
| (letfn [(parse [x] | |
| (cond | |
| (number? x) | |
| {:node :number :value x} | |
| (symbol? x) | |
| (let [s (str x)] | |
| (if (contains? #{"+" "-" "*" "/"} s) | |
| {:node :op :value x} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tokens: | |
| split(" ") | map(select(length > 0)); | |
| def isnum: | |
| test("^-?([0-9]+(\\.[0-9]+)?)$"); | |
| def evaluate: | |
| def eval($tokens): | |
| if ($tokens | length) == 0 then | |
| error("ending unexpected") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defmacro cond-as-> | |
| [value sym & clauses] | |
| (when (odd? (count clauses)) | |
| (throw (IllegalArgumentException. "cond-as-> requires an even number of clauses"))) | |
| (let [steps (partition 2 clauses)] | |
| (loop [val value, steps steps] | |
| (if (empty? steps) | |
| val | |
| (let [[test expr] (first steps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var isValidSudoku = function(board) { | |
| const rows = new Array(9).fill(0).map(() => new Set()); | |
| const cols = new Array(9).fill(0).map(() => new Set()); | |
| const boxes = new Array(9).fill(0).map(() => new Set()); | |
| for (let i = 0; i < 9; i++) { | |
| for (let j = 0; j < 9; j++) { | |
| const num = board[i][j]; | |
| if (num === '.') continue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const example = "1 - 1 + 3 + 44 / 2"; | |
| const lexer = (source: string): string[] => { | |
| const tokens: string[] = []; | |
| let currentToken = ""; | |
| for (const char of source) { | |
| if ([" ", "+", "-", "*", "/"].includes(char)) { | |
| if (currentToken) tokens.push(currentToken); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module MathInterpreter (mathInterpreter) where | |
| import Data.Char | |
| data Token = Number Integer | |
| | Plus | |
| | Dash | |
| | Star | |
| | Slash | |
| deriving Show |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +-assoc-proof : ∀ (x y z : ℕ) → x + (y + z) ≡ (x + y) + z | |
| +-assoc-proof zero y z = refl | |
| +-assoc-proof (suc x) y z = cong suc (+-assoc-proof x y z) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with recursive fib as ( | |
| select 0 as a, 1 as b | |
| union | |
| select b, a + b from fib | |
| ) select a from fib limit 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Iter<A> = () => A | null; | |
| const array_to_iter = <A>(arr: A[]): Iter<A> => { | |
| let index = 0; | |
| return () => { | |
| const el = arr[index]; | |
| index += 1; | |
| return el; | |
| } |
NewerOlder