All SolutionsAll Solutions

🎳

A Billion Bowling Pins

Week 5, 2026

Python - Inefficient but works method | BMC | Python Solutions

# meths or maths? goals = [1_000_000, 1_000_000_000] for goal in goals: i = 0 while goal >= 0: i += 1 goal -= i print(i-1)

python | Peiran D | Python Solutions

//Paste your solution here if you want to share it publiclyrows = 0 number = 1 n = int(input()) while n > 0: n -= number number += 1 rows += 1 if n < 0: rows -= 1 print(rows)

using vectors and loops | Draw6 | C++ Solutions

//Draw6 #include <iostream> #include <vector> // not efficient at all - takes about 45 seconds to run // Function to generate the first n triangular numbers std::vector<long> generateTriangularNumbers(long numberOfTerms) { std::vector<long> triangularNumbers; for (long n = 1; n <= numberOfTerms; ++n) { long triangularNumber = (n * (n + 1)) / 2; triangularNumbers.push_back(triangularNumber); } return triangularNumbers; } int main() { std::cout << "Please stand by for outcome...\n"; long numberOfTerms = 1; long numM, numB, finalM, finalB; for(int i = 0; i < numberOfTerms; i++) { std::vector<long> triangularNumbersM = generateTriangularNumbers(numberOfTerms); finalM = numberOfTerms; for ( long numM : triangularNumbersM) { if(numM > 1000000) { numberOfTerms = 0; } } numberOfTerms++; } for(int i = 0; i < numberOfTerms; i++) { std::vector<long> triangularNumbersB = generateTriangularNumbers(numberOfTerms); finalB = numberOfTerms; for ( long numB : triangularNumbersB) { if(numB > 1000000000) { numberOfTerms = 0; } } numberOfTerms++; } std::cout << "Number of rows with a million pins: " << finalM -1 << "\n"; std::cout << "Number of rows with a billion pins: " << finalB -1 << "\n"; return 0; }

Loop, increment, subtract | greenya | Odin Solutions

package main import "core:fmt" main :: proc () { for i in ([?] int { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1e3, 1e4, 1e5, 1e6, 1e9, 1e12, 1e15, 1e18, }) { rows := full_rows_count(i) fmt.printfln("%i\t%i", i, rows) } } full_rows_count :: proc (pins: int) -> int { i := 0 p := pins for p >= 0 { i += 1 p -= i } return i - 1 }

Python solution | AlfieJ | Python Solutions

n = int(input()) a = 0 b = 1 while True : a += b b += 1 print(a) if a > n: print(b-2) break elif a == n: print(b-1) break

Easier Python solution | AlfieJ | Python Solutions

n = int(input()) a = 0 b = 1 while a <= n : a += b b += 1 print(b-2)

Formula solution | AlfieJ | C++ Solutions

#include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int k = (sqrt(8 * n + 1) - 1) / 2; cout << k << endl; }

triangular numbers | AbsolutelyArsenal | Pseudocode Solutions

DECLARE Counter : INTEGER DECLARE Triangle : INTEGER Counter ← 1 Triangle ← (1/2)*(Counter)*(Counter + 1) WHILE Triangle < 1000000 Counter ← Counter + 1 Triangle ← (1/2)*(Counter)*(Counter + 1) ENDWHILE OUTPUT Counter-1 WHILE Triangle < 1000000000 Counter ← Counter + 1 Triangle ← (1/2)*(Counter)*(Counter + 1) ENDWHILE OUTPUT Counter-1

python | JustinJ | Python Solutions

//Paste your solution here if you want to share it publicly import math x = int(input()) y = (-1 + math.sqrt(1 + 8*(x))) / 2 y= math.floor(y) print(y)

python | JustinJ | Python Solutions

//Paste your solution here if you want to share it publicly import math x = int(input()) y = (-1 + math.sqrt(1 + 8*(x))) / 2 y= math.floor(y) print(y)

Pseudocode A Billion Bowling Pins | MarsKing | Pseudocode Solutions

FUNCTION HowManyRows(Pins:INTEGER) RETURNS INTEGER DECLARE RemaningPins,Row:INTEGER RemaningPins ← Pins Row ← 0 REPEAT Row ← Row + 1 RemaningPins ← RemaningPins - Row UNTIL RemaningPins <= 0 IF RemaningPins < 0 THEN Row ← Row - 1 ENDIF RETURN Row ENDFUNCTION

Python | PaulZ | Python Solutions

import math Pins = int(input("How many pins: ")) Rows = (-1 + math.sqrt(1 + 8*(Pins))) / 2 Rows= math.floor(Rows) print(Rows)

Easiest but not efficient solution | MushyZ | Python Solutions

def calc_pin_rows(no_of_pins): rows = 0 n = 1 if no_of_pins == 1: return 1 while no_of_pins > 0: if no_of_pins - n < 0: break rows += 1 no_of_pins -= n n += 1 return rows if __name__ == "__main__": no_of_pins = 1000000000 #for billion rows = calc_pin_rows(no_of_pins) print(f"Number of rows needed for {no_of_pins} pins: {rows}")