Slide 1

Slide 1 text

Going The Distance @schneems

Slide 2

Slide 2 text

They Call me @Schneems

Slide 3

Slide 3 text

Ruby Schneems

Slide 4

Slide 4 text

Ruby Python

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Code Triage .com

Slide 7

Slide 7 text

Challenge: Comment on an issue

Slide 8

Slide 8 text

Docs Doctor .org

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Top 50 Rails Contrib

Slide 11

Slide 11 text

Cats

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Can you keep Ruby weird?

Slide 14

Slide 14 text

%CP%CP

Slide 15

Slide 15 text

'XGT[QPG%CP%CP

Slide 16

Slide 16 text

Thank You!

Slide 17

Slide 17 text

Algorithms:

Slide 18

Slide 18 text

I went to Georgia Tech for…

Slide 19

Slide 19 text

Mechanical 
 Engineering

Slide 20

Slide 20 text

Self taught Programmer ~8 years

Slide 21

Slide 21 text

CS is boring to me

Slide 22

Slide 22 text

Programming is interesting

Slide 23

Slide 23 text

Building programs that accomplish tasks

Slide 24

Slide 24 text

But…

Slide 25

Slide 25 text

Those CS students are on to something

Slide 26

Slide 26 text

Algorithms

Slide 27

Slide 27 text

Are

Slide 28

Slide 28 text

Beautiful

Slide 29

Slide 29 text

<3

Slide 30

Slide 30 text

Algorithms solve problems

Slide 31

Slide 31 text

Introducting A Problem…

Slide 32

Slide 32 text

Spelling

Slide 33

Slide 33 text

When you are tired, or distracted spelling becomes harder

Slide 34

Slide 34 text

$ git commmit -m first WARNING: You called a Git command named 'commmit', which does not exist. Continuing under the assumption that you meant 'commit' in 0.1 seconds automatically...

Slide 35

Slide 35 text

How does Git know?

Slide 36

Slide 36 text

Introducing:
 Edge Distance

Slide 37

Slide 37 text

The “cost” to change one word to another

Slide 38

Slide 38 text

Less “cost” means less more likely match

Slide 39

Slide 39 text

Cost of? zat => bat

Slide 40

Slide 40 text

Cost of? zat => bat 1

Slide 41

Slide 41 text

Cost of? zzat => bat

Slide 42

Slide 42 text

Cost of? bat 2 zzat =>

Slide 43

Slide 43 text

How do we code it though?

Slide 44

Slide 44 text

My First Attempt

Slide 45

Slide 45 text

def distance(str1, str2) cost = 0 str1.each_char.with_index do |char, index| cost += 1 if str2[index] != char end cost end zat bat =>

Slide 46

Slide 46 text

def distance(str1, str2) cost = 0 str1.each_char.with_index do |char, index| cost += 1 if str2[index] != char end cost end zat bat => Cost = 1

Slide 47

Slide 47 text

Perfect?

Slide 48

Slide 48 text

saturday sunday Cost = ?

Slide 49

Slide 49 text

saturday sunday Cost = 7

Slide 50

Slide 50 text

Wat?

Slide 51

Slide 51 text

Turns out I almost recreated

Slide 52

Slide 52 text

Hamming Distance

Slide 53

Slide 53 text

Hamming AKA: Signal Distance

Slide 54

Slide 54 text

Measures: the errors introduced in a string Hamming

Slide 55

Slide 55 text

Only valid for strings of same length Hamming

Slide 56

Slide 56 text

Good for: Detecting and correcting errors in binary and telecommunications Hamming

Slide 57

Slide 57 text

Bad for: mis- spelled words Hamming

Slide 58

Slide 58 text

Does not include: Insertion
 Deletion Hamming

Slide 59

Slide 59 text

Introducing:
 An Algorithm!

Slide 60

Slide 60 text

Introducing:
 Levenshtein Distance

Slide 61

Slide 61 text

How do we calculate deletion?

Slide 62

Slide 62 text

distance("schneems", "zschneems")

Slide 63

Slide 63 text

distance("schneems", "zschneems") Match! deletion

Slide 64

Slide 64 text

str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] deletion

Slide 65

Slide 65 text

How do we calculate insertion?

Slide 66

Slide 66 text

distance("schneems", "chneems")

