From cf4c0252465a08262b654ce45e19b296c9009553 Mon Sep 17 00:00:00 2001 From: Jan Kjetil Myklebust Date: Tue, 23 Dec 2025 08:49:58 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 49 ++++++++++++++++++++++++++++ TwelveDays.sln | 25 +++++++++++++++ TwelveDays/Data.cs | 8 +++++ TwelveDays/Helpers.cs | 37 +++++++++++++++++++++ TwelveDays/Program.cs | 28 ++++++++++++++++ TwelveDays/TwelveDays.csproj | 16 ++++++++++ TwelveDays/data.json | 62 ++++++++++++++++++++++++++++++++++++ 7 files changed, 225 insertions(+) create mode 100644 .gitignore create mode 100644 TwelveDays.sln create mode 100644 TwelveDays/Data.cs create mode 100644 TwelveDays/Helpers.cs create mode 100644 TwelveDays/Program.cs create mode 100644 TwelveDays/TwelveDays.csproj create mode 100644 TwelveDays/data.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b81ef2 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/TwelveDays.sln b/TwelveDays.sln new file mode 100644 index 0000000..d620213 --- /dev/null +++ b/TwelveDays.sln @@ -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 diff --git a/TwelveDays/Data.cs b/TwelveDays/Data.cs new file mode 100644 index 0000000..2f504da --- /dev/null +++ b/TwelveDays/Data.cs @@ -0,0 +1,8 @@ +namespace TwelveDays; + +public record Data +{ + public int Day { get; init; } + public string Gift { get; init; } + public string Context { get; init; } +} diff --git a/TwelveDays/Helpers.cs b/TwelveDays/Helpers.cs new file mode 100644 index 0000000..eebc0c1 --- /dev/null +++ b/TwelveDays/Helpers.cs @@ -0,0 +1,37 @@ +namespace TwelveDays; + +internal class Helpers +{ + internal static List Numerals => new List + { + "a", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve" + }; + + internal static List Ordinals => new List + { + "first", + "second", + "third", + "fourth", + "fifth", + "sixth", + "seventh", + "eighth", + "ninth", + "tenth", + "eleventh", + "twelfth" + }; +} + diff --git a/TwelveDays/Program.cs b/TwelveDays/Program.cs new file mode 100644 index 0000000..c0e3c4e --- /dev/null +++ b/TwelveDays/Program.cs @@ -0,0 +1,28 @@ +using System.Text.Json; +using TwelveDays; + +string fileName = "data.json"; +string jsonString = File.ReadAllText(fileName); +List data = JsonSerializer.Deserialize>(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(); diff --git a/TwelveDays/TwelveDays.csproj b/TwelveDays/TwelveDays.csproj new file mode 100644 index 0000000..bc5c1e0 --- /dev/null +++ b/TwelveDays/TwelveDays.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + enable + + + + + Always + + + + diff --git a/TwelveDays/data.json b/TwelveDays/data.json new file mode 100644 index 0000000..5f2ddd3 --- /dev/null +++ b/TwelveDays/data.json @@ -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" + } +]