Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My:
- import scala.collection.mutable.ListBuffer
- object Kata {
- def pyramid(n: Int): List[List[Int]] = {
- val arr =ListBuffer.empty[List[Int]]
- def fulling( index: Int=0): List[List[Int]]={
- if(n==0) {arr+=List.empty[Int]
- arr.remove(0)
- arr.toList}
- else if(index<=n) {arr+=List.fill(index)(1)
- fulling(index+1)}
- else arr.remove(0)
- arr.toList
- }
- fulling()
- }
- }
- Other:
- object Kata {
- def pyramid(n: Int): List[List[Int]] =
- List.tabulate(n)(i => List.fill(i+1)(1))
- }
- object Kata {
- def pyramid(n: Int): List[List[Int]] = {
- (1 to n).map(List.fill(_)(1)).toList
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement