Programming Search⌘K

Taskintro

FizzBuzz

Also called fizzbuzz, fizz buzz, Fizz Buzz, FizzBuzz task, fizzbuzz interview question, count with fizz and buzz.

Count from 1 to n, and say Fizz for multiples of 3, Buzz for multiples of 5 and FizzBuzz for both, with the test for both before the other two.

Task

Count from 1 to n, and replace some numbers with words. The function fizzbuzz(n) returns one string for each number from 1 to n:

  • "FizzBuzz" for a multiple of both 3 and 5,
  • "Fizz" for a multiple of 3,
  • "Buzz" for a multiple of 5,
  • the number in decimal for any other number.

For example, fizzbuzz(5) is ["1", "2", "Fizz", "4", "Buzz"]. n is an integer from 0 to 10000.

The Rosetta Code task prints the integers from 1 to 100 with the same rules1. Fizz buzz is "a group word game for children to teach them about division", and it "has been used as an interview screening device for computer programmers"2. The program needs "little more than a loop and conditional statements in any popular language"2. Here the function returns the strings, so the tests can check them.

Solutions

Language The loop The test for both
Python for i in range(1, n + 1): i % 15 == 0
JavaScript, TypeScript for (let i = 1; i <= n; i++) i % 15 === 0
Java, C#, C, C++ for (int i = 1; i <= n; i++) i % 15 == 0
Go for i := 1; i <= n; i++ i%15 == 0
Rust for i in 1..=n i % 15 == 0
Bash for ((i = 1; i <= n; i++)) ((i % 15 == 0))
  • The remainder. % gives the remainder of a division. In Python, "the % operator returns the remainder of the division"3, and the other languages have the same operator for these positive numbers. A number is a multiple of 3 when i % 3 is 0.
  • The order of the tests. A multiple of both 3 and 5 is a multiple of 15. Each solution tests 15 first, then 3, then 5, with one if and else if chain.
  • C. Each string is a new allocation, and the caller frees each one and the array.
  • Bash. The function prints one string on each line.

Edge cases

The cases are in cases/basic.jsonl and cases/edge.jsonl.

  • zero: the loop body does not run, and the result is empty.
  • one: only the number 1.
  • three and five: the first Fizz and the first Buzz are the last item.
  • fifteen: the first FizzBuzz is the last item. The loop must include n. See off-by-one errors.
  • thirty: two FizzBuzz items.

Pitfalls

  • The test for 3 before the test for 15 hides FizzBuzz. An if chain "selects exactly one of the suites by evaluating the expressions one by one until one is found to be true"4. If i % 3 == 0 comes first, it is true for 15, and the chain never reaches the test for 15:
def wrong(i):
    if i % 3 == 0:
        return "Fizz"
    elif i % 5 == 0:
        return "Buzz"
    elif i % 15 == 0:
        return "FizzBuzz"
    return str(i)


def right(i):
    if i % 15 == 0:
        return "FizzBuzz"
    elif i % 3 == 0:
        return "Fizz"
    elif i % 5 == 0:
        return "Buzz"
    return str(i)


print([wrong(i) for i in range(13, 16)])
print([right(i) for i in range(13, 16)])
Output
['13', '14', 'Fizz']
['13', '14', 'FizzBuzz']
  • The loop starts at 1 and includes n. A loop from 0 adds an item for 0, which is a multiple of 15, and a loop that stops before n misses the last item. See write a counted loop.

Code

The build runs the native tests of each language in a pinned toolchain.

fizzbuzz.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/fizzbuzz-task/.

def fizzbuzz(n: int) -> list[str]:
    """Return FizzBuzz, Fizz, Buzz or the number for each number from 1 to n."""
    out = []
    for i in range(1, n + 1):
        # Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
        if i % 15 == 0:
            out.append("FizzBuzz")
        elif i % 3 == 0:
            out.append("Fizz")
        elif i % 5 == 0:
            out.append("Buzz")
        else:
            out.append(str(i))
    return out
test_fizzbuzz.py 21 lines
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/fizzbuzz-task/.

import pytest

from fizzbuzz import fizzbuzz

CASES = {
    "fifteen": (15, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]),
    "thirty": (30, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"]),
    "zero": (0, []),
    "one": (1, ["1"]),
    "three": (3, ["1", "2", "Fizz"]),
    "five": (5, ["1", "2", "Fizz", "4", "Buzz"]),
}


@pytest.mark.parametrize("name", CASES)
def test_fizzbuzz(name):
    n, want = CASES[name]
    assert fizzbuzz(n) == want
fizzbuzz.cppI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#include "fizzbuzz.hpp"

#include <string>
#include <vector>

