9
9
namespace Algorithms.Strings
10
10
11
11
module MinCostStringConversion =
12
-
12
+
13
13
[<RequireQualifiedAccess>]
14
14
type Operation =
15
15
| Copy of char
16
16
| Replace of Source : char * Target : char
17
17
| Delete of char
18
18
| Insert of char
19
-
19
+
20
20
let computeTransformTables
21
21
(
22
22
source : string ,
@@ -26,17 +26,17 @@ module MinCostStringConversion =
26
26
deleteCost : int ,
27
27
insertCost : int
28
28
): array < array < int >> * array < array < Operation >> =
29
-
29
+
30
30
let costs =
31
31
Array.init ( source.Length + 1 ) ( fun _ -> Array.init ( destination.Length + 1 ) ( fun _ -> None))
32
-
32
+
33
33
let ops =
34
34
Array.init ( source.Length + 1 ) ( fun _ -> Array.init ( destination.Length + 1 ) ( fun _ -> None))
35
-
35
+
36
36
costs.[ 0 ].[ 0 ] <- Some 0
37
- ops.[ 0 ].[ 0 ] <- Some ( Operation.Copy 'a' ) // There is no operation to perform, assigning dummy operation to satisfy compiler
38
-
39
-
37
+ ops.[ 0 ].[ 0 ] <- Some ( Operation.Copy 'a' ) // There is no operation to perform, assigning dummy operation to satisfy compiler
38
+
39
+
40
40
for i = 1 to source.Length do
41
41
costs.[ i].[ 0 ] <- Some ( i * deleteCost)
42
42
ops.[ i].[ 0 ] <- Some ( Operation.Delete source.[ i - 1 ])
@@ -73,11 +73,11 @@ module MinCostStringConversion =
73
73
| Operation.Replace _
74
74
| Operation.Copy _ ->
75
75
let seq = assembleTransformation ( ops, i - 1 , j - 1 )
76
- Array.append seq [| ops[ i][ j] |]
76
+ Array.append seq [| ops[ i][ j] |]
77
77
| Operation.Delete _ ->
78
78
let seq = assembleTransformation ( ops, i - 1 , j)
79
- Array.append seq [| ops[ i][ j] |]
79
+ Array.append seq [| ops[ i][ j] |]
80
80
| Operation.Insert _ ->
81
81
let seq = assembleTransformation ( ops, i , j - 1 )
82
- Array.append seq [| ops[ i][ j] |]
83
-
82
+ Array.append seq [| ops[ i][ j] |]
83
+
0 commit comments