Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnOddDoorKnight committed Aug 21, 2022
1 parent f6d3a19 commit a36305e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Gold Splitter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>GoldSplitter</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Gold Splitter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gold Splitter", "Gold Splitter.csproj", "{407290BD-8743-46B1-902B-45AB61C55661}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{407290BD-8743-46B1-902B-45AB61C55661}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{407290BD-8743-46B1-902B-45AB61C55661}.Debug|Any CPU.Build.0 = Debug|Any CPU
{407290BD-8743-46B1-902B-45AB61C55661}.Release|Any CPU.ActiveCfg = Release|Any CPU
{407290BD-8743-46B1-902B-45AB61C55661}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DDD05195-4059-4D20-B784-22830C1B8BC5}
EndGlobalSection
EndGlobal
71 changes: 71 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;

namespace GoldSplitter;
using System;

internal static class Program
{
public static NamedAction[] actions =
{
new ("Split", package =>
{
Console.WriteLine("Split with how many?");
int people = int.Parse(Console.ReadLine() ?? "0");
Console.WriteLine(package.Split(people));
}),
new ("To All Copper", package =>
{
Console.WriteLine(package.ToAllCopper().Copper);
})
};
static void Main()
{
GoldPackage gold = GoldPackage.HumanInput();
Console.WriteLine("Choose an action:");
for (int i = 0; i < actions.Length; i++)
Console.WriteLine($"{i + 1}. {actions[i].Name}");
actions[int.Parse(Console.ReadLine() ?? "0") - 1].Action.Invoke(gold);
Console.ReadLine();
}
}
public record NamedAction(string Name, Action<GoldPackage> Action);
public record GoldPackage(int Platinum, int Gold, int Silver, int Copper)
{
public const int copperRepresentative = 1, silverRepresentative = 10, goldRepresentative = 100, platinumRepresentative = 1000;
public static explicit operator int(GoldPackage package)
=> package.ToAllCopper().Copper;
public static GoldPackage HumanInput()
{
Console.Write("Platinum: ");
int plat = int.Parse(Console.ReadLine() ?? "0");
Console.Write("Gold: ");
int gold = int.Parse(Console.ReadLine() ?? "0");
Console.Write("Silver: ");
int silver = int.Parse(Console.ReadLine() ?? "0");
Console.Write("Copper: ");
int copper = int.Parse(Console.ReadLine() ?? "0");
return new GoldPackage(plat, gold, silver, copper);
}

public GoldPackage Split(int people)
{
int copper = ToAllCopper().Copper;
copper /= people;
return new GoldPackage(0, 0, 0, copper).DisperseToAppropriateCoinValues();
}
public GoldPackage ToAllCopper() => new(0, 0, 0, (Copper * copperRepresentative)
+ (Silver * silverRepresentative) + (Gold * goldRepresentative)
+ (Platinum * platinumRepresentative));
public GoldPackage DisperseToAppropriateCoinValues()
{
int copperTotal = ToAllCopper().Copper;
int platinumOut = copperTotal / platinumRepresentative;
copperTotal -= platinumOut * platinumRepresentative;
int goldOut = copperTotal / goldRepresentative;
copperTotal -= goldOut * goldRepresentative;
int silverOut = copperTotal / silverRepresentative;
copperTotal -= silverOut * silverRepresentative;
int copperOut = copperTotal;
return new GoldPackage(platinumOut, goldOut, silverOut, copperOut);
}
}

0 comments on commit a36305e

Please sign in to comment.