std::vector<std::string> fizzbuzz(int n) {
    std::vector<std::string> out;
    for (int i = 1; i <= n; i++) {
        // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
        if (i % 15 == 0) {
            out.push_back("FizzBuzz");
        } else if (i % 3 == 0) {
            out.push_back("Fizz");
        } else if (i % 5 == 0) {
            out.push_back("Buzz");
        } else {
            out.push_back(std::to_string(i));
        }
    }
    return out;
}
fizzbuzz.hpp 11 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#pragma once

#include <string>
#include <vector>

// fizzbuzz returns FizzBuzz, Fizz, Buzz or the number for each number from 1
// to n.
std::vector<std::string> fizzbuzz(int n);
test_fizzbuzz.cpp 32 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#include "fizzbuzz.hpp"

#include <iostream>
#include <string>
#include <string_view>
#include <vector>

static int failures = 0;

static void check(std::string_view name, int n, const std::vector<std::string> &want) {
    if (fizzbuzz(n) != want) {
        std::cerr << "case " << name << " failed\n";
        failures++;
    }
}

int main() {
    check("fifteen", 15, {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"});
    check("thirty", 30, {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"});
    check("zero", 0, {});
    check("one", 1, {"1"});
    check("three", 3, {"1", "2", "Fizz"});
    check("five", 5, {"1", "2", "Fizz", "4", "Buzz"});
    if (failures > 0) {
        return 1;
    }
    std::cout << "all cases pass\n";
    return 0;
}
FizzBuzz.javaI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

import java.util.ArrayList;
import java.util.List;

final class FizzBuzz {
  private FizzBuzz() {}

  /** Returns FizzBuzz, Fizz, Buzz or the number for each number from 1 to n. */
  static List<String> fizzbuzz(int n) {
    List<String> out = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
      // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
      if (i % 15 == 0) {
        out.add("FizzBuzz");
      } else if (i % 3 == 0) {
        out.add("Fizz");
      } else if (i % 5 == 0) {
        out.add("Buzz");
      } else {
        out.add(Integer.toString(i));
      }
    }
    return out;
  }
}
FizzBuzzTest.java 28 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class FizzBuzzTest {
  static Stream<Arguments> cases() {
    return Stream.of(
        Arguments.of("fifteen", 15, List.of("1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz")),
        Arguments.of("thirty", 30, List.of("1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz")),
        Arguments.of("zero", 0, List.of()),
        Arguments.of("one", 1, List.of("1")),
        Arguments.of("three", 3, List.of("1", "2", "Fizz")),
        Arguments.of("five", 5, List.of("1", "2", "Fizz", "4", "Buzz")));
  }

  @ParameterizedTest(name = "{0}")
  @MethodSource("cases")
  void fizzbuzz(String name, int n, List<String> want) {
    assertEquals(want, FizzBuzz.fizzbuzz(n), name);
  }
}
fizzbuzz.cI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#include "fizzbuzz.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void fizzbuzz_free(char **out, int n) {
    if (out == NULL) {
        return;
    }
    for (int i = 0; i < n; i++) {
        free(out[i]);
    }
    free(out);
}

char **fizzbuzz(int n) {
    // malloc(0) may return NULL, so ask for at least one pointer.
    char **out = malloc((size_t)(n > 0 ? n : 1) * sizeof *out);
    if (out == NULL) {
        return NULL;
    }
    for (int i = 1; i <= n; i++) {
        // 12 bytes hold "FizzBuzz" or any int in decimal, with the 0.
        char *s = malloc(12);
        if (s == NULL) {
            fizzbuzz_free(out, i - 1);
            return NULL;
        }
        // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
        if (i % 15 == 0) {
            strcpy(s, "FizzBuzz");
        } else if (i % 3 == 0) {
            strcpy(s, "Fizz");
        } else if (i % 5 == 0) {
            strcpy(s, "Buzz");
        } else {
            snprintf(s, 12, "%d", i);
        }
        out[i - 1] = s;
    }
    return out;
}
fizzbuzz.h 15 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#ifndef FIZZBUZZ_H
#define FIZZBUZZ_H

// fizzbuzz returns a new array of n new strings: FizzBuzz, Fizz, Buzz or the
// number for each number from 1 to n. The caller frees each string and the
// array with fizzbuzz_free. It returns NULL when malloc fails.
char **fizzbuzz(int n);

// fizzbuzz_free frees the n strings and the array that fizzbuzz returned.
void fizzbuzz_free(char **out, int n);

#endif
test_fizzbuzz.c 37 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

#include "fizzbuzz.h"

#include <stdio.h>
#include <string.h>

static int failures = 0;

static void check(const char *name, int n, const char *const *want) {
    char **out = fizzbuzz(n);
    int ok = out != NULL;
    for (int i = 0; ok && i < n; i++) {
        ok = strcmp(out[i], want[i]) == 0;
    }
    fizzbuzz_free(out, n);
    if (!ok) {
        fprintf(stderr, "case %s failed\n", name);
        failures++;
    }
}

int main(void) {
    const char *thirty[] = {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"};
    check("fifteen", 15, thirty);
    check("thirty", 30, thirty);
    check("zero", 0, thirty);
    check("one", 1, thirty);
    check("three", 3, thirty);
    check("five", 5, thirty);
    if (failures > 0) {
        return 1;
    }
    printf("all cases pass\n");
    return 0;
}
FizzBuzz.csI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

using System.Globalization;

public static class FizzBuzz
{
    // Returns FizzBuzz, Fizz, Buzz or the number for each number from 1 to n.
    public static List<string> Of(int n)
    {
        var result = new List<string>();
        for (int i = 1; i <= n; i++)
        {
            // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
            if (i % 15 == 0)
            {
                result.Add("FizzBuzz");
            }
            else if (i % 3 == 0)
            {
                result.Add("Fizz");
            }
            else if (i % 5 == 0)
            {
                result.Add("Buzz");
            }
            else
            {
                result.Add(i.ToString(CultureInfo.InvariantCulture));
            }
        }
        return result;
    }
}
FizzBuzzTests.cs 25 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

using Xunit;

public sealed class FizzBuzzTests
{
    public static TheoryData<string, int, string[]> Cases => new()
    {
        { "fifteen", 15, new[] { "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz" } },
        { "thirty", 30, new[] { "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz" } },
        { "zero", 0, new string[0] },
        { "one", 1, new[] { "1" } },
        { "three", 3, new[] { "1", "2", "Fizz" } },
        { "five", 5, new[] { "1", "2", "Fizz", "4", "Buzz" } },
    };

    [Theory]
    [MemberData(nameof(Cases))]
    public void Check(string name, int n, string[] want)
    {
        Assert.NotNull(name);
        Assert.Equal(want, FizzBuzz.Of(n));
    }
}
fizzbuzz.jsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

/**
 * Returns FizzBuzz, Fizz, Buzz or the number for each number from 1 to n.
 * @param {number} n
 * @returns {string[]}
 */
export function fizzbuzz(n) {
  const out = [];
  for (let i = 1; i <= n; i++) {
    // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
    if (i % 15 === 0) {
      out.push("FizzBuzz");
    } else if (i % 3 === 0) {
      out.push("Fizz");
    } else if (i % 5 === 0) {
      out.push("Buzz");
    } else {
      out.push(String(i));
    }
  }
  return out;
}
fizzbuzz.test.js 22 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { fizzbuzz } from "./fizzbuzz.js";

const cases = [
  ["fifteen", 15, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]],
  ["thirty", 30, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"]],
  ["zero", 0, []],
  ["one", 1, ["1"]],
  ["three", 3, ["1", "2", "Fizz"]],
  ["five", 5, ["1", "2", "Fizz", "4", "Buzz"]],
];

for (const [name, n, want] of cases) {
  test(name, () => {
    assert.deepEqual(fizzbuzz(n), want);
  });
}
fizzbuzz.tsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

export function fizzbuzz(n: number): string[] {
  const out: string[] = [];
  for (let i = 1; i <= n; i++) {
    // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
    if (i % 15 === 0) {
      out.push("FizzBuzz");
    } else if (i % 3 === 0) {
      out.push("Fizz");
    } else if (i % 5 === 0) {
      out.push("Buzz");
    } else {
      out.push(String(i));
    }
  }
  return out;
}
fizzbuzz.test.ts 22 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { fizzbuzz } from "./fizzbuzz.ts";

const cases: [string, number, string[]][] = [
  ["fifteen", 15, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]],
  ["thirty", 30, ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"]],
  ["zero", 0, []],
  ["one", 1, ["1"]],
  ["three", 3, ["1", "2", "Fizz"]],
  ["five", 5, ["1", "2", "Fizz", "4", "Buzz"]],
];

for (const [name, n, want] of cases) {
  test(name, () => {
    assert.deepEqual(fizzbuzz(n), want);
  });
}
fizzbuzz.goI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

// Package fizzbuzz counts from 1 to n with Fizz and Buzz.
package fizzbuzz

import "strconv"

// FizzBuzz returns FizzBuzz, Fizz, Buzz or the number for each number from 1 to n.
func FizzBuzz(n int) []string {
	out := []string{}
	for i := 1; i <= n; i++ {
		// Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
		switch {
		case i%15 == 0:
			out = append(out, "FizzBuzz")
		case i%3 == 0:
			out = append(out, "Fizz")
		case i%5 == 0:
			out = append(out, "Buzz")
		default:
			out = append(out, strconv.Itoa(i))
		}
	}
	return out
}
fizzbuzz_test.go 30 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

package fizzbuzz

import (
	"slices"
	"testing"
)

var cases = []struct {
	name string
	n    int
	want []string
}{
	{"fifteen", 15, []string{"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"}},
	{"thirty", 30, []string{"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"}},
	{"zero", 0, []string{}},
	{"one", 1, []string{"1"}},
	{"three", 3, []string{"1", "2", "Fizz"}},
	{"five", 5, []string{"1", "2", "Fizz", "4", "Buzz"}},
}

func TestFizzBuzz(t *testing.T) {
	for _, c := range cases {
		if got := FizzBuzz(c.n); !slices.Equal(got, c.want) {
			t.Errorf("%s: got %q, want %q", c.name, got, c.want)
		}
	}
}
fizzbuzz.rsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

/// Returns FizzBuzz, Fizz, Buzz or the number for each number from 1 to n.
pub fn fizzbuzz(n: u32) -> Vec<String> {
    let mut out = Vec::new();
    for i in 1..=n {
        // Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
        if i % 15 == 0 {
            out.push("FizzBuzz".to_string());
        } else if i % 3 == 0 {
            out.push("Fizz".to_string());
        } else if i % 5 == 0 {
            out.push("Buzz".to_string());
        } else {
            out.push(i.to_string());
        }
    }
    out
}
tests/fizzbuzz_test.rs 19 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/fizzbuzz-task/.

use algo_fizzbuzz_task::fizzbuzz;

#[test]
fn cases() {
    let cases: &[(&str, u32, &[&str])] = &[
        ("fifteen", 15, &["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]),
        ("thirty", 30, &["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"]),
        ("zero", 0, &[]),
        ("one", 1, &["1"]),
        ("three", 3, &["1", "2", "Fizz"]),
        ("five", 5, &["1", "2", "Fizz", "4", "Buzz"]),
    ];
    for &(name, n, want) in cases {
        assert_eq!(fizzbuzz(n), want, "{name}");
    }
}
fizzbuzz.shI0RawGitHub
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/fizzbuzz-task/.

# fizzbuzz N
# Prints FizzBuzz, Fizz, Buzz or the number for each number from 1 to N, one
# on each line.
fizzbuzz() {
  local n=$1 i
  for ((i = 1; i <= n; i++)); do
    # Test 15 first: a multiple of 15 is also a multiple of 3 and of 5.
    if ((i % 15 == 0)); then
      printf '%s\n' FizzBuzz
    elif ((i % 3 == 0)); then
      printf '%s\n' Fizz
    elif ((i % 5 == 0)); then
      printf '%s\n' Buzz
    else
      printf '%s\n' "$i"
    fi
  done
}
test_fizzbuzz.bats 26 lines
#!/usr/bin/env bats
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/fizzbuzz-task/.

bats_require_minimum_version 1.5.0

setup() {
  source "$BATS_TEST_DIRNAME/fizzbuzz.sh"
}

check() { # check N WANT...
  local n=$1
  shift
  local got want
  # The x keeps the trailing newlines, which $(...) removes.
  got=$(fizzbuzz "$n"; printf x)
  want=$(if (($# > 0)); then printf '%s\n' "$@"; fi; printf x)
  [ "$got" = "$want" ] || { printf 'got:  %q\nwant: %q\n' "$got" "$want"; return 1; }
}

@test "fifteen" { check 15 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz; }
@test "thirty" { check 30 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz; }
@test "zero" { check 0; }
@test "one" { check 1 1; }
@test "three" { check 3 1 2 Fizz; }
@test "five" { check 5 1 2 Fizz 4 Buzz; }

References

  1. FizzBuzz, Rosetta Code (the RosettaCodeData mirror), Task
  2. Fizz buzz, Wikipedia, Lead; Play; Programming
  3. An Informal Introduction to Python, The Python Tutorial, 3.1.1 Numbers
  4. Compound statements, The Python Language Reference, 8.1 The if statement

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (bash)I0 not checked yet
  • the tests did not run in this build
Code (c)I0 not checked yet
  • the tests did not run in this build
Code (cpp)I0 not checked yet
  • the tests did not run in this build
Code (csharp)I0 not checked yet
  • the tests did not run in this build
Code (go)I0 not checked yet
  • the tests did not run in this build
Code (java)I0 not checked yet
  • the tests did not run in this build
Code (javascript)I0 not checked yet
  • the tests did not run in this build
Code (python)I0 not checked yet
  • the tests did not run in this build
Code (rust)I0 not checked yet
  • the tests did not run in this build
Code (typescript)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • a history with a source