Hi /g/
Time for a simple programming challenge
Make a program that prints a christmas tree for a given height, like so:
N = 5
*
***
*****
*******
*********
*
N = 7
*
***
*****
*******
*********
***********
*************
*
not doing you're home work kid
Respond
Or
Your
Mother
D
In
Her
Sleep
Tonight
>>60405832
Here is my version frienddef main():
branches = '*'
tree_height = int(input('Tree height: '))
for i in range(tree_height):
print(branches)
branches += '**'
print('*')
main()
>>60405804
>dpt explained
Try the dpttxt twitter for a curated shitpost collection
public void printTree(int n){
int a=1;
for(int i=0 i<n; i++){
for(int j=0; j<a; j++) {
System.out.print("*");
}
System.out.println("");
a += 2;
}
System.out.print("*");
}
height = int(raw_input("Input tree height: "))
branch = '*'
for i in range(0, height + height):
if i % 2 == 0:
pass
else:
print branch * i
print branch
>inb4 >python
Literally the first assignment in harvard cs50, except it has to be right aligned.
>>60405804
Here ya go:package main
import "fmt"
func main() {
height := 8
for i := 0; i < height-1; i++ {
fmt.Print("#")
for i1 := 0; i1 < i; i1++ {
fmt.Print("#")
}
fmt.Println()
}
fmt.Println("#")
}
>>60405804
>unironically using counterstree = (h) => {
return '*'
.repeat(h)
.split('')
.map((e,i) => {
return (i>0 ? '\n' : '') + e.repeat(2*i + 1);
})
.join('') + '\n*';
}
console.log(tree(5));
def tree(h)
puts (1..h).map{|i| "*"*i}.push("*")
end
stars n = foldr (\x y -> "*':y) "\n" [1..n]
tree n = putStrLn $ concat $ [ stars x | x <- [1..n] ]