Slide 67

Slide 67 text

distance("schneems", "chneems") Match! insertion

Slide 68

Slide 68 text

str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 insertion

Slide 69

Slide 69 text

substitution?

Slide 70

Slide 70 text

distance("zchneems", "schneems") Substitution

Slide 71

Slide 71 text

str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] Substitution

Slide 72

Slide 72 text

How do we calculate Distance?

Slide 73

Slide 73 text

Pretend we have a distance() method

Slide 74

Slide 74 text

Strings of different lengths

Slide 75

Slide 75 text

distance(“”, “foo”) # => 3 distance(“foo”, “”) # => 3

Slide 76

Slide 76 text

return str2.length if str1.empty? return str1.length if str2.empty? Different Lengths

Slide 77

Slide 77 text

Calculate distance between every substring

Slide 78

Slide 78 text

l1 = distance(str1, str2[1..-1]) # deletion l2 = distance(str1[1..-1], str2) # insertion l3 = distance(str1[1..-1], str2[1..-1]) # substitution Calculate costs

Slide 79

Slide 79 text

l1 = distance(str1, str2[1..-1]) # deletion l2 = distance(str1[1..-1], str2) # insertion l3 = distance(str1[1..-1], str2[1..-1]) # substitution cost = 1 + [l1,l2,l3].min Take minimum

Slide 80

Slide 80 text

l1 = distance(str1, str2[1..-1]) # deletion l2 = distance(str1[1..-1], str2) # insertion l3 = distance(str1[1..-1], str2[1..-1]) # substitution cost = 1 + [l1,l2,l3].min Why did we add one?

Slide 81

Slide 81 text

Pick the cheapest operation, then add one

Slide 82

Slide 82 text

What about when characters match?

Slide 83

Slide 83 text

distance(str1[1..-1], str2[1..-1]) if str1[0] == str2[0] Match str1 = “saturday” str2 = “sunday”

Slide 84

Slide 84 text

Our powers combined, we form!

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

