Skip to content

Commit eea9a6c

Browse files
Add bottle-song (#2384)
* Add `bottle-song` * Apply code review * regenerate tests * update project file * Add lockfile --------- Co-authored-by: Erik Schierboom <[email protected]>
1 parent 445ec38 commit eea9a6c

12 files changed

+675
-0
lines changed

config.json

+9
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,15 @@
13771377
"slug": "beer-song",
13781378
"name": "Beer Song",
13791379
"uuid": "4ae402a7-5345-429a-a6af-e95ec5b95e13",
1380+
"practices": [],
1381+
"prerequisites": [],
1382+
"difficulty": 3,
1383+
"status": "deprecated"
1384+
},
1385+
{
1386+
"slug": "bottle-song",
1387+
"name": "Bottle Song",
1388+
"uuid": "745b56de-ddfd-4e93-908b-1dc935c6f8bb",
13801389
"practices": [
13811390
"switch-statements",
13821391
"string-formatting"

exercises/Exercises.sln

+7
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Satellite", "practice\satel
355355
EndProject
356356
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StateOfTicTacToe", "practice\state-of-tic-tac-toe\StateOfTicTacToe.csproj", "{67E9BAB3-9805-42F1-9298-E9BBB795140E}"
357357
EndProject
358+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BottleSong", "practice\bottle-song\BottleSong.csproj", "{6BD384E6-225E-4F8A-856C-3079957C6E36}"
359+
EndProject
358360
Global
359361
GlobalSection(SolutionConfigurationPlatforms) = preSolution
360362
Debug|Any CPU = Debug|Any CPU
@@ -1057,6 +1059,10 @@ Global
10571059
{67E9BAB3-9805-42F1-9298-E9BBB795140E}.Debug|Any CPU.Build.0 = Debug|Any CPU
10581060
{67E9BAB3-9805-42F1-9298-E9BBB795140E}.Release|Any CPU.ActiveCfg = Release|Any CPU
10591061
{67E9BAB3-9805-42F1-9298-E9BBB795140E}.Release|Any CPU.Build.0 = Release|Any CPU
1062+
{6BD384E6-225E-4F8A-856C-3079957C6E36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1063+
{6BD384E6-225E-4F8A-856C-3079957C6E36}.Debug|Any CPU.Build.0 = Debug|Any CPU
1064+
{6BD384E6-225E-4F8A-856C-3079957C6E36}.Release|Any CPU.ActiveCfg = Release|Any CPU
1065+
{6BD384E6-225E-4F8A-856C-3079957C6E36}.Release|Any CPU.Build.0 = Release|Any CPU
10601066
EndGlobalSection
10611067
GlobalSection(SolutionProperties) = preSolution
10621068
HideSolutionNode = FALSE
@@ -1236,6 +1242,7 @@ Global
12361242
{BEBBD420-075D-46F1-AE51-CC9A05FECE4A} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
12371243
{8E276065-1371-4CFA-BA20-95225EC6AEBC} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
12381244
{67E9BAB3-9805-42F1-9298-E9BBB795140E} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
1245+
{6BD384E6-225E-4F8A-856C-3079957C6E36} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
12391246
EndGlobalSection
12401247
GlobalSection(ExtensibilityGlobals) = postSolution
12411248
SolutionGuid = {AB4EA6C9-5461-4024-BDC7-2AE0C3A85CD1}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Instructions
2+
3+
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.
4+
5+
Note that not all verses are identical.
6+
7+
```text
8+
Ten green bottles hanging on the wall,
9+
Ten green bottles hanging on the wall,
10+
And if one green bottle should accidentally fall,
11+
There'll be nine green bottles hanging on the wall.
12+
13+
Nine green bottles hanging on the wall,
14+
Nine green bottles hanging on the wall,
15+
And if one green bottle should accidentally fall,
16+
There'll be eight green bottles hanging on the wall.
17+
18+
Eight green bottles hanging on the wall,
19+
Eight green bottles hanging on the wall,
20+
And if one green bottle should accidentally fall,
21+
There'll be seven green bottles hanging on the wall.
22+
23+
Seven green bottles hanging on the wall,
24+
Seven green bottles hanging on the wall,
25+
And if one green bottle should accidentally fall,
26+
There'll be six green bottles hanging on the wall.
27+
28+
Six green bottles hanging on the wall,
29+
Six green bottles hanging on the wall,
30+
And if one green bottle should accidentally fall,
31+
There'll be five green bottles hanging on the wall.
32+
33+
Five green bottles hanging on the wall,
34+
Five green bottles hanging on the wall,
35+
And if one green bottle should accidentally fall,
36+
There'll be four green bottles hanging on the wall.
37+
38+
Four green bottles hanging on the wall,
39+
Four green bottles hanging on the wall,
40+
And if one green bottle should accidentally fall,
41+
There'll be three green bottles hanging on the wall.
42+
43+
Three green bottles hanging on the wall,
44+
Three green bottles hanging on the wall,
45+
And if one green bottle should accidentally fall,
46+
There'll be two green bottles hanging on the wall.
47+
48+
Two green bottles hanging on the wall,
49+
Two green bottles hanging on the wall,
50+
And if one green bottle should accidentally fall,
51+
There'll be one green bottle hanging on the wall.
52+
53+
One green bottle hanging on the wall,
54+
One green bottle hanging on the wall,
55+
And if one green bottle should accidentally fall,
56+
There'll be no green bottles hanging on the wall.
57+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
###############################
2+
# Core EditorConfig Options #
3+
###############################
4+
5+
; This file is for unifying the coding style for different editors and IDEs.
6+
; More information at:
7+
; https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
8+
; https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2017
9+
10+
root = true
11+
12+
[*]
13+
indent_style = space
14+
15+
[BottleSong.cs]
16+
indent_size = 4
17+
18+
###############################
19+
# .NET Coding Conventions #
20+
###############################
21+
22+
# Organize usings
23+
dotnet_sort_system_directives_first = true
24+
dotnet_separate_import_directive_groups = true
25+
26+
# this. preferences
27+
dotnet_style_qualification_for_field = false:suggestion
28+
dotnet_style_qualification_for_property = false:suggestion
29+
dotnet_style_qualification_for_method = false:suggestion
30+
dotnet_style_qualification_for_event = false:suggestion
31+
32+
# Language keywords vs BCL types preferences
33+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
34+
dotnet_style_predefined_type_for_member_access = true:suggestion
35+
36+
# Parentheses preferences
37+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
38+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
39+
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
40+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
41+
42+
# Modifier preferences
43+
dotnet_style_require_accessibility_modifiers = always:suggestion
44+
dotnet_style_readonly_field = true:suggestion
45+
46+
# Expression-level preferences
47+
dotnet_style_object_initializer = true:suggestion
48+
dotnet_style_collection_initializer = true:suggestion
49+
dotnet_style_explicit_tuple_names = true:suggestion
50+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
51+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
52+
dotnet_style_prefer_auto_properties = true:suggestion
53+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
54+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
55+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
56+
dotnet_style_coalesce_expression = true:suggestion
57+
dotnet_style_null_propagation = true:suggestion
58+
59+
###############################
60+
# Naming Conventions #
61+
###############################
62+
63+
# Style Definitions
64+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
65+
66+
# Use PascalCase for constant fields
67+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
68+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
69+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
70+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
71+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
72+
dotnet_naming_symbols.constant_fields.required_modifiers = const
73+
74+
###############################
75+
# C# Code Style Rules #
76+
###############################
77+
78+
# var preferences
79+
csharp_style_var_for_built_in_types = true:none
80+
csharp_style_var_when_type_is_apparent = true:none
81+
csharp_style_var_elsewhere = true:none
82+
83+
# Expression-bodied members
84+
csharp_style_expression_bodied_methods = true:suggestion
85+
csharp_style_expression_bodied_constructors = true:suggestion
86+
csharp_style_expression_bodied_operators = true:suggestion
87+
csharp_style_expression_bodied_properties = true:suggestion
88+
csharp_style_expression_bodied_indexers = true:suggestion
89+
csharp_style_expression_bodied_accessors = true:suggestion
90+
91+
# Pattern-matching preferences
92+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
93+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
94+
95+
# Null-checking preferences
96+
csharp_style_throw_expression = true:suggestion
97+
csharp_style_conditional_delegate_call = true:suggestion
98+
99+
# Modifier preferences
100+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
101+
102+
# Expression-level preferences
103+
csharp_prefer_braces = true:none
104+
csharp_prefer_simple_default_expression = true:suggestion
105+
csharp_style_deconstructed_variable_declaration = true:suggestion
106+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
107+
csharp_style_inlined_variable_declaration = true:suggestion
108+
109+
###############################
110+
# C# Formatting Rules #
111+
###############################
112+
113+
# New line preferences
114+
csharp_new_line_before_open_brace = all
115+
csharp_new_line_before_else = true
116+
csharp_new_line_before_catch = true
117+
csharp_new_line_before_finally = true
118+
csharp_new_line_before_members_in_object_initializers = false
119+
csharp_new_line_before_members_in_anonymous_types = false
120+
csharp_new_line_between_query_expression_clauses = true
121+
122+
# Indentation preferences
123+
csharp_indent_case_contents = true
124+
csharp_indent_switch_labels = true
125+
csharp_indent_labels = flush_left
126+
127+
# Space preferences
128+
csharp_space_after_cast = false
129+
csharp_space_after_keywords_in_control_flow_statements = true
130+
csharp_space_between_method_declaration_parameter_list_parentheses = false
131+
csharp_space_between_method_call_parameter_list_parentheses = false
132+
csharp_space_before_colon_in_inheritance_clause = true
133+
csharp_space_after_colon_in_inheritance_clause = true
134+
csharp_space_around_binary_operators = before_and_after
135+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
136+
csharp_space_between_method_call_name_and_opening_parenthesis = false
137+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
138+
139+
# Wrapping preferences
140+
csharp_preserve_single_line_blocks = true
141+
csharp_preserve_single_line_statements = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
public static class BottleSong
6+
{
7+
public static IEnumerable<string> Recite(int startBottles, int takeDown)
8+
=> Enumerable
9+
.Range(startBottles - takeDown + 1, takeDown)
10+
.Reverse()
11+
.Select(Verse)
12+
.SelectMany((v, i) =>
13+
{
14+
if (i == 0)
15+
{
16+
return v;
17+
}
18+
List<string> delimiter = [string.Empty];
19+
return delimiter.Concat(v);
20+
})
21+
.ToList();
22+
23+
private static List<string> Verse(int number)
24+
{
25+
string bottles = number == 1 ? "bottle" : "bottles";
26+
string nextBottles = (number - 1) == 1 ? "bottle" : "bottles";
27+
string currCount = DecimalToOrdinal(number);
28+
string nextCount = DecimalToOrdinal(number - 1);
29+
30+
return [
31+
$"{currCount} green {bottles} hanging on the wall,",
32+
$"{currCount} green {bottles} hanging on the wall,",
33+
"And if one green bottle should accidentally fall,",
34+
$"There'll be {nextCount.ToLowerInvariant()} green {nextBottles} hanging on the wall."
35+
];
36+
}
37+
38+
private static string DecimalToOrdinal(int number)
39+
=> number switch
40+
{
41+
0 => "No",
42+
1 => "One",
43+
2 => "Two",
44+
3 => "Three",
45+
4 => "Four",
46+
5 => "Five",
47+
6 => "Six",
48+
7 => "Seven",
49+
8 => "Eight",
50+
9 => "Nine",
51+
10 => "Ten",
52+
_ => throw new NotImplementedException()
53+
};
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class {{ testClass }}
2+
{
3+
{{- for test in tests }}
4+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
5+
public void {{ test.testMethod }}()
6+
{
7+
string[] expected = [
8+
{{- for line in test.expected }}
9+
{{ line | string.literal }}{{- if !for.last }},{{ end -}}
10+
{{ end }}
11+
];
12+
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.startBottles }}, {{ test.input.takeDown }}));
13+
}
14+
{{ end -}}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"BNAndras",
4+
"ErikSchierboom"
5+
],
6+
"files": {
7+
"solution": [
8+
"BottleSong.cs"
9+
],
10+
"test": [
11+
"BottleSongTests.cs"
12+
],
13+
"example": [
14+
".meta/Example.cs"
15+
]
16+
},
17+
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.",
18+
"source": "Wikipedia",
19+
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles"
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03]
13+
description = "verse -> single verse -> first generic verse"
14+
15+
[0f0aded3-472a-4c64-b842-18d4f1f5f030]
16+
description = "verse -> single verse -> last generic verse"
17+
18+
[f61f3c97-131f-459e-b40a-7428f3ed99d9]
19+
description = "verse -> single verse -> verse with 2 bottles"
20+
21+
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0]
22+
description = "verse -> single verse -> verse with 1 bottle"
23+
24+
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80]
25+
description = "lyrics -> multiple verses -> first two verses"
26+
27+
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db]
28+
description = "lyrics -> multiple verses -> last three verses"
29+
30+
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28]
31+
description = "lyrics -> multiple verses -> all verses"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public static class BottleSong
2+
{
3+
public static string Recite(int startBottles, int takeDown)
4+
{
5+
throw new NotImplementedException("You need to implement this method.");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Using Include="Xunit" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
14+
<PackageReference Include="xunit.v3" Version="1.1.0" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
16+
<PackageReference Include="Exercism.Tests.xunit.v3" Version="0.1.0-beta1" />
17+
</ItemGroup>
18+
</Project>

0 commit comments

Comments
 (0)