-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit d5623e4.
- Loading branch information
Showing
136 changed files
with
166 additions
and
1,565 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+59.7 KB
... Parentheses/DesignTimeBuild/.dtbcache.v2 → .../Best travel/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Best_travel | ||
{ | ||
public static class SumOfK | ||
{ | ||
class Town | ||
{ | ||
Town previousTown; | ||
List<Town> availableTownsToVisit; | ||
int townsLeftToVisit; | ||
|
||
public int? maxAvailableDistance { get; private set; } = null; | ||
int distanceCovered; | ||
static int maxPossibleDistance; | ||
|
||
private Town(Town previousTown, int townsLeftToVisit, int distanceCovered) | ||
{ | ||
this.previousTown = previousTown; | ||
this.townsLeftToVisit = townsLeftToVisit; | ||
this.distanceCovered = distanceCovered; | ||
availableTownsToVisit = new List<Town>(); | ||
} | ||
|
||
public Town(Town previousTown, List<int> distancesToAvailableTowns, int townsLeftToVisit, int distanceCovered, int maxDistanceToCover) | ||
: this(previousTown, townsLeftToVisit, distanceCovered) | ||
{ | ||
Town.maxPossibleDistance = maxDistanceToCover; | ||
AddAvailableTowns(distancesToAvailableTowns); | ||
} | ||
|
||
void AddAvailableTowns(List<int> distancesToAvailableTowns) | ||
{ | ||
if (townsLeftToVisit == 0) | ||
{ | ||
EvaluateMaxDistanceCovered(); | ||
return; | ||
} | ||
|
||
int index = 1; | ||
foreach(var item in distancesToAvailableTowns) | ||
{ | ||
Town available = new Town(this, townsLeftToVisit - 1, distanceCovered + item); | ||
availableTownsToVisit.Add(available); | ||
available.AddAvailableTowns(distancesToAvailableTowns.GetRange(index, distancesToAvailableTowns.Count - index)); | ||
index++; | ||
} | ||
|
||
EvaluateMaxDistanceCovered(); | ||
} | ||
|
||
void EvaluateMaxDistanceCovered() | ||
{ | ||
if (distanceCovered > Town.maxPossibleDistance) return; | ||
|
||
if (availableTownsToVisit.Count == 0) | ||
{ | ||
if (townsLeftToVisit == 0) maxAvailableDistance = distanceCovered; | ||
return; | ||
} | ||
|
||
foreach(var item in availableTownsToVisit) | ||
{ | ||
if (item.maxAvailableDistance == null) continue; | ||
|
||
maxAvailableDistance = (maxAvailableDistance > item.maxAvailableDistance) ? maxAvailableDistance : item.maxAvailableDistance; | ||
} | ||
} | ||
} | ||
|
||
//return null if no ways to get pathway < t and k | ||
public static int? chooseBestSum(int t, int k, List<int> ls) | ||
{ | ||
Town town = new Town(null, ls, k, 0, t); | ||
return town.maxAvailableDistance; | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
List<int> ts = new List<int> { 91, 74, 73, 85, 73, 81, 87 }; | ||
int? n = SumOfK.chooseBestSum(230, 3, ts); | ||
int? answer = 228; | ||
Console.WriteLine($"Expect: {answer}; What you get: {n}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file renamed
BIN
+171 KB
.../bin/Debug/netcoreapp3.1/Rome2Integer.exe → ...l/bin/Debug/netcoreapp3.1/Best travel.exe
Binary file not shown.
Binary file renamed
BIN
+9.58 KB
...Debug/netcoreapp3.1/Primes in numbers.pdb → ...l/bin/Debug/netcoreapp3.1/Best travel.pdb
Binary file not shown.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
...obj/Rome2Integer.csproj.nuget.dgspec.json → .../obj/Best travel.csproj.nuget.dgspec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Best travel/Best travel/obj/Debug/netcoreapp3.1/Best travel.AssemblyInfoInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1f04ff09123fa0320a23a9d321e58de627424647 |
Binary file renamed
BIN
+273 Bytes
...app3.1/Decode the Morse code.assets.cache → ...ug/netcoreapp3.1/Best travel.assets.cache
Binary file not shown.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
Best travel/Best travel/obj/Debug/netcoreapp3.1/Best travel.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a67b840a89dd883154a555fe21a811828db0e0c0 |
13 changes: 13 additions & 0 deletions
13
Best travel/Best travel/obj/Debug/netcoreapp3.1/Best travel.csproj.FileListAbsolute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.exe | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.deps.json | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.runtimeconfig.json | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.runtimeconfig.dev.json | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.dll | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\bin\Debug\netcoreapp3.1\Best travel.pdb | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.csproj.AssemblyReference.cache | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.AssemblyInfoInputs.cache | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.AssemblyInfo.cs | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.csproj.CoreCompileInputs.cache | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.dll | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.pdb | ||
C:\Users\WHOAMI\Desktop\Codewars\Best travel\Best travel\obj\Debug\netcoreapp3.1\Best travel.genruntimeconfig.cache |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
Best travel/Best travel/obj/Debug/netcoreapp3.1/Best travel.genruntimeconfig.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e8f18416515c1ef7a54ef919eb3429a9eb47335a |
Binary file renamed
BIN
+9.58 KB
...Debug/netcoreapp3.1/Primes in numbers.pdb → ...l/obj/Debug/netcoreapp3.1/Best travel.pdb
Binary file not shown.
Binary file renamed
BIN
+171 KB
...teger/obj/Debug/netcoreapp3.1/apphost.exe → ...ravel/obj/Debug/netcoreapp3.1/apphost.exe
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"version": 2, | ||
"dgSpecHash": "s0N+DyCZIL2ZZ06fyqzj3XHFQBCCDobdo40PC7o0BzGtQquEZlpvr1LcXPJdwGhixqmjVxc8+lP9JiTJYkFPUQ==", | ||
"success": true, | ||
"projectFilePath": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj", | ||
"expectedPackageFiles": [], | ||
"logs": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Link: https://www.codewars.com/kata/55e7280b40e1c4a06d0000aa/train/csharp | ||
|
||
Task: | ||
John and Mary want to travel between a few towns A, B, C ... Mary has on a sheet of paper a list of distances between these towns. ls = [50, 55, 57, 58, 60]. John is tired of driving and he says to Mary that he doesn't want to drive more than t = 174 miles and he will visit only 3 towns. | ||
|
||
Which distances, hence which towns, they will choose so that the sum of the distances is the biggest possible to please Mary and John? | ||
|
||
Example: | ||
With list ls and 3 towns to visit they can make a choice between: [50,55,57],[50,55,58],[50,55,60],[50,57,58],[50,57,60],[50,58,60],[55,57,58],[55,57,60],[55,58,60],[57,58,60]. | ||
|
||
The sums of distances are then: 162, 163, 165, 165, 167, 168, 170, 172, 173, 175. | ||
|
||
The biggest possible sum taking a limit of 174 into account is then 173 and the distances of the 3 corresponding towns is [55, 58, 60]. | ||
|
||
The function chooseBestSum (or choose_best_sum or ... depending on the language) will take as parameters t (maximum sum of distances, integer >= 0), k (number of towns to visit, k >= 1) and ls (list of distances, all distances are positive or zero integers and this list has at least one element). The function returns the "best" sum ie the biggest possible sum of k distances less than or equal to the given limit t, if that sum exists, or otherwise nil, null, None, Nothing, depending on the language. | ||
|
||
With C, C++, Dart, Fortran, F#, Go, Julia, Kotlin, Nim, OCaml, Pascal, Perl, PowerShell, Reason, Rust, Scala, Shell, Swift return -1. | ||
|
||
Examples: | ||
ts = [50, 55, 56, 57, 58] choose_best_sum(163, 3, ts) -> 163 | ||
|
||
xs = [50] choose_best_sum(163, 3, xs) -> nil (or null or ... or -1 (C++, C, Rust, Swift, Go, ...) | ||
|
||
ys = [91, 74, 73, 85, 73, 81, 87] choose_best_sum(230, 3, ys) -> 228 | ||
|
||
Notes: | ||
try not to modify the input list of distances ls | ||
in some languages this "list" is in fact a string (see the Sample Tests). |
Binary file removed
BIN
-59.8 KB
Decode the Morse code/.vs/Decode the Morse code/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
Decode the Morse code/Decode the Morse code/Decode the Morse code.csproj
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
... code/Decode the Morse code/obj/Debug/netcoreapp3.1/Decode the Morse code.AssemblyInfo.cs
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ode the Morse code/obj/Debug/netcoreapp3.1/Decode the Morse code.AssemblyInfoInputs.cache
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-86.3 KB
...e Morse code/obj/Debug/netcoreapp3.1/Decode the Morse code.csproj.AssemblyReference.cache
Binary file not shown.
Oops, something went wrong.