Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2017 01:56
Show Gist options
  • Save anonymous/4ffcc8439f0bf641aeaa189cb21c7b2a to your computer and use it in GitHub Desktop.
Save anonymous/4ffcc8439f0bf641aeaa189cb21c7b2a to your computer and use it in GitHub Desktop.
Attempt at Diamond Kata in Pony
actor Main
new create(env: Env) =>
try
let size: U8 = env.args(1)?.u8()?
let diamond = Diamond(size)?
env.out.print(diamond.render())
end
class Diamond
//let _halfLevels:U8
var _result:String = ""
new create(size:U8)? =>
if size == 0 then error end
let halfLevels = size
let width = halfLevels
if halfLevels == 1 then
_result = "A"
return
end
var i:U8 = 0
while i < halfLevels do
_result.append(_spaces(i))
_result.append("B").append("\n")
i = i + 1
end
fun render():String =>
_result
fun _spaces(number:U8):String =>
var spaces = String(number.usize())
var i:U8 = 0
while i < number do
spaces.append("_")
i = i + 1
end
spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment