aboutsummaryrefslogtreecommitdiff
path: root/slides/presentations/basic-math-in-programming/default.pug
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2018-09-24 00:02:40 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2018-09-24 00:02:40 +0200
commiteec70d435d564fea77f2449ab5faeb431043d2cc (patch)
tree14cb3cec9200e2e225471eb44cb35f5ba1aa579a /slides/presentations/basic-math-in-programming/default.pug
parentae31d7b337c64acfdef4ec7697bccb3eba2c9584 (diff)
downloadmitjafelicijan.com-eec70d435d564fea77f2449ab5faeb431043d2cc.tar.gz
content update
Diffstat (limited to 'slides/presentations/basic-math-in-programming/default.pug')
-rw-r--r--slides/presentations/basic-math-in-programming/default.pug47
1 files changed, 46 insertions, 1 deletions
diff --git a/slides/presentations/basic-math-in-programming/default.pug b/slides/presentations/basic-math-in-programming/default.pug
index af5ee90..92b1474 100644
--- a/slides/presentations/basic-math-in-programming/default.pug
+++ b/slides/presentations/basic-math-in-programming/default.pug
@@ -16,12 +16,57 @@ section
16 16
17 ul 17 ul
18 li We search for code example instead of algorithms. 18 li We search for code example instead of algorithms.
19 li We copy and paste and do testing on trial&error principle. 19 li We copy and paste and do testing on trial&amp;error principle.
20 li We don't take enough time to properly understand problem we a re trying to solve. 20 li We don't take enough time to properly understand problem we a re trying to solve.
21 li Brute force solutions we make are usually not optimized 21 li Brute force solutions we make are usually not optimized
22 22
23 23
24section 24section
25 h2 Levenshtein distance
26 p The Levenshtein distance is a string metric for measuring difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word into the other.
27
28 hr
29
30 div.center
31 img(src="levenshtein-distance.svg")
32
33 hr
34
35 pre
36 code.language-python
37 | def levenshtein(seq1, seq2):
38 | oneago = None
39 | thisrow = range(1, len(seq2) + 1) + [0]
40 | for x in xrange(len(seq1)):
41 | twoago, oneago, thisrow = oneago, thisrow, [0] * len(seq2) + [x + 1]
42 | for y in xrange(len(seq2)):
43 | delcost = oneago[y] + 1
44 | addcost = thisrow[y - 1] + 1
45 | subcost = oneago[y - 1] + (seq1[x] != seq2[y])
46 | thisrow[y] = min(delcost, addcost, subcost)
47 | return thisrow[len(seq2) - 1]
48
49
50 hr
51
52 h4 Going further
53 ol
54 li https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance
55 li https://en.wikipedia.org/wiki/Levenshtein_distance
56 li https://rosettacode.org/wiki/Levenshtein_distance
57
58
59
60
61
62
63
64
65
66
67
68
69section
25 h2 Basic linear algebra 70 h2 Basic linear algebra
26 71
27 pre 72 pre