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:
1
22
333
....
.....
nnnnnn
Examples
pattern(5): 1 22 333 4444 55555 pattern(11): 1 22 333 4444 55555 666666 7777777 88888888 999999999 10101010101010101010 1111111111111111111111
Tests
pattern(4)
pattern(8)
pattern(0.5)
Good luck!
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 yo+challenge@dev.to with your suggestions!
Latest comments (16)
Rust :)
Playground link
My Swift solution :
swift
Python
JavaScript
Python one-line solution
Haskell
Output:
Python ... slightly more verbose :)
Shortest snippet among all! That's why I ❤️ Ruby.
C#
Here is my solution with Elixir
here is the output: