ใพใJ่จ่ชใง้ใถ. FizzBuzz ๆธใใชใฉใใฆใฟใใ.
J่จ่ชใงifใforใชใฉใฎๅถๅพกๆง้ ใฏ็จๆใฏใใใฆใใใฉ ใใใไฝฟใใฎใฏJ่จ่ชใใใใชใใ ใจใใใฉใใใซๆธใใฆใใฃใๆฐใใใใฎใงไฝฟใใชใใใจใซใใใ
idx n | n `mod` 15 == 0 = 3
| n `mod` 5 == 0 = 2
| n `mod` 3 == 0 = 1
| n `mod` 1 == 0 = 0
fizzbuzz n = [show n, "Fizz", "Buzz", "FizzBuzz"] !! (idx n)
main = print $ map fizzbuzz [1..100]
ๆใใคใใใฎใฏ๏ผใใใใใใๆน
idx =: (0=5|]) + 2 * 0=3|]
ๅคงๅคใใฎใพใพใงใใ ใใฃใจJใใใๆธใในใใใใจ
idx =: +/ @ (1 2 # 0=3 5 |])
ๆธใใฆใฆใใใฃใใใจใซ๏ผJใงใฏๅ จใฆใฏๅณ็ตๅใจๆใฃใฆใใใใใฉ๏ผ @ใฎใใใชๆฅ็ถ่ฉใฏไพๅคใใใ ่ฉฐใใใฐ๏ผ็ญใใฏใชใฃใฆใใ๏ผใงใๅใใใซใใใฏ๏ผใชใฃใ
table =: 13 : '(y; ''Fizz''; ''Buzz''; ''FizzBuzz'')'
table
(<;._1 ' Fizz Buzz FizzBuzz') ;~ ]
13 : 'hogehoge'
ใจใใๆ็คบ็ๅฎ็พฉใใใใฐ๏ผๆฐใใๆผ็ฎๅญใๅญฆในใ
table 0
โโโฌโโโโโฌโโโโโฌโโโโโโโโโ
โ0โFizzโBuzzโFizzBuzzโ
โโโดโโโโโดโโโโโดโโโโโโโโโ
table 1
โโโฌโโโโโฌโโโโโฌโโโโโโโโโ
โ1โFizzโBuzzโFizzBuzzโ
โโโดโโโโโดโโโโโดโโโโโโโโโ
fizzbuzz =: idx { table
ใงใใ๏ผ
fizzbuzz"0 (i.6)
โโโโโโโโโโฌโโฌโโฌโโโโโฌโโฌโโโโโ
โFizzBuzzโ1โ2โBuzzโ4โFizzโ
โโโโโโโโโโดโโดโโดโโโโโดโโดโโโโโ
ๆๅญๅใๅ ฅใใใใใซใใใฏในไฝฟใฃใใใฉ Open (ใขใณใใใฏใน)ใใใฎใฏ > ใจใใๆผ็ฎๅญใ ใฃใใฏใ
> fizzbuzz"0 (i.6)
|domain error
| > fizzbuzz"0(i.6)
ใใผ๏ผOpenใฏใใใฏในใใ้ ๅใซใใใใฉ๏ผ้ ๅใฃใฆใฎใฏไธญใฎๅใๆใฃใฆใ ใฎใๅๆใชใฎใ ใฃใ๏ผ
":
ใฏๆดๆฐใๆๅญๅใซๅคๆใใ
table =: 13 : '(": y); ''Fizz''; ''Buzz''; ''FizzBuzz'' '
table
(<;._1 ' Fizz Buzz FizzBuzz') ;~ ":
fizzbuzz 24
Fizz
fizzbuzz"0 (i.6)
FizzBuzz
1
2
Fizz
4
Buzz
ใชใใๅๆใซๆน่กใใใฆ่กจ็คบใใใฆใใฎใๆชใใใใฉ๏ผใงใใ๏ผ
ใใฎ (<;._1 ' Fizz Buzz FizzBuzz') ;~ ":
ใซใคใใฆใฏ
http://www.jsoftware.com/help/dictionary/d331.htm
_1
ใจใใๆฐๅญใซไธ่ฌใฎๆๅณใฏใชใ๏ผ ใใ m ;. _1
ใฎๅ ดๅ๏ผ ' hoge fuga'
ใจใใๆๅญๅใ hoge , fuga
ใซๅๅฒใใฆ๏ผใใใใใซ m ใ้ฉ็จใใฆ่ฟใ๏ผใจใใใ ใใใใ
2013/8/24 (Sat.) ใซไธ้๏ผๅฝ็ซ็งๅญฆๅ็ฉ้คจใงใๆทฑๆตทใใจใใๅฑ็คบใ่ฆใพใใ ใใฎๆฅไปใฏๅนพๅใๆๅณใๆใฃใฆใใใใจใใกใขใใฆใใใพใ
ๆๅณใๅ จใๆใๅบใใชใ.