DEV Community

Yuta Goto
Yuta Goto

Posted on

2

Emojicode FizzBuzz

この記事は、雑談Slack Advent Calendar 2019 の13日目の記事です。 📆

https://adventar.org/calendars/4684

Emojicodeというプログラミング言語(?)を用いてFizzBuzzを書いたので、かんたんに読み解いていきます。 💻

https://www.emojicode.org/

emoji-fizzbuzz

Compile

$ emojicodec fizzbuzz.emojic
Enter fullscreen mode Exit fullscreen mode

Run

$ ./fizzbuzz
Enter fullscreen mode Exit fullscreen mode




🏁 🍇
  1 ➡️ 🖍🆕 i

  🔁 i ◀️🙌 15 🍇
    ↪️ i 🚮 15 🙌 0 🍇
      😀 🔤FizzBuzz🔤❗️
    🍉
    🙅↪️ i 🚮 5 🙌 0 🍇
      😀 🔤Buzz🔤❗️
    🍉
    🙅↪️ i 🚮 3 🙌 0 🍇
      😀 🔤Fizz🔤❗️
    🍉
    🙅 🍇
      😀 🔡 i 10❗️❗️
    🍉
    i ➕ 1 ➡️🖍 i
  🍉
🍉
Enter fullscreen mode Exit fullscreen mode
  • 🏁でメイン関数
  • 🍇 🍉でブロックの始めとおわり
  • ➡️ :lower_left_crayon:🆕 変数代入
  • 🔁 Whileループ
  • ◀️🙌 小なりイコール ≦
  • ↪️ if
  • 🚮 剰余算
  • 🙌 イコール
  • 😃 文字列標準出力
  • 🔤 文字列を囲むダブルクォーテーションのような働きをするやつ
  • ❗ 閉じカッコのようなもの。Booleanの頭の方にあったら否定する働きももつ。
  • 🙅↪️ elseif
  • 🙅 else
  • 🔡 整数値を文字列に変換する
  • ➕ +

なのでよくみる言語で書き直すと、

# ruby
def main
  i = 1

  while i <= 15
    if i % 15 == 0
      puts "FizzBuzz"
    elsif i % 5 == 0
      puts "Buzz"
    elsif i % 3 == 0
      puts "Fizz"
    else
      puts i.to_s
    end
    i = i + 1
  end
end
Enter fullscreen mode Exit fullscreen mode
# python3
def main():
  i = 1

  while i <= 15:
    if i % 15 == 0:
      print("FizzBuzz")
    elif i % 5 == 0:
      print("Buzz")
    elif i % 3 == 0:
      print("Fizz")
    else:
      print(str(i))

    i = i + 1
Enter fullscreen mode Exit fullscreen mode

とかなります。

入力はかなり大変ですが、見た目に慣れてしまえばかなり楽しいです。

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay