Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions solutions/python/bottle-song/1/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Bottle Song
===========

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

Ten_Green_Bottles: list[str] = [
"Ten green bottles hanging on the wall,",
"Ten green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be nine green bottles hanging on the wall.",
"",
"Nine green bottles hanging on the wall,",
"Nine green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be eight green bottles hanging on the wall.",
"",
"Eight green bottles hanging on the wall,",
"Eight green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be seven green bottles hanging on the wall.",
"",
"Seven green bottles hanging on the wall,",
"Seven green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be six green bottles hanging on the wall.",
"",
"Six green bottles hanging on the wall,",
"Six green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be five green bottles hanging on the wall.",
"",
"Five green bottles hanging on the wall,",
"Five green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be four green bottles hanging on the wall.",
"",
"Four green bottles hanging on the wall,",
"Four green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be three green bottles hanging on the wall.",
"",
"Three green bottles hanging on the wall,",
"Three green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be two green bottles hanging on the wall.",
"",
"Two green bottles hanging on the wall,",
"Two green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be one green bottle hanging on the wall.",
"",
"One green bottle hanging on the wall,",
"One green bottle hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be no green bottles hanging on the wall.",
]


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics corresponding to ``take`` consecutive
verses starting from the verse that begins with ``start`` green bottles.

The lyrics are stored as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function computes the
appropriate slice boundaries to return the requested verses in order.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
start: int = -(start * 5)
end: int = len(Ten_Green_Bottles) + start + (take * 5)
return Ten_Green_Bottles[start + 1 : end]
67 changes: 67 additions & 0 deletions solutions/python/bottle-song/2/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Bottle Song
===========

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

NUMBERS: tuple = (
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
)


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics corresponding to ``take`` consecutive
verses starting from the verse that begins with ``start`` green bottles.

The lyrics are stored as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function computes the
appropriate slice boundaries to return the requested verses in order.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
result: list[str] = []
for i in range(start, start - take, -1):
if i == 1:
verse = [
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be no green bottles hanging on the wall.",
]
elif i != start - take + 1:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green {'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
"",
]
else:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green {'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
]
result += verse
return result
68 changes: 68 additions & 0 deletions solutions/python/bottle-song/3/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Bottle Song.

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

NUMBERS: tuple = (
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
)


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics corresponding to ``take`` consecutive
verses starting from the verse that begins with ``start`` green bottles.

The lyrics are stored as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function computes the
appropriate slice boundaries to return the requested verses in order.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
result: list[str] = []
for i in range(start, start - take, -1):
if i == 1:
verse = [
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be no green bottles hanging on the wall.",
]
elif i != start - take + 1:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
"",
]
else:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
]
result += verse
return result
68 changes: 68 additions & 0 deletions solutions/python/bottle-song/4/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Bottle Song.

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

NUMBERS: tuple = (
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
)


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics corresponding to ``take`` consecutive
verses starting from the verse that begins with ``start`` green bottles.

The lyrics are generated as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function generates the
requested verses dynamically based on the song's pattern.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
result: list[str] = []
for i in range(start, start - take, -1):
if i == 1:
verse = [
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
f"{NUMBERS[i - 1]} green bottle hanging on the wall,",
"And if one green bottle should accidentally fall,",
"There'll be no green bottles hanging on the wall.",
]
elif i != start - take + 1:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
"",
]
else:
verse = [
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
f"{NUMBERS[i - 1]} green bottles hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower()} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
]
result += verse
return result
53 changes: 53 additions & 0 deletions solutions/python/bottle-song/5/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Bottle Song.

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

NUMBERS: tuple = (
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
)


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics corresponding to ``take`` consecutive
verses starting from the verse that begins with ``start`` green bottles.

The lyrics are generated as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function generates the
requested verses dynamically based on the song's pattern.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
result: list[str] = []
for i in range(start, start - take, -1):
result += [
f"{NUMBERS[i - 1]} green "
f"{'bottles' if NUMBERS[i - 1] != 'One' else 'bottle'} hanging on the wall,",
f"{NUMBERS[i - 1]} green "
f"{'bottles' if NUMBERS[i - 1] != 'One' else 'bottle'} hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower() if (i - 2) > -1 else 'no'} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
]
if i != start - take + 1:
result.append("")
return result
52 changes: 52 additions & 0 deletions solutions/python/bottle-song/6/bottle_song.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Bottle Song.

Recite verses from the children's song "Ten Green Bottles".

This module exposes the precomputed lyrics and a helper to
extract slices of the song by verse.
"""

NUMBERS: tuple = (
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
)


def recite(start: int, take: int = 1) -> list[str]:
"""
Return a slice of the song lyrics.

The lyrics are generated as a flat list where each verse occupies five lines
(four lyric lines plus a trailing blank line). This function generates the
requested verses dynamically based on the song's pattern.

:param start: The number of green bottles to start from (e.g., 10 for
"Ten green bottles"). Must be between 1 and 10.
:param take: Number of consecutive verses to include starting at ``start``.
Defaults to 1.
:returns: A list of lyric lines forming the requested verses.
"""
result: list[str] = []
for i in range(start, start - take, -1):
result += [
f"{NUMBERS[i - 1]} green "
f"{'bottles' if NUMBERS[i - 1] != 'One' else 'bottle'} hanging on the wall,",
f"{NUMBERS[i - 1]} green "
f"{'bottles' if NUMBERS[i - 1] != 'One' else 'bottle'} hanging on the wall,",
"And if one green bottle should accidentally fall,",
f"There'll be {NUMBERS[i - 2].lower() if (i - 2) > -1 else 'no'} green "
f"{'bottles' if NUMBERS[i - 2] != 'One' else 'bottle'} hanging on"
f" the wall.",
]
if i != start - take + 1:
result.append("")
return result
Loading