Implement a function
pattern, which returns the following pattern for up to
n number of rows. If n < 1 then it should return
" " i.e. empty string. There are no whitespaces in the pattern.
pattern(4): 4321 432 43 4 pattern(11): 1110987654321 111098765432 11109876543 1110987654 111098765 11109876 1110987 111098 11109 1110 11
This challenge comes from curious_db97 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!
Top comments (12)
I'm writing this on my phone, so there are probably errors, I'll check it when I have access to a compiler.
Edit: fixed issues after running it through a compiler.
I do a lot of these challgnes on my phone. I use rextester.com/l/haskell_online_com... to test my Haskell code a lot.
Thanks for the tip!
I based my solution on the examples, rather than the explanation.
Python solution 🐍
No new-line at the end.
Java, with the assumption that the function is actually taking an integer, not a float.
Here is a recursive approach using Python
One liner for the above
for i in range(num,0,-1):
print(''.join([str(x) for x in range(num,(num-i),-1)]))