Initial commit.

This commit is contained in:
Jan Kjetil Myklebust 2025-12-23 08:49:58 +01:00
commit cf4c025246
No known key found for this signature in database
GPG key ID: 849CF7CCD7320509
7 changed files with 225 additions and 0 deletions

49
.gitignore vendored Normal file
View file

@ -0,0 +1,49 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
# Visual Studio Code
.vscode/*
!.vscode/settings.json
# Rider
.idea/
# Visual Studio
.vs/
# Fleet
.fleet/
# Code Rush
.cr/
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn
# Node.js build artifacts
node_modules/
package-lock.json
package.json

25
TwelveDays.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwelveDays", "TwelveDays\TwelveDays.csproj", "{7B73BA15-6348-493E-A70E-738F1D53D436}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B73BA15-6348-493E-A70E-738F1D53D436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B73BA15-6348-493E-A70E-738F1D53D436}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B73BA15-6348-493E-A70E-738F1D53D436}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B73BA15-6348-493E-A70E-738F1D53D436}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {050C6306-C26E-4D49-8150-C37A010180A7}
EndGlobalSection
EndGlobal

8
TwelveDays/Data.cs Normal file
View file

@ -0,0 +1,8 @@
namespace TwelveDays;
public record Data
{
public int Day { get; init; }
public string Gift { get; init; }
public string Context { get; init; }
}

37
TwelveDays/Helpers.cs Normal file
View file

@ -0,0 +1,37 @@
namespace TwelveDays;
internal class Helpers
{
internal static List<string> Numerals => new List<string>
{
"a",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve"
};
internal static List<string> Ordinals => new List<string>
{
"first",
"second",
"third",
"fourth",
"fifth",
"sixth",
"seventh",
"eighth",
"ninth",
"tenth",
"eleventh",
"twelfth"
};
}

28
TwelveDays/Program.cs Normal file
View file

@ -0,0 +1,28 @@
using System.Text.Json;
using TwelveDays;
string fileName = "data.json";
string jsonString = File.ReadAllText(fileName);
List<Data> data = JsonSerializer.Deserialize<List<Data>>(jsonString)!;
var giftLines = data
.Select(d => $"{Helpers.Numerals[d.Day - 1]} {d.Gift} {d.Context}".Trim());
foreach(int day in Enumerable.Range(1, giftLines.Count()))
{
Console.WriteLine($"On the {Helpers.Ordinals[day - 1]} day of Christmas my true love gave to me:");
foreach (var line in giftLines.Take(day).Reverse())
{
if (day > 1 && line == giftLines.First())
Console.Write("and ");
if(day == 5)
Console.WriteLine(line.ToUpper());
else
Console.WriteLine(line);
}
Console.WriteLine();
}
Console.WriteLine("Press any key to exit…");
Console.Read();

View file

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Update="data.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

62
TwelveDays/data.json Normal file
View file

@ -0,0 +1,62 @@
[
{
"Day": 1,
"Gift": "partridge",
"Context": "in a Pear Tree"
},
{
"Day": 2,
"Gift": "turtle doves",
"Context": ""
},
{
"Day": 3,
"Gift": "French hens",
"Context": ""
},
{
"Day": 4,
"Gift": "calling birds",
"Context": ""
},
{
"Day": 5,
"Gift": "gold rings",
"Context": ""
},
{
"Day": 6,
"Gift": "geese",
"Context": "a-laying"
},
{
"Day": 7,
"Gift": "swans",
"Context": "a-swimming"
},
{
"Day": 8,
"Gift": "maids",
"Context": "a-milking"
},
{
"Day": 9,
"Gift": "ladies",
"Context": "dancing"
},
{
"Day": 10,
"Gift": "lords",
"Context": "a-leaping"
},
{
"Day": 11,
"Gift": "pipers",
"Context": "piping"
},
{
"Day": 12,
"Gift": "drummers",
"Context": "drumming"
}
]