ReasonML / OCaml
Runnable example: sketch.sh/s/RvRBbbn6iqnEIumBYs7UwE/
type parity = | Even | Odd; let testEven = value => value mod 2 == 0 ? Even : Odd; let rec createDiamond = (~middleStars, ~shape=[], ~i=1, ()) => { switch (testEven(middleStars)) { | Even => None | Odd => switch (middleStars - i) { | 0 => Some( [List.rev(shape), [String.make(middleStars, '*')], shape] |> List.flatten |> String.concat("\n"), ) | _ => let padding = (middleStars - i) / 2; let row = Bytes.make(middleStars, ' '); Bytes.fill(row, padding, i, '*'); let shape = [Bytes.to_string(row), ...shape]; createDiamond(~middleStars, ~i=i + 2, ~shape, ()); } }; }; switch (createDiamond(~middleStars=11, ())) { | None => () | Some(d) => print_string(d) };
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.
ReasonML / OCaml
Runnable example: sketch.sh/s/RvRBbbn6iqnEIumBYs7UwE/