Dirty Nim, planning to rewriting. :)
import math proc diamond(num: int): string = if num < 0: return "" let midPoint = floorDiv(num, 2) for row in 0..num: let distanceFromMid = abs(row - midPoint) let starsInRow = num - distanceFromMid * 2 for col in 0..num: if col >= distanceFromMid + starsInRow or col <= distanceFromMid: result &= " " else: result &= "*" result &= "\n" if isMainModule: const num = 30 echo diamond(num)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Dirty Nim, planning to rewriting. :)