cijb-7724 / Fizz-Buzz

0 stars 1 forks source link

Fizz-Buzz

Fizz Buzzの定義

i(in [1, 100])行目が
3の倍数なら"Fizz"
5の倍数なら"Buzz"
15の倍数なら"FizzBuzz"
どれでもなければ"i"

https://ja.wikipedia.org/wiki/Fizz_Buzz

Rules

Fizz Buzz Checker

checker

https://komari.co.jp/fizzbuzz/ で100/100にする

1.><>

fish

2.AWK

BEGIN {
    for (i=1; i<=100; ++i) {
      s = ""
      if (i % 15 == 0) s = "FizzBuzz";
      else if (i % 3 == 0) s = "Fizz";
      else if (i % 5 == 0)  s = "Buzz";
      else s = i;
      print s;
    }
}

3.Ada

with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
use Ada.Text_IO;

procedure Program is
   I : Integer := 1;
   F : String := "FizzBuzz";
begin
   for I in 1 .. 100 loop
      if I mod 15 = 0 then
        Put_Line(F(1..8));
      elsif I mod 3 = 0 then
        Put_Line(F(1..4));
      elsif I mod 5 = 0 then
        Put_Line(F(5..8));
      else
        Put_Line(Integer'Image(I));
      end if;
   end loop;
end Program;

4.Assembly x64

5.Bash

for ((i=1; i <= 100; i++)); do
    if (($i % 15 == 0)); then
        echo "FizzBuzz"
    elif (($i % 3 == 0)); then
        echo "Fizz"
    elif (($i % 5 == 0)); then
        echo "Buzz"
    else
        echo $i
    fi
done

6.Brainfuck

++++++++++[->>>>++++++++++>+++++++>+++++++>++++++++++>++++++++++++>++++++++++++<
<<<<<<<<]>>>>+>---->>+++++>--->++<<<<<<<<<+++++[->>>>>>>>>>+>+>++>+++<<<<<<<<<<<
<<]>>>>>>>>>>--<<<<<<[-<+>>>>>>>>>>>>>>+<<<<<<<<<<<<<]<[->+<]>>>>>>>>>>[->>+>>>>
>>>>>>+<<<<<<<<<<<<]>>[-<<+>>]<<<<<[->>>>>+>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<
<<<<<]>>>>>[-<<<<<+>>>>>]<<<<[->>>>+>>>>>>>>>>>>>>>>>>>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>]<[-<->]+<[[-]>-<]>[
->>>>>>>+<<<<<<<]>>>>>>>>+<<<[->[-]>[-]>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<.>.>>..<<<<.>>>.>..>>>.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>[->[-]>[-]<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<.>.>>..>>>.>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>]>[->[-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<.>>>.>..>>>.>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-<+>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<]<[->+<]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[->+<<<+>>]<<[->>+<<]>[->>->[
-]>[-]>[-]<<<[->+>+<<]>>[-<<+>>]<[[-]>+<]>>+<[[-]>-<]>[-<<<<[->+>+<<]>>[-<<+>>]>
>>+<]<<<<<]>>>>>>>++++++++++<<<<<[->>>>>-<<<<<]>>>>[->>+>+<<<]>>>[-<<<+>>>]<[[-]
>+<]>>>++++++++[-<++++++>]<[-<<<+<+>>>>]<[-<<<.>>>]<<<[-]>.[-]++++++++++.[-]<<<<
<<<<<<<<]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>]<<<<<<]

7.C

#include <stdio.h>
#include <string.h>
int main() {
    for (int i=1; i<=100; ++i) {
        if (i % 3 == 0) printf("Fizz");
        if (i % 5 == 0) printf("Buzz");
        if (i % 3 != 0 && i % 5 != 0) printf("%d", i);
        printf("\n");
    }
}

8.C

using System;

class Program {
    static void Main() {
        int N, K;
        string input = Console.ReadLine();
        N = int.Parse(input.Split(' ')[0]);
        for (int i = 1; i <= N; i++) {
            string output = "";
            if (i % 3 == 0) output += "Fizz";
            if (i % 5 == 0) output += "Buzz";
            if (output == "") output = i.ToString();
            Console.WriteLine(output);
        }
        K = int.Parse(input.Split(' ')[1]);
        Console.WriteLine(K);
    }
}

9.C++

#include <iostream>
#include <string>
using namespace std;
int main() {
    for (int i=1; i<=100; ++i) {
        string s = "";
        if (i % 3 == 0) s += "Fizz";
        if (i % 5 == 0) s += "Buzz";
        if (s == "") s += to_string(i);
        cout << s << endl;
    }
}

10.COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MAIN.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WORK-AREA.
       03 disp PIC Z(3).
       03 I PIC 999.
       PROCEDURE DIVISION.
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100
               IF FUNCTION MOD(I, 15) = 0
                   DISPLAY "FizzBuzz"
               ELSE IF FUNCTION MOD(I, 3) = 0
                   DISPLAY "Fizz"
               ELSE IF FUNCTION MOD(I, 5) = 0
                   DISPLAY "Buzz"
               ELSE
                   COMPUTE disp = I
                   DISPLAY disp
               END-IF
           END-PERFORM.
           STOP RUN.
       END PROGRAM MAIN.

