From 176161dbee3aa81efe959abd097d2e0eb11ac070 Mon Sep 17 00:00:00 2001 From: moudrick Date: Thu, 30 Jan 2020 11:46:25 +0200 Subject: [PATCH] making 10.1 prettier, fixing [#191 main issue - Input demo array is not sorted](https://github.com/careercup/CtCI-6th-Edition/issues/191) --- Ch 10. Sorting and Searching/Q10 01 Sorted Merge.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Ch 10. Sorting and Searching/Q10 01 Sorted Merge.fs b/Ch 10. Sorting and Searching/Q10 01 Sorted Merge.fs index 812ee0c..04242ef 100644 --- a/Ch 10. Sorting and Searching/Q10 01 Sorted Merge.fs +++ b/Ch 10. Sorting and Searching/Q10 01 Sorted Merge.fs @@ -33,9 +33,9 @@ module Sln = let (current, newIndices) = let currentB = b |> Array.get <| indexB let currentA = lazy (a |> Array.get <| indexA) - match (indexA >= 0) && (currentA.Force() > currentB) with // (* end of A is bigger than end of B *) - | true -> (currentA.Value, (indexMerged - 1, indexA - 1, indexB )) - | _ -> (currentB , (indexMerged - 1, indexA , indexB - 1)) + if (indexA >= 0) && (currentA.Force() > currentB) (* end of A is bigger than end of B *) + then (currentA.Value, (indexMerged - 1, indexA - 1, indexB )) + else (currentB , (indexMerged - 1, indexA , indexB - 1)) a |> Array.set <| indexMerged <| current // copy element mergeAtIndices a b newIndices // move indices @@ -50,11 +50,11 @@ type Question() = override this.DemoRun() = let a = [| 2; 3; 4; 5; 6; 8; 10; 100; 0; 0; 0; 0; 0; 0 |] - let b = [| 1; 4; 7; 6; 7; 7 |]; + let b = [| 1; 4; 6; 7; 7; 7 |]; Sln.merge a b 8 6 printfn "%A" a let a1 = [| 2; 3; 4; 5; 6; 8; 10; 100; 0; 0; 0; 0; 0; 0 |] - let b1 = [| 1; 4; 7; 6; 7; 7 |]; + let b1 = [| 1; 4; 6; 7; 7; 7 |]; Sln.NoMutable.merge a1 b1 8 6 printfn "%A" a1