+ 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 */
23 Antworten
+ 14
I may have gone a bit overboard condensing the code so I write this too :)
https://code.sololearn.com/cQbf68JWJ2r7/?ref=app
+ 18
https://code.sololearn.com/cE2ub9tP5iQe/?ref=app
little late but here you go
+ 15
Zero Loops - recurse your brains out!
https://code.sololearn.com/cQ7D9Q6ztyK1/?ref=app
+ 15
1 loop 2 lines
https://code.sololearn.com/cLEXgEKDOxUd/?ref=app
+ 14
Does Mr Stark have an official solution?
+ 13
+ 11
@Kartik very good! its surprises me how little code you need in python to create stuff like this well done
+ 11
Most of problems in Python can be solved in just one line
+ 9
Here's my try in Python
https://code.sololearn.com/cplFLL2k7KwE/?ref=app
+ 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!
+ 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))
+ 8
here's my solution https://code.sololearn.com/c1S2W9Nwtu1z/?ref=app 4 loops
+ 8
@D_Stark I updated my answer. I didn't saw your reference guide when I first uploaded the answer
+ 8
i have tried hard and finally got.....
https://code.sololearn.com/cR2KY70AfVJ1/?ref=app
+ 6
what language is that Kartikey?
+ 5
@D_Stark Python
+ 5
David Ashton's code deserved the best answer!
+ 4
I think it is python...
+ 3
Edit: I've edited my code to match with your output.
+ 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.