Skip to content

Instantly share code, notes, and snippets.

@automactic
automactic / Levenshtein.swift
Created January 17, 2018 22:13
Levenshtein distance in swift 4
class Levenshtein {
private(set) var cache = [Set<String.SubSequence>: Int]()
func calculateDistance(a: String.SubSequence, b: String.SubSequence) -> Int {
let key = Set([a, b])
if let distance = cache[key] {
return distance
} else {
let distance: Int = {
if a.count == 0 || b.count == 0 {
@VivienGiraud
VivienGiraud / Swift 3 - Dijkstra.swift
Created October 27, 2016 09:39 — forked from pocketkk/Swift - Dijkstra.swift
Swift 3 - Shortest Path Algorithm (Compiled from: http://waynewbishop.com/swift/graphs/dijkstra/)
import UIKit
public class Vertex {
var key: String?
var neighbors: Array<Edge>
init() {
self.neighbors = Array<Edge>()
}
}