mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
26 lines
762 B
C
26 lines
762 B
C
module levenshtein;
|
|
import std::math;
|
|
|
|
// This levenshtein exercises C3 slices.
|
|
fn int levenshtein(String s, String t)
|
|
{
|
|
// if either string is empty, difference is inserting all chars
|
|
// from the other
|
|
if (!s.len) return t.len;
|
|
if (!t.len) return s.len;
|
|
|
|
// if last letters are the same, the difference is whatever is
|
|
// required to edit the rest of the strings
|
|
if (s[^1] == t[^1]) return levenshtein(s[0..^2], t[0..^2]);
|
|
|
|
// else try:
|
|
// changing last letter of s to that of t; or
|
|
// remove last letter of s; or
|
|
// remove last letter of t,
|
|
// any of which is 1 edit plus editing the rest of the strings
|
|
int a = levenshtein(s[0..^2], t[0..^2]);
|
|
int b = levenshtein(s, t[0..^2]);
|
|
int c = levenshtein(s[0..^2], t);
|
|
|
|
return min(min(a, b), c) + 1;
|
|
} |