+ 19

Draw this triangle [CHALLANGE]

/*Using loops and ternary create this pattern. . ... ...... .......... --------------- --------------------- --------------- .......... ...... ... . Each loop adds all the previous loops upto 7 then does the same in reverse by subtracting. The one who creates this with the least amount of loops wins and gets a ✅. ☺ Reference guide 0 = 0 0+1 = 1 0+1+2 = 3 0+1+2+3 = 6 0+1+2+3+4 = 10 0+1+2+3+4+5 = 15 0+1+2+3+4+5+6 = 21 0+1+2+3+4+5 = 15 0+1+2+3+4 = 10 0+1+2+3 = 6 0+1+2 = 3 0+1 = 1 0 = 0 */

11th Nov 2017, 9:23 PM
D_Stark
D_Stark - avatar
23 Answers
+ 14
I may have gone a bit overboard condensing the code so I write this too :) https://code.sololearn.com/cQbf68JWJ2r7/?ref=app
13th Nov 2017, 8:15 AM
David Ashton
David Ashton - avatar
+ 18
https://code.sololearn.com/cE2ub9tP5iQe/?ref=app little late but here you go
12th Nov 2017, 3:52 PM
jay
jay - avatar
+ 15
Zero Loops - recurse your brains out! https://code.sololearn.com/cQ7D9Q6ztyK1/?ref=app
12th Nov 2017, 3:55 PM
Louis
Louis - avatar
13th Nov 2017, 5:20 AM
David Ashton
David Ashton - avatar
+ 14
Does Mr Stark have an official solution?
12th Nov 2017, 4:31 PM
jay
jay - avatar
12th Nov 2017, 2:13 PM
LukArToDo
LukArToDo - avatar
+ 11
@Kartik very good! its surprises me how little code you need in python to create stuff like this well done
12th Nov 2017, 12:53 PM
D_Stark
D_Stark - avatar
+ 11
Most of problems in Python can be solved in just one line
12th Nov 2017, 12:56 PM
Kartikey Sahu
Kartikey Sahu - avatar
12th Nov 2017, 11:58 AM
Kartik
Kartik - avatar
+ 9
Thanks for trying this guys i hope you liked my very difficult decision 😰 i thought i would use simplicity over complexity to help me make this decision as they were all amazing and id tick them all if i could but i just wanted to choose one that was the closest to what i expected and i feel like @David Ashton had the upper edge. This decision had nothing to do with us having the same first name by the way haha 😜 Thank you all keep being amazing!
13th Nov 2017, 6:40 PM
D_Stark
D_Stark - avatar
+ 8
n, k = 7, [] for i in range(2*n-1): if i < n: k.append(i+1) else: del k[-1] print('#'*sum(k))
12th Nov 2017, 2:16 AM
Kartikey Sahu
Kartikey Sahu - avatar
12th Nov 2017, 10:11 AM
Stoyan Todorov
Stoyan Todorov - avatar
+ 8
@D_Stark I updated my answer. I didn't saw your reference guide when I first uploaded the answer
12th Nov 2017, 12:57 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 8
i have tried hard and finally got..... https://code.sololearn.com/cR2KY70AfVJ1/?ref=app
12th Nov 2017, 6:22 PM
SAKSHI
SAKSHI - avatar
+ 6
what language is that Kartikey?
12th Nov 2017, 9:15 AM
D_Stark
D_Stark - avatar
+ 5
@D_Stark Python
12th Nov 2017, 11:41 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 5
David Ashton's code deserved the best answer!
13th Nov 2017, 6:44 PM
Kartik
Kartik - avatar
+ 4
I think it is python...
12th Nov 2017, 9:59 AM
Avi Rzayev
Avi Rzayev - avatar
+ 3
Edit: I've edited my code to match with your output.
12th Nov 2017, 5:20 PM
Kartik
Kartik - avatar
+ 3
One loop in java https://code.sololearn.com/cyfKl45f5kEg/#java Woops! I didn't initially notice that some lines were dots, not dashes! I have made the necessary changes.
12th Nov 2017, 10:40 PM
Bill Fisher