Given a positive integer, n, how can a numerical triangle of height n-1 be printed?

Karun Arora
  • HackerRank: Triangle Quest
  • Using only arithmetic operations, a single for-loop, and a single print statement.
  • String operations are not permitted.
  • Constraints 1 ≤ n ≤ 9
  • As an example, given n=5 as input, print the following output:
1
22
333
4444
Lafexlos

Using math, it would be,

Python 2.7:

for i in range(1,n):
    print i*(10**i-1)/9

Check repdigit for more information.

Python 3+

  • Leave or remove int depending if you want .0 or not.
for i in range(1, n):
    print(int(i*(10**i-1)/9))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to print all primes which are not greater than the given positive integer N?

From Dev

Minimal positive integer divisible by n

From Dev

How to find the minimum positive integer in a list of lists in O(n)?

From Dev

Given a positive int n, print “Has 1” if it contains a 1 digit otherwise print “Has No 1”

From Dev

Given n numbers find minimum perimeter triangle

From Java

Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

From Dev

How to write a function that takes a positive integer N and returns a list of the first N natural numbers

From Dev

how do I know what n(positive integer) is when user types ./a.out -n?

From Dev

Define the function squarefact::Int -> Int that computes for any positive integer n the squared factorial (n!)^2 == (1 * ...* n)^2

From Dev

How do I find all positive integer solutions to 7x+2y=n

From Dev

how to represent message as an integer between 1 and n-1?

From Dev

how to represent message as an integer between 1 and n-1?

From Dev

How can ensure that a function only accepts a positive integer?

From Dev

How can ensure that a function only accepts a positive integer?

From Dev

How to print 1,2,3,..N , (N-1) , (N-2) on given amount of integers

From Dev

Maximum sum of 1 to n numbers where the sum should never be equal to given integer k

From Dev

How can I add a \n + a ">" and a numerical header to separate lines every 200 characters?

From Dev

For a given integer Z, check if Z can be written as P^Q where Q and P are positive integers

From Dev

positive iterator design given an integer iterator

From Dev

Given two points (x1,y1) (x2,y2), how can I compute N different points evenly lying on the line between the given points

From Dev

How come the height of recursion tree in merge sort lg(n)+1

From Dev

How come the height of recursion tree in merge sort lg(n)+1

From Dev

Given an integer, w, find n and k such that n^k = w

From Dev

Given N bits, how many integers can be represented in binary?

From Dev

how can n=1 be the parameter of a function

From Dev

How to search the numerical range where a given numerical digit lies in between?

From Dev

How to search the minimum n that 10^n ≡ 1 mod(9x) for given x

From Dev

How to store pow(10,n) integer values in c where n can be <200?

From Dev

Query to print triangle star(asterisk) for given N value in SQL or PL/SQL

Related Related

  1. 1

    How to print all primes which are not greater than the given positive integer N?

  2. 2

    Minimal positive integer divisible by n

  3. 3

    How to find the minimum positive integer in a list of lists in O(n)?

  4. 4

    Given a positive int n, print “Has 1” if it contains a 1 digit otherwise print “Has No 1”

  5. 5

    Given n numbers find minimum perimeter triangle

  6. 6

    Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

  7. 7

    How to write a function that takes a positive integer N and returns a list of the first N natural numbers

  8. 8

    how do I know what n(positive integer) is when user types ./a.out -n?

  9. 9

    Define the function squarefact::Int -> Int that computes for any positive integer n the squared factorial (n!)^2 == (1 * ...* n)^2

  10. 10

    How do I find all positive integer solutions to 7x+2y=n

  11. 11

    how to represent message as an integer between 1 and n-1?

  12. 12

    how to represent message as an integer between 1 and n-1?

  13. 13

    How can ensure that a function only accepts a positive integer?

  14. 14

    How can ensure that a function only accepts a positive integer?

  15. 15

    How to print 1,2,3,..N , (N-1) , (N-2) on given amount of integers

  16. 16

    Maximum sum of 1 to n numbers where the sum should never be equal to given integer k

  17. 17

    How can I add a \n + a ">" and a numerical header to separate lines every 200 characters?

  18. 18

    For a given integer Z, check if Z can be written as P^Q where Q and P are positive integers

  19. 19

    positive iterator design given an integer iterator

  20. 20

    Given two points (x1,y1) (x2,y2), how can I compute N different points evenly lying on the line between the given points

  21. 21

    How come the height of recursion tree in merge sort lg(n)+1

  22. 22

    How come the height of recursion tree in merge sort lg(n)+1

  23. 23

    Given an integer, w, find n and k such that n^k = w

  24. 24

    Given N bits, how many integers can be represented in binary?

  25. 25

    how can n=1 be the parameter of a function

  26. 26

    How to search the numerical range where a given numerical digit lies in between?

  27. 27

    How to search the minimum n that 10^n ≡ 1 mod(9x) for given x

  28. 28

    How to store pow(10,n) integer values in c where n can be <200?

  29. 29

    Query to print triangle star(asterisk) for given N value in SQL or PL/SQL

HotTag

Archive