[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hi /g/ Time for a simple programming challenge Make a program

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 1

File: 1326390384199.png (38KB, 642x537px) Image search: [Google]
1326390384199.png
38KB, 642x537px
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 friend
def 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 counters

tree = (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] ]
Thread posts: 11
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.