This file contains 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
(defn fib | |
([n] | |
(take n (fib 0 1))) | |
([a-2 a-1] | |
(cons a-1 (lazy-seq (fib a-1 (+ a-2 a-1)))))) | |
(comment | |
(fib 3) | |
;; => (1 1 2) | |
(fib 6) | |
;; => (1 1 2 3 5 8) |
This file contains 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
(defn my-update-in | |
[m ks f & args] | |
(assoc-in m ks (apply f (cons (get-in m ks) args)))) | |
(comment | |
(my-update-in {:author {:name "Dominik"}} [:author] vec) | |
;; => {:author [[:name "Dominik"]]} | |
(my-update-in {:author {:name "Dominik"}} [:author :name] str " Magdalenski") | |
;; => {:author {:name "Dominik Magdalenski"}} | |
(my-update-in {} [:author :name] str " Magdalenski") |
This file contains 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
(defn my-assoc-in | |
[m [k & ks] v] | |
(assoc m k | |
(reduce (fn [v-in k-in] (assoc {} k-in v-in)) | |
v | |
(reverse ks)))) | |
(comment | |
(my-assoc-in {} [:a] 1) | |
;; => {:a 1} |
This file contains 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
(defn my-comp | |
([f g] | |
(fn [& args] | |
(f (apply g args)))) | |
([f g & fns] | |
(fn [& args] | |
(f (g (reduce (fn [result next-f] (next-f result)) | |
(apply (last fns) args) | |
(reverse (butlast fns)))))))) |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<div id="counter"></div> | |
<button id="start">Start</button> | |
<script> |
This file contains 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
from math import e | |
import numpy as np | |
import matplotlib.pyplot as plot | |
a_arr = np.array([1, 1 / 4]) | |
c_arr = np.array([1, 1 / 4]) | |
t_arr = np.linspace(0, 8, 200) |
This file contains 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
# Example: | |
x_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
y_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
colors = ['black', 'white', 'red'] | |
types = ['-', '*', '+'] | |
for index, value in enumerate(values): | |
plot(x_values[index], y_values[index], colors[index], types[index]) | |
# You can do it better by using just a single array | |
args = [((1, 2, 3), (1, 2, 3), 'black', '-'), ((2, 3, 4), (2, 3, 4), 'white', '*'), ((5, 6, 7), (5, 6, 7), 'red', '+')] |
This file contains 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
(defn my-map | |
([f coll] | |
(reverse | |
(reduce (fn [result x] | |
(cons (f x) result)) | |
() | |
coll))) | |
([f coll & colls] | |
(let [colls (cons coll colls) | |
n (apply min (my-map count colls))] |