`

Slide 87

Slide 87 text

Recursive Levenshtein Distance!

Slide 88

Slide 88 text

def distance(str1, str2) # Different lengths return str2.length if str1.empty? return str1.length if str2.empty? ! return distance(str1[1..-1], str2[1..-1]) if str1[0] == str2[0] # match l1 = distance(str1, str2[1..-1]) # deletion l2 = distance(str1[1..-1], str2) # insertion l3 = distance(str1[1..-1], str2[1..-1]) # substitution return 1 + [l1,l2,l3].min # increment cost end Recursive

Slide 89

Slide 89 text

distance(“saturday”, “sunday”) # => 3 Recursive Levenshtein

Slide 90

Slide 90 text

Much better

Slide 91

Slide 91 text

What does that look like?

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

github.com/ schneems/ going_the_distance

Slide 94

Slide 94 text

Hmm…

Slide 95

Slide 95 text

“Dirty Distance” took 8 comparisons

Slide 96

Slide 96 text

“Recursive” took 1647 comparisons

Slide 97

Slide 97 text

No trophy, no flowers, no flashbulbs, no wine,

Slide 98

Slide 98 text

Ouch

Slide 99

Slide 99 text

Can we do better?

Slide 100

Slide 100 text

If you watch the recursive algorithm closely, you notice repeats

Slide 101

Slide 101 text

Maybe we can store substring distance and use to calculate total distance

Slide 102

Slide 102 text

I want you to join the club

Slide 103

Slide 103 text

A members only club

Slide 104

Slide 104 text

Matrix:
 Levenshtein Distance

Slide 105

Slide 105 text

Matrix:
 Levenshtein Distance

Slide 106

Slide 106 text

“” => “saturday” Cost?

Slide 107

Slide 107 text

+---+---+ | | S | +---+---+ | | 1 | +---+---+ Matrix

Slide 108

Slide 108 text

+---+---+---+ | | S | A | +---+---+---+ | | 1 | 2 | +---+---+---+ Matrix

Slide 109

Slide 109 text

+---+---+---+---+ | | S | A | T | +---+---+---+---+ | | 1 | 2 | 3 | +---+---+---+---+ Matrix

Slide 110

Slide 110 text

+---+---+---+---+---+ | | S | A | T | U | +---+---+---+---+---+ | | 1 | 2 | 3 | 4 | +---+---+---+---+---+ Matrix

Slide 111

Slide 111 text

+---+---+---+---+---+---+ | | S | A | T | U | R | +---+---+---+---+---+---+ | | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ Matrix

Slide 112

Slide 112 text

+---+---+---+---+---+---+---+ | | S | A | T | U | R | D | +---+---+---+---+---+---+---+ | | 1 | 2 | 3 | 4 | 5 | 6 | +---+---+---+---+---+---+---+ Matrix

Slide 113

Slide 113 text

+---+---+---+---+---+---+---+---+ | | S | A | T | U | R | D | A | +---+---+---+---+---+---+---+---+ | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +---+---+---+---+---+---+---+---+ Matrix

Slide 114

Slide 114 text

+---+---+---+---+---+---+---+---+---+ | | S | A | T | U | R | D | A | Y | +---+---+---+---+---+---+---+---+---+ | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+---+---+---+---+---+---+---+---+ Matrix

Slide 115

Slide 115 text

“sunday” => “” Cost?

Slide 116

Slide 116 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ Matrix

Slide 117

Slide 117 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ Matrix

Slide 118

Slide 118 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ | N | 3 | +---+---+ Matrix

Slide 119

Slide 119 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ | N | 3 | +---+---+ | D | 4 | +---+---+ Matrix

Slide 120

Slide 120 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ | N | 3 | +---+---+ | D | 4 | +---+---+ | A | 5 | +---+---+ Matrix

Slide 121

Slide 121 text

+---+---+ | | | +---+---+ | | 0 | +---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ | N | 3 | +---+---+ | D | 4 | +---+---+ | A | 5 | +---+---+ | Y | 6 | +---+---+ Matrix

Slide 122

Slide 122 text

Now, fill in the matrix

Slide 123

Slide 123 text

+---+---+---+---+---+---+---+---+---+---+ | | | S | A | T | U | R | D | A | Y | +---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+---+---+---+---+---+---+---+---+---+ | S | 1 | +---+---+ | U | 2 | +---+---+ | N | 3 | +---+---+ | D | 4 | +---+---+ | A | 5 | +---+---+ | Y | 6 | +---+---+ Matrix

Slide 124

Slide 124 text

Break it down

Slide 125

Slide 125 text

How much does it cost to change “s” into “s”?

Slide 126

Slide 126 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ Match! Cost = 0

Slide 127

Slide 127 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ Insertion! Cost = ?

Slide 128

Slide 128 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ Insertion! Cost = 1

Slide 129

Slide 129 text

How do we calculate insertion programmatically?

Slide 130

Slide 130 text

str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 Insertion!

Slide 131

Slide 131 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1] Insertion!

Slide 132

Slide 132 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ Insertion! str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1]

Slide 133

Slide 133 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ Insertion! str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1]

Slide 134

Slide 134 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ Insertion! str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1]

Slide 135

Slide 135 text

+ cost of change (+1)

Slide 136

Slide 136 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | | +---+---+---+---+ Insertion! str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1] + 1

Slide 137

Slide 137 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ Insertion! Cost = 1 str1 = “schneems” str2 = “chneems” str1[1..-1] == str2 matrix[row_index][column_index - 1] + 1

Slide 138

Slide 138 text

Keep Going

Slide 139

Slide 139 text

+---+---+---+---+---+---+---+---+---+---+ | | | S | A | T | U | R | D | A | Y | +---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+---+---+---+---+---+---+---+---+---+ | S | 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +---+---+---+---+---+---+---+---+---+---+ Insertion(s)

Slide 140

Slide 140 text

Next Char “su” => “s”

Slide 141

Slide 141 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | | +---+---+---+ Action?

Slide 142

Slide 142 text

Change “su” to “s” is a deletion. How do we calculate?

Slide 143

Slide 143 text

Deletion

Slide 144

Slide 144 text

str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] deletion

Slide 145

Slide 145 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | | +---+---+---+ Deletion str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] matrix[row_index - 1][column_index]

Slide 146

Slide 146 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | | +---+---+---+ Deletion str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] matrix[row_index - 1][column_index]

Slide 147

Slide 147 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | | +---+---+---+ Deletion str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] matrix[row_index - 1][column_index]

Slide 148

Slide 148 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | | +---+---+---+ Deletion str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] matrix[row_index - 1][column_index] + 1

Slide 149

Slide 149 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ | U | 2 | 1 | +---+---+---+ Deletion Cost = 1 str1 = “schneems” str2 = “zschneems” str1 == str2[1..-1] matrix[row_index - 1][column_index] + 1

Slide 150

Slide 150 text

- Insertion - Deletion - Substitution

Slide 151

Slide 151 text

- Insertion - Deletion - Substitution

Slide 152

Slide 152 text

Substitution

Slide 153

Slide 153 text

str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] Substitution!

Slide 154

Slide 154 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | | +---+---+---+---+ Substitution str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1]

Slide 155

Slide 155 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | | +---+---+---+---+ Substitution str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1]

Slide 156

Slide 156 text

str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1] +---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | | +---+---+---+---+ Substitution

Slide 157

Slide 157 text

str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1] +---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | | +---+---+---+---+ Substitution

Slide 158

Slide 158 text

str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1] +---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | | +---+---+---+---+ Substitution

Slide 159

Slide 159 text

+---+---+---+---+ | | | S | A | +---+---+---+---+ | | 0 | 1 | 2 | +---+---+---+---+ | S | 1 | 0 | 1 | +---+---+---+---+ | U | 2 | 1 | 1 | +---+---+---+---+ Substitution Cost = 1 str1 = “zchneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1] + 1

Slide 160

Slide 160 text

- Insertion - Deletion - Substitution

Slide 161

Slide 161 text

What about match?

Slide 162

Slide 162 text

+---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+ Match! str1 = “schneems” str2 = “schneems” str1[1..-1] == str2[1..-1] matrix[row_index - 1][column_index- 1]

Slide 163

Slide 163 text

Why?

Slide 164

Slide 164 text

If the current character matches, cost is to change previous character to previous sub string

Slide 165

Slide 165 text

i.e. changing “” to “” +---+---+---+ | | | S | +---+---+---+ | | 0 | 1 | +---+---+---+ | S | 1 | 0 | +---+---+---+

Slide 166

Slide 166 text

Now What?

Slide 167

Slide 167 text

Algorithm str2.each_char.each_with_index do |char1,i| str1.each_char.each_with_index do |char2, j| if char1 == char2 puts [:skip, matrix[i][j]].inspect matrix[i + 1 ][j + 1 ] = matrix[i][j] else actions = { deletion: matrix[i][j + 1] + 1, insert: matrix[i + 1][j] + 1, substitution: matrix[i][j] + 1 } action = actions.sort {|(k,v), (k2, v2)| v <=> v2 }.first puts action.inspect matrix[i + 1 ][j + 1 ] = action.last end each_step.call(matrix) if each_step end end

Slide 168

Slide 168 text

Iterate!

Slide 169

Slide 169 text

No content

Slide 170

Slide 170 text

Final Cost +---+---+---+---+---+---+---+---+---+---+ | | | S | A | T | U | R | D | A | Y | +---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+---+---+---+---+---+---+---+---+---+ | S | 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +---+---+---+---+---+---+---+---+---+---+ | U | 2 | 1 | 1 | 2 | 2 | 3 | 4 | 5 | 6 | +---+---+---+---+---+---+---+---+---+---+ | N | 3 | 2 | 2 | 2 | 3 | 3 | 4 | 5 | 6 | +---+---+---+---+---+---+---+---+---+---+ | D | 4 | 3 | 3 | 3 | 3 | 4 | 3 | 4 | 5 | +---+---+---+---+---+---+---+---+---+---+ | A | 5 | 4 | 3 | 4 | 4 | 4 | 4 | 3 | 4 | +---+---+---+---+---+---+---+---+---+---+ | Y | 6 | 5 | 4 | 4 | 5 | 5 | 5 | 4 | 3 | +---+---+---+---+---+---+---+---+---+---+ 3

Slide 171

Slide 171 text

We can also get cost of sub strings

Slide 172

Slide 172 text

“sun” => “sat”

Slide 173

Slide 173 text

Final Cost +---+---+---+---+---+---+---+---+---+---+ | | | S | A | T | U | R | D | A | Y | +---+---+---+---+---+---+---+---+---+---+ | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+---+---+---+---+---+---+---+---+---+ | S | 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +---+---+---+---+---+---+---+---+---+---+ | U | 2 | 1 | 1 | 2 | 2 | 3 | 4 | 5 | 6 | +---+---+---+---+---+---+---+---+---+---+ | N | 3 | 2 | 2 | 2 | 3 | 3 | 4 | 5 | 6 | +---+---+---+---+---+---+---+---+---+---+ | D | 4 | 3 | 3 | 3 | 3 | 4 | 3 | 4 | 5 | +---+---+---+---+---+---+---+---+---+---+ | A | 5 | 4 | 3 | 4 | 4 | 4 | 4 | 3 | 4 | +---+---+---+---+---+---+---+---+---+---+ | Y | 6 | 5 | 4 | 4 | 5 | 5 | 5 | 4 | 3 | +---+---+---+---+---+---+---+---+---+---+ 2

Slide 174

Slide 174 text

Better than Recursive?

Slide 175

Slide 175 text

As they speed through the finish, the flags go down.

Slide 176

Slide 176 text

48 iterations

Slide 177

Slide 177 text

Wayyyyyy better than 1647

Slide 178

Slide 178 text

bit.ly/ going_the_distance

Slide 179

Slide 179 text

My Problem

Slide 180

Slide 180 text

I am human

Slide 181

Slide 181 text

I get tired

Slide 182

Slide 182 text

Machines don’t understand tired

Slide 183

Slide 183 text

One day I tried typing

Slide 184

Slide 184 text

$ rails generate migration

Slide 185

Slide 185 text

But accidentally typed

Slide 186

Slide 186 text

$ rails generate migratoon

Slide 187

Slide 187 text

ERROR

Slide 188

Slide 188 text

No content

Slide 189

Slide 189 text

Stress is increased when we fail at simple tasks

Slide 190

Slide 190 text

Why? It’s not hard

Slide 191

Slide 191 text

Why can’t my software be more like git?

Slide 192

Slide 192 text

We know what you’re trying to accomplish. Let’s help you out

Slide 193

Slide 193 text

No content

Slide 194

Slide 194 text

When you have ERROR

Slide 195

Slide 195 text

Compare given command to possible commands

Slide 196

Slide 196 text

Recommend smallest distance.

Slide 197

Slide 197 text

Google:

Slide 198

Slide 198 text

Google:

Slide 199

Slide 199 text

Read A lot of words from real books

Slide 200

Slide 200 text

~1+ million words

Slide 201

Slide 201 text

Count Each word

Slide 202

Slide 202 text

Higher count, higher probability

Slide 203

Slide 203 text

Get edit distance between input and dictionary

Slide 204

Slide 204 text

Lower edit, higher probability

Slide 205

Slide 205 text

Show Suggestion

Slide 206

Slide 206 text

No content

Slide 207

Slide 207 text

Cache correct spelling suggestions

Slide 208

Slide 208 text

did_you_mean gem

Slide 209

Slide 209 text

No content

Slide 210

Slide 210 text

More distance measurements

Slide 211

Slide 211 text

Levenshtein Distance

Slide 212

Slide 212 text

Hamming Distance

Slide 213

Slide 213 text

longest common subsequence Distance

Slide 214

Slide 214 text

Manhattan Distance

Slide 215

Slide 215 text

Tree Distance

Slide 216

Slide 216 text

Jaro-Winkler Distance

Slide 217

Slide 217 text

Many Many More

Slide 218

Slide 218 text

Algorithms are Awesome

Slide 219

Slide 219 text

Where to go next?

Slide 220

Slide 220 text

I want to learn more about algorithms?

Slide 221

Slide 221 text

Wikipedia!

Slide 222

Slide 222 text

Rosetta code

Slide 223

Slide 223 text

Give an algorithm talk

Slide 224

Slide 224 text

Everyone suggests a new Algorithm!

Slide 225

Slide 225 text

Algorithms are a way of sharing knowledge

Slide 226

Slide 226 text

Expand your knowledge Explore Algorithms

Slide 227

Slide 227 text

Antepenultimate Slide

Slide 228

Slide 228 text

YAY!

Slide 229

Slide 229 text

Questions @schneems

Slide 230

Slide 230 text

Going The Distance