SyntaxHighlighter

Thursday, August 25, 2011

Text-graph

/**
Problem: Given a list of positive Integers and a Char,
print the Char n times per line.
Eg. if I have [1,3,2,5] and '.' I want the output of:
.
...
..
.....
*/

print_chars = { l, c ->
  l.each { n ->
    for (int i = 0; i < n; i++) {
      print c
    }
    println ""
  }
}

// try using it.
print_chars([1,3,2,5], '.')

No comments:

Post a Comment