Help us understand the problem. What is going on with this article?

Go言語で5の倍数と5のつく数字だけヒロミゴーする

More than 3 years have passed since last update.

経緯

最近Goのプロジェクトに間接的に関わっている。

自分はほとんどGo書かないのだけれど、楽しそうだし、Goは非常にロックだと聞いているし入門することにした。

Goといえばやっぱりヒロミゴーなのは2億4千万人の間でコンセンサスがとれていると思うので、エキゾチック・ジャパンなFizzBuzzを書いた。

5がつく数字で「Exotic」、5の倍数で「Japan」、両立したら「Exotic Japan」するようになっている。

こんな感じ

Screenshot 2015-02-11 13.51.45.png

ヒロミゴー的なロックを求めるならばやっぱり2億5千万で行きましょう。

Enter integer: 250000000

コード

コードはこんな感じになった。

hiromi.go
package main

import (
    "fmt"
    "strconv"
)

func main() {

    fmt.Print("Enter integer: ")
    var input int
    fmt.Scanf("%d", &input)

    for i := 1; i <= input; i++ {
        fizzbuzz(i)
    }
}

func isFiveIncluded(num int) bool {
    var strInt = strconv.Itoa(num)
    for k := 0; k < len([]rune(strInt)); k++ {
        if '5' == strInt[k] {
            return true
        }
    }
    return false
}

func fizzbuzz(i int) {
    exotic := "Exotic"
    japan := "Japan"

    if isFiveIncluded(i) && i%5 == 0 {
        fmt.Println(i, exotic+" "+japan)
    } else if isFiveIncluded(i) {
        fmt.Println(i, exotic)
    } else if i%5 == 0 {
        fmt.Println(i, japan)
    } else {
        fmt.Println(i)
    }
}

コードはGitHubにあるよ。
kmagai/hiromigo-in-golang

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away