All SolutionsAll Solutions
🎆
Happy New Year
Week 1, 2026
JS - Simple Loops | program52 | JavaScript Solutions
//messy & unoptimised...but working
function drawFireworks(size) {
var half = Math.ceil(size / 2)
var out = ""
line = ""
for (var offset = 1; offset <= size; offset++) {
if (offset < half) {
line = " ".repeat(offset - 1) + "\\" + " ".repeat(half - offset - 1) + "|" + " ".repeat(half - offset - 1) + "/"
} else if (offset === half) {
line = "-".repeat(size)
} else {
line = " ".repeat(size - offset) + "/" + " ".repeat(half - (size - offset) - 2) + "|" + " ".repeat(half - (size - offset) - 2) + "\\"
}
out = out + line + "\n"
}
console.log(out)
}
drawFireworks(99)
Python Solution | BMC | Python Solutions
def firework(size):
store = []
b = '\\'
f = '|'
r = '/'
space = (size-3)//2
for i in range(size//2):
store.append(f"{" "*i}{b}{" "*space}{f}{" "*space}{r}{" "*i}")
space -= 1
for s in store: print(s)
print("-"*size)
store = store[::-1]
for s in store:
print(s[::-1])
firework(99)
Simple Python iterative approach | rud | Python Solutions
def fireworks(size: int) -> None:
# Initializing
size = size if size % 2 != 0 else size + 1
half_height: int = size // 2
lines: list[str] = []
# Drawing the top layer
for row_index in range(half_height):
outer_padding: str = " " * row_index
inner_gap: str = " " * (half_height - 1 - row_index)
lines.append(f"{outer_padding}\\{inner_gap}|{inner_gap}/")
# Drawing the middle layer
lines.append("-" * size)
# Drawing the bottom layer (ez copy paste)
for row_index in range(half_height - 1, -1, -1):
outer_padding: str = " " * row_index
inner_gap: str = " " * (half_height - 1 - row_index)
lines.append(f"{outer_padding}/{inner_gap}|{inner_gap}\\")
print("\n".join(lines))
Python Logical Approach | Alexevi | Python Solutions
def fireworks(n: int) -> None:
l = (n-1)//2
for i in range(l):
a = l-i-1
print(' '*i + '\\' + ' '*a + '|' + ' '*a + '/')
print('-'*n)
for j in range(l):
i = l-j-1
a = l-i-1
print(' '*i + '/' + ' '*a + '|' + ' '*a + '\\')
Odin: Line by line generation | greenya | Odin Solutions
// This code is in Odin programming language
// (which is not in the list when submitting form)
package main
import "core:fmt"
import "core:strings"
main :: proc () {
for i:=1; i<=99; i+=2 {
fireworks(i)
}
}
fireworks :: proc (size: int) {
fmt.println(#procedure, size)
assert(size>0 && size%2==1, "Expected `size` to be positive odd number")
context.allocator = context.temp_allocator
rep :: strings.repeat
// top part
for s:=size; s>=3; s-=2 {
fmt.print(rep(" ", (size-s)/2))
fmt.print("\\")
fmt.print(rep(" ", (s-3)/2))
fmt.print("|")
fmt.print(rep(" ", (s-3)/2))
fmt.print("/")
fmt.println()
}
// middle part
fmt.println(rep("-", size))
// bottom part
for s:=3; s<=size; s+=2 {
fmt.print(rep(" ", (size-s)/2))
fmt.print("/")
fmt.print(rep(" ", (s-3)/2))
fmt.print("|")
fmt.print(rep(" ", (s-3)/2))
fmt.print("\\")
fmt.println()
}
}
python | saim | Python Solutions
def fireworks(n):
if n % 2 == 0 or n < 1:
raise ValueError("n must be a positive odd number")
mid = n // 2
#Top half
for i in range(mid):
spaces_left = mid - i
spaces_mid = i * 2 - 1
if i == 0:
print(" " * spaces_left + "|")
else:
print(
" " * spaces_left +
"\\" +
" " * spaces_mid +
"|" +
" " * spaces_mid +
"/"
)
#Middle line
print("-" * n)
#Bottom half (mirror)
for i in reversed(range(mid)):
spaces_left = mid - i
spaces_mid = i * 2 - 1
if i == 0:
print(" " * spaces_left + "|")
else:
print(
" " * spaces_left +
"/" +
" " * spaces_mid +
"|" +
" " * spaces_mid +
"\\"
)
# Call for fireworks(99)
fireworks(99)
Fireworks : Easy Solution by Python | IbnulMisbah | Python Solutions
def fireWorks(num: int):
half = num // 2
# Upper Part :
for i in range(half):
beforeSpaces = i
middleSpaces = (half - 1) - i
print(' ' * beforeSpaces + '\\' + ' ' * middleSpaces + '|' + ' ' * middleSpaces + '/')
# Middle Line :
print('-' * num)
# Lower Part :
for i in range(half - 1, -1, -1):
beforeSpaces = i
middleSpaces = (half - 1) - i
print(' ' * beforeSpaces + '/' + ' ' * middleSpaces + '|' + ' ' * middleSpaces + '\\')
num = int(input('Type an odd number : '))
fireWorks(num)
Pseudocode - Increment & Decrement Spaces | program52 | Pseudocode Solutions
CALL drawFireworks(99)
PROCEDURE drawFireworks(size : INTEGER)
DECLARE midpoint, row, leadingSpaces, middleSpaces : INTEGER
midpoint ← (size DIV 2) + 1
leadingSpaces ← 0
middleSpaces ← (size - 3) / 2
FOR row ← 1 TO size
IF row < midpoint THEN
OUTPUT strRepeat(" ", leadingSpaces), "\\", strRepeat(" ", middleSpaces), "|", strRepeat(" ", middleSpaces), "/", strRepeat(" ", leadingSpaces)
middleSpaces ← middleSpaces - 1
leadingSpaces ← leadingSpaces + 1
ELSE
IF row = midpoint THEN
OUTPUT strRepeat("-", size)
middleSpaces ← 0
leadingSpaces ← leadingSpaces - 1
ELSE
OUTPUT strRepeat(" ", leadingSpaces), "/", strRepeat(" ", middleSpaces), "|", strRepeat(" ", middleSpaces), "\\", strRepeat(" ", leadingSpaces)
middleSpaces ← middleSpaces + 1
leadingSpaces ← leadingSpaces - 1
ENDIF
ENDIF
NEXT row
ENDPROCEDURE
FUNCTION strRepeat(str : STRING, count : INTEGER) RETURNS STRING
DECLARE index : INTEGER
DECLARE out : STRING
out ← ""
FOR index ← 1 TO count
out ← out & str
NEXT index
RETURN out
ENDFUNCTION
Zig runtime solution with nested iteration | asherx14 | Zig Solutions
const print = @import("std").debug.print;
fn fireworks(size: u8) void {
const column_height = (size - 1) / 2;
for (0..size) |i| {
if (i < column_height) { print_line(size, i); }
else if (i == column_height) {
for (0..size) |_| {
print("-", .{});
}
print("\n", .{});
}
else { print_line(size, i); }
}
}
fn print_line(size: u8, padding: usize) void {
const middle_idx = @as(u16, (size - 3) / 2) + 1;
for (0..size) |i| {
if (i == 0 + padding) { print("\\", .{}); }
else if (i == size - 1 - padding) { print("/", .{}); }
else if (i == middle_idx) { print("|", .{}); }
else { print(" ", .{}); }
}
print("\n", .{});
}
pub fn main() void {
fireworks(99);
}
Python implementation | THOMAS L | Python Solutions
//Paste your solution here if you want to share it publicly
n = int(input())
for i in range(n):
for j in range(n):
if i == n // 2:
print("-", end="")
elif j == n // 2:
print("|", end="")
elif i == j:
print("\\", end="")
elif i == n - j - 1:
print("/", end="")
else:
print(" ", end="")
print()
Pytho | AlfieJ | Python Solutions
star = 99
layer = round((star - 1)/2)
for i in range (layer):
col = layer-i-1
print(" "*i + "\\" + " "*col + "|" + " "*col + "/")
print("-"*star)
for i in range (layer):
col = layer-i-1
print(" "*col + "/" + " "*i + "|" + " "*i + "\\")
python | JustinJ | Python Solutions
def fireworks(n):
rows = (n - 1) // 2
for i in range(rows):
spaces_out = i
spaces_in = rows - i - 1
print(" " * spaces_out + "\\" + " " * spaces_in + "|" + " " * spaces_in + "/")
print("-" * n)
for i in reversed(range(rows)):
spaces_out = i
spaces_in = rows - i - 1
print(" " * spaces_out + "/" + " " * spaces_in + "|" + " " * spaces_in + "\\")
fireworks(99)
Pseudocode approach to Happy New Year problem | MarsKing | Pseudocode Solutions
PROCEDURE fireworks(NumberOfFireWorks:INTEGER)
DECLARE MidPositon: INTEGER
DECLARE Top: BOOLEAN
DECLARE dash,spaces,remaningspaces: STRING
MidPositon ← INT((NumberOfFireWorks + 1)/2)
Top ← TRUE
spaces ← ""
dash ← ""
remaningspaces ← ""
FOR Count ← 1 TO (MidPositon-2)
spaces ← spaces & " "
NEXT Count
FOR Count ← 1 TO (NumberOfFireWorks-1)
IF Count = MidPositon THEN
FOR I ← 1 TO NumberOfFireWorks
dash ← dash & "-"
NEXT I
OUTPUT dash
Top ← FALSE
ENDIF
IF Top = TRUE THEN
OUTPUT remaningspaces,'\\',spaces,"|",spaces,"/"
IF LENGTH(spaces) >= 1 THEN
spaces ← MID(spaces, 1, (LENGTH(spaces)-1))
remaningspaces ← remaningspaces & " "
ENDIF
ELSE
OUTPUT remaningspaces,"/",spaces,"|",spaces,'\\'
spaces ← spaces & " "
remaningspaces ← MID(remaningspaces,1, (LENGTH(remaningspaces)-1))
ENDIF
NEXT Count
ENDPROCEDURE