Well the question might seem to be very easy i.e. to print a star pattern like
1
22
333
4444
For an input of 5
But the trick is that we have to make this pattern only by completing the following lines of code:
for i in range (1,input()):
print {Here goes the code}
Code can not extend more than 2 lines
Numbers of the form
x
repeatedy
times are called repdigits. You can produce such a number simply by calculation. The challenge simplified this by asking you to produce repdigits wherex == y
;y
repeats of the digity
.You can produce a repeated
1
,y
times with the formula(10 ** y - 1) / 9
; ten to the powery
produces a1
withy
zeros. Subtract 1 and you havey
nines. Divide that by9
to gety
ones:Now all you have to do is multiply this by
y
to gety
repeatedy
digits:Now you have a formula for producing a repdigit for any given
y
:No string operations needed; all that is needed is arithmetic operators.
Demo: