Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #1 from m1ker1n/undone" (#2)"
Browse files Browse the repository at this point in the history
This reverts commit d5623e4.
  • Loading branch information
m1ker1n committed Feb 6, 2022
1 parent d5623e4 commit b026673
Show file tree
Hide file tree
Showing 136 changed files with 166 additions and 1,565 deletions.
Binary file not shown.
Binary file added Best travel/.vs/Best travel/v16/.suo
Binary file not shown.
12 changes: 6 additions & 6 deletions Rome2Integer/Rome2Integer.sln → Best travel/Best travel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rome2Integer", "Rome2Integer\Rome2Integer.csproj", "{B5FAD71A-967B-4D01-B47E-7F0DA85E249B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Best travel", "Best travel\Best travel.csproj", "{EEA8AB04-2FCC-4218-8BBF-9BB042B00FCD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B5FAD71A-967B-4D01-B47E-7F0DA85E249B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5FAD71A-967B-4D01-B47E-7F0DA85E249B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5FAD71A-967B-4D01-B47E-7F0DA85E249B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5FAD71A-967B-4D01-B47E-7F0DA85E249B}.Release|Any CPU.Build.0 = Release|Any CPU
{EEA8AB04-2FCC-4218-8BBF-9BB042B00FCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEA8AB04-2FCC-4218-8BBF-9BB042B00FCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEA8AB04-2FCC-4218-8BBF-9BB042B00FCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEA8AB04-2FCC-4218-8BBF-9BB042B00FCD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CCFE7CAF-4087-49C8-B195-7A7BB6BB0E5E}
SolutionGuid = {AF66E3A0-4C8D-40AB-A5FD-587691F42B38}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Best_travel</RootNamespace>
</PropertyGroup>

</Project>
91 changes: 91 additions & 0 deletions Best travel/Best travel/Program.cs
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}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"Rome2Integer/1.0.0": {
"Best travel/1.0.0": {
"runtime": {
"Rome2Integer.dll": {}
"Best travel.dll": {}
}
}
}
},
"libraries": {
"Rome2Integer/1.0.0": {
"Best travel/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj": {}
"C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj": {}
},
"projects": {
"C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj": {
"C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj",
"projectName": "Rome2Integer",
"projectPath": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj",
"projectUniqueName": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj",
"projectName": "Best travel",
"projectPath": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj",
"packagesPath": "C:\\Users\\WHOAMI\\.nuget\\packages\\",
"outputPath": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\obj\\",
"outputPath": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Rome2Integer")]
[assembly: System.Reflection.AssemblyCompanyAttribute("Best travel")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Rome2Integer")]
[assembly: System.Reflection.AssemblyTitleAttribute("Rome2Integer")]
[assembly: System.Reflection.AssemblyProductAttribute("Best travel")]
[assembly: System.Reflection.AssemblyTitleAttribute("Best travel")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Создано классом WriteCodeFragment MSBuild.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1f04ff09123fa0320a23a9d321e58de627424647
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a67b840a89dd883154a555fe21a811828db0e0c0
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e8f18416515c1ef7a54ef919eb3429a9eb47335a
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj",
"projectName": "Rome2Integer",
"projectPath": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\Rome2Integer.csproj",
"projectUniqueName": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj",
"projectName": "Best travel",
"projectPath": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\Best travel.csproj",
"packagesPath": "C:\\Users\\WHOAMI\\.nuget\\packages\\",
"outputPath": "C:\\Users\\WHOAMI\\Desktop\\Kata\\Rome2Integer\\Rome2Integer\\obj\\",
"outputPath": "C:\\Users\\WHOAMI\\Desktop\\Codewars\\Best travel\\Best travel\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
Expand Down
8 changes: 8 additions & 0 deletions Best travel/Best travel/obj/project.nuget.cache
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": []
}
28 changes: 28 additions & 0 deletions Best travel/README.md
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 not shown.
Binary file not shown.
25 changes: 0 additions & 25 deletions Decode the Morse code/Decode the Morse code.sln

This file was deleted.

This file was deleted.

47 changes: 0 additions & 47 deletions Decode the Morse code/Decode the Morse code/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Loading

0 comments on commit b026673

Please sign in to comment.