Skip to content

Instantly share code, notes, and snippets.

@tekkoc
Last active February 8, 2017 04:24
Show Gist options
  • Save tekkoc/9684cf79506f598c5b20929bfbc003ed to your computer and use it in GitHub Desktop.
Save tekkoc/9684cf79506f598c5b20929bfbc003ed to your computer and use it in GitHub Desktop.
ピラミッドっぽいやつ
object Main extends App{
def pir(n: Int): Iterable[String] = {
import scala.math._
for (
i <- (-n to n);
height = n - abs(i)
if (height > 0)
) yield "o" * height
}
for (i <- 0 to 5) {
println(s"pir(${i}):")
pir(i).foreach(println)
}
}
pir(0):
pir(1):
o
pir(2):
o
oo
o
pir(3):
o
oo
ooo
oo
o
pir(4):
o
oo
ooo
oooo
ooo
oo
o
pir(5):
o
oo
ooo
oooo
ooooo
oooo
ooo
oo
o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment