mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

zunda

$ cat tt.rb
(1..20).each do |i|
m = []
m << 'トリック' if i % 3 == 0
m << 'トリート' if i % 5 == 0
puts m.empty? ? i : m.join(" or ")
end
$ ruby tt.rb
1
2
トリック
4
トリート
トリック
7
8
トリック
トリート
11
トリック
13
14
トリック or トリート
16
17
トリック
19
トリート

せっかくならRustとGoで書けばいいのにね←

Rustまだまだ慣れないなあ

$ cat src/main.rs
fn main() {
for i in 1..21 {
if i % 15 == 0 {
println!("トリック or トリート");
} else if i % 5 == 0 {
println!("トリート");
} else if i % 3 == 0 {
println!("トリック");
} else {
println!("{}", i);
};
}
}
$ cargo run
:
1
2
トリック
4
トリート
トリック
7
8
トリック
トリート
11
トリック
13
14
トリック or トリート
16
17
トリック
19
トリート

Goでもあんまり工夫の余地を見出せない

$ cat main.go
package main

import "fmt"

func main() {
for i := 1; i < 21; i++ {
switch {
case i%15 == 0:
fmt.Println("トリック or トリート")
case i%5 == 0:
fmt.Println("トリート")
case i%3 == 0:
fmt.Println("トリック")
default:
fmt.Println(i)
}
}
}
$ go run main.go
1
2
トリック
4
トリート
トリック
7
8
トリック
トリート
11
トリック
13
14
トリック or トリート
16
17
トリック
19
トリート

これはkazuhoさんのすんごいfizzbuzz.js https://gist.github.com/kazuho/3300555

$ cat tt.js
trick = function f() {
trick = function () {
trick = function () {
trick = f
return "トリック"
}
}
}

treat = function f() {
treat = function () {
treat = function () {
treat = function () {
treat = function () {
treat = f
return "トリート"
}
}
}
}
}

n = 0
tricktreat = function () {
++n
x = trick()
y = treat()
console.log((x || "") + (x && y ? " or " : "") + (y || "") || n)
}
while(n < 21) {
tricktreat()
}
$ node tt.js
1
2
トリック
4
トリート
トリック
7
8
トリック
トリート
11
トリック
13
14
トリック or トリート
16
17
トリック
19
トリート
トリック

Gistfizzbuzz.jsGitHub Gist: instantly share code, notes, and snippets.