11.Carp

(use IO)
(use String)
(use Int)

(defn fizzbuzz [i n]
  (if (< i (+ n 1))
    (do
      (if (= 0 (mod i 15))
        (println* "FizzBuzz")
        (do
          (if (= 0 (mod i 3))
            (println* "Fizz")
            (do
              (if (= 0 (mod i 5))
                (println* "Buzz")
                (println &(Int.str i))
              )
            )
          )
        )
      )
      (fizzbuzz (inc i) n)
    )
    ()
  )
)

(defn main []
  (fizzbuzz 1 100)
)

12.Clojure

(loop [i 1]
    (cond
        (zero? (mod i 15)) (println "FizzBuzz")
        (zero? (mod i 3)) (println "Fizz")
        (zero? (mod i 5)) (println "Buzz")
        :else (println i))
    (if (< i 101)
        (recur (inc i))
        i))

13.Common Lisp

(defun fizzbuzz (n)
    (when (< n 101)
        (cond
            ((= 0 (mod n 15))
                (write-string "FizzBuzz")
            )
            ((= 0 (mod n 3))
                (write-string "Fizz")
            )
            ((= 0 (mod n 5))
                (write-string "Buzz")
            )
            (t
                (write-string (write-to-string n))
            )
        )
        (terpri)
        (fizzbuzz (+ 1 n))
    )
)
(fizzbuzz 1)

14.Crystal

n = (1).to_i
while n <= 100
    if n % 15 == 0
        puts "FizzBuzz"
    elsif n % 3 == 0
        puts "Fizz"
    elsif n % 5 == 0
        puts "Buzz"
    else
        puts n
    end
    n += 1
end

15.Cyber

for 1..101 each 1:
    if i % 3 == 0:
        prints 'Fizz'
    if i % 5 == 0:
        prints 'Buzz'
    if i % 3 != 0 and i % 5 != 0:
        prints '{i}'
    print ''

16.D

import std.stdio;
void main() {
  for (int i=1; i<=100; ++i) {
    if (i % 3 == 0) write("Fizz");
    if (i % 5 == 0) write("Buzz");
    if (i % 3 != 0 && i % 5 != 0) write(i);
    writeln("");
  }
}

17.Dart

import 'Dart:io';
void main() {
    for (int n=1; n<=100; ++n) {
        if (n % 3 == 0) stdout.write('Fizz');
        if (n % 5 == 0) stdout.write('Buzz');
        if (n % 3 != 0 && n % 5 != 0) stdout.write(n);
        print('');
    }
}

18.ECLiPSe

main :-
    (
        count(N, 1, 100)
    do
        ( N mod 3 =:= 0 ->
            write("Fizz")
        ;
            true
        ),
        ( N mod 5 =:= 0 ->
            write("Buzz")
        ;
            true
        ),
        ( N mod 5 =\= 0 , N mod 3 =\= 0 ->
            write(N)
        ;
            true
        ),
        nl
    ).

19.Elixir

defmodule Main do
  def create_list do
    1..100
    |> Enum.to_list()
  end
  def main do
    n = Main.create_list()
    for x <- n do
      if rem(x, 15) == 0 do
        IO.puts("FizzBuzz")
      else
        if rem(x, 3) == 0 do
          IO.puts("Fizz")
        else
          if rem(x, 5) == 0 do
            IO.puts("Buzz")
          else
            IO.puts(x)
          end
        end
      end
    end
  end
end

20.Emacs Lisp

(defun solve (n)
  (mapcar
    (lambda (x)
      (cond
        ((zerop (mod x 15)) "FizzBuzz")
        ((zerop (mod x 3))  "Fizz")
        ((zerop (mod x 5))  "Buzz")
        (t                  (number-to-string x))
      )
    )
  n
  )
)
(defun main ()
  (interactive)
  (let
    (
      (n (number-sequence 1 100)) 
      results
    )
    (setq results (solve n))
    (dolist
      (result results)
      (princ (format "%s\n" result))
    )
  )
)
(main)

21.x

22.x

23.x

24.x

25.x

26.x

27.x

28.x

29.x

30.x

31.x

32.Kotlin

fun main() {
    for (i in 1..100) {
        if (i % 3 == 0) print("Fizz")
        if (i % 5 == 0) print("Buzz")
        if (i % 3 != 0 && i % 5 != 0) print("$i")
        println("")
    }
}

33.x

34.x

35.x

36.x

37.x

38.x

39.x

40.x

41.x

42.x

43.x

44.x

45.x

46.x

47.x

48.x

49.x

50.x

51.x

52.x

53.x

54.x

55.x

56.x

57.x

58.x

59.x

60.x

61.x

62.x

63.x

64.x

65.x

66.x

67.x

68.x

69.x

70.x