Baklava in Granule

Published on 01 January 2025 (Updated: 01 January 2025)

Welcome to the Baklava in Granule page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

import Bool

repeatString : Int -> String[] -> String
repeatString 0 [str] = "";
repeatString times [str] = str `stringAppend` (repeatString (times - 1) [str])

numSpaces : Int[] -> Int
numSpaces [n] = if n < 0 then 0 - n else n

numStars : Int[] -> Int
numStars [n] = 21 - 2 * numSpaces [n]

baklavaLine : Int[] -> String
baklavaLine [n] =
    (repeatString (numSpaces [n]) [" "]) `stringAppend` (repeatString (numStars [n]) ["*"]) `stringAppend` "\n"

baklava : String[] -> Int[] -> Int[] -> String
baklava [lines] [n] [ne] =
    if n <= ne then
        lines `stringAppend` (baklavaLine [n]) `stringAppend` (baklava [lines] [n + 1] [ne])
    else
        lines

main : () <{Stdout}>
main = toStdout (baklava [""] [-10] [10])

Baklava in Granule was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.