Skip to content

Instantly share code, notes, and snippets.

@barmic
Created December 3, 2019 13:08
Show Gist options
  • Save barmic/9f2100c46391ca7182569250fa1911d5 to your computer and use it in GitHub Desktop.
Save barmic/9f2100c46391ca7182569250fa1911d5 to your computer and use it in GitHub Desktop.
sub MAIN ($length){say (1...$length).map({("*" x $length).comb.join("_").subst(/\*_/," ", :x($length-$_))}).join("\n")}
sub step($line) {
say $line;
$line ~~ /\s/ && step($line.subst(/\s(\S)/,{"*_$0"}));
}
step(" " x 10 ~ "*");
func arbreDeNoel(n: UInt, indentation: String = "") -> String {
switch n {
case 1:
return printArbre(branche: "*", indentation: indentation)
default:
return printArbre(branche: arbreDeNoel(n: n - 1, indentation: indentation + " ") + "_*", indentation: indentation)
}
}
func printArbre(branche: String, indentation: String) -> String {
print(indentation + branche)
return branche
}
arbreDeNoel(n: 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment