Levenshtein distance: Difference between revisions

Add Processing. Based on Java example.
m (→‎{{header|Haskell}}: make the types more general)
(Add Processing. Based on Java example.)
Line 3,426:
rosettacode raisethysword 8
</pre>
 
 
=={{header|Processing}}==
<lang processing>void setup() {
println(distance("kitten", "sitting"));
}
int distance(String a, String b) {
int [] costs = new int [b.length() + 1];
for (int j = 0; j < costs.length; j++)
costs[j] = j;
for (int i = 1; i <= a.length(); i++) {
costs[0] = i;
int nw = i - 1;
for (int j = 1; j <= b.length(); j++) {
int cj = min(1 + min(costs[j], costs[j - 1]), a.charAt(i - 1) == b.charAt(j - 1) ? nw : nw + 1);
nw = costs[j];
costs[j] = cj;
}
}
return costs[b.length()];
}</lang>
 
 
=={{header|Prolog}}==