3

Given this triangular:
$$1$$ $$2,3$$ $$4,5,6$$ $$7,8,9,10$$ $$.............$$

Now, how can i calculate the height of number of some number in this triangular? (Namely, how can i find formula for the height of $n$?)

5 Answers5

4

For a given value $n$ there exist $h$ such that \begin{eqnarray*} \frac{h(h-1)}{2} < n \leq \frac{h(h+1)}{2}. \end{eqnarray*} Now treat the the right hand in equality as a quadratic in $h$ and solve to get \begin{eqnarray*} h = \left\lceil \frac{-1 + \sqrt{1+8n}}{2} \right\rceil. \end{eqnarray*}

Donald Splutterwit
  • 36,613
  • 2
  • 26
  • 73
  • How it's give the line of n? – Master Question Dec 20 '17 at 15:44
  • The answer is good, but I think it may be confusing to OP because it uses the symbol $n$ differently than in the question. In the question, $n$ is a known value and the unknown value to be found is its unnamed "height". This answer uses $m$ as the name of the known value and $n$ as the unknown value to be found. It might help if the notation were consistent with the question and were carefully defined (i.e., say which variable is the "number" and which is the "height"). – David K Dec 24 '17 at 16:25
  • @DavidK Thanks for the comment; I have changed the variable names. & thanks for getting the lciel & rciel to look right $ \ddot \smile$ – Donald Splutterwit Dec 24 '17 at 20:19
0

The first entry in the $n$-th row is $\frac{n(n-1)}{2}+1$ and the last is $\frac{n(n+1)}{2}$ so in order to find the row of the number $x$ you have to find $n$ such that

$$\frac{n(n-1)}{2}+1 \leq x \leq \frac{n(n+1)}{2}$$

asdf
  • 4,587
0

Pointers:

  • There are $n$ numbers in row $n$.

  • The last number of the $n^{\text{th}}$ row is $\dfrac {n(n+1)}{2}$.

  • The first number in the $n^{\text{th}}$ row is $\dfrac{n(n-1)}{2}+1$.

To calculate the row in which any number $x$ lies, just check the triangular number nearest to it and bigger than it, and it lies in the row number $n$ corresponding to that triangular number.

  • It's not clear how you get the line from this, can you explain me it? – Master Question Dec 20 '17 at 15:46
  • @MasterQuestion See the last number in every row. You can see that it is the nth triangular number. Now, the first number in the row is the (n-1)th triangular number +1. So, a Number has to lie between this range only. –  Dec 20 '17 at 16:04
  • @MasterQuestion Now, the upper bound for a number to be in the nth row is the nth triangular number. So, we check using this criteria itself. –  Dec 20 '17 at 16:05
  • @MasterQuestion Hence, given a number $x$ we check the closest triangular number to x and bigger than it. It will correspond to some row n because the nth triangular number is n(n+1)/2. Then, we can conclude that $x$ will also be in row $n$. –  Dec 20 '17 at 16:06
  • @MasterQuestion You can accept my answer if it helped you. –  Dec 21 '17 at 09:40
0

To find the row that $n$ is on, double $n$, take the square root, and find the nearest integer.

gandalf61
  • 15,326
0

Define a function $h(m)$ recursively:

$h(1) = 1$

Let $h(m)$ be defined.

If $m + 1 \le \dfrac {h(m)(h(m)+1)}{2}$ then $h(m+1) = h(m)$
else
$\qquad \qquad \qquad \qquad \qquad \qquad \qquad \, h(m+1) = h(m) + 1$


This doesn't provide an explicit formula, but I'm pretty sure that a few lines of code in a (suitable) programming language will do the trick. So that is reassuring.

OK, here is some code. I got some help from python experts; see this stackoverflow Q/A link. Note that this code also gives the row position of each number:

def daHB(m):
    if m == 1:
        return {'rowNum':1, 'posNum':1, 'TriNum':1}
    else:
        r = daHB(m-1)
        if m <= r['TriNum']:
            return {'rowNum':r['rowNum'], 'posNum':r['posNum'] + 1, 'TriNum':r['TriNum']}
        else:
            TriangularNum = (r['rowNum']+1)*(r['rowNum']+2)  // 2
            return {'rowNum':r['rowNum'] + 1,'posNum':1, 'TriNum':TriangularNum}

for n in range(1, 33):
    print (n, daHB(n))

OUTPUT

1 {'rowNum': 1, 'posNum': 1, 'TriNum': 1}
2 {'rowNum': 2, 'posNum': 1, 'TriNum': 3}
3 {'rowNum': 2, 'posNum': 2, 'TriNum': 3}
4 {'rowNum': 3, 'posNum': 1, 'TriNum': 6}
5 {'rowNum': 3, 'posNum': 2, 'TriNum': 6}
6 {'rowNum': 3, 'posNum': 3, 'TriNum': 6}
7 {'rowNum': 4, 'posNum': 1, 'TriNum': 10}
8 {'rowNum': 4, 'posNum': 2, 'TriNum': 10}
9 {'rowNum': 4, 'posNum': 3, 'TriNum': 10}
10 {'rowNum': 4, 'posNum': 4, 'TriNum': 10}
11 {'rowNum': 5, 'posNum': 1, 'TriNum': 15}
12 {'rowNum': 5, 'posNum': 2, 'TriNum': 15}
13 {'rowNum': 5, 'posNum': 3, 'TriNum': 15}
14 {'rowNum': 5, 'posNum': 4, 'TriNum': 15}
15 {'rowNum': 5, 'posNum': 5, 'TriNum': 15}
16 {'rowNum': 6, 'posNum': 1, 'TriNum': 21}
17 {'rowNum': 6, 'posNum': 2, 'TriNum': 21}
18 {'rowNum': 6, 'posNum': 3, 'TriNum': 21}
19 {'rowNum': 6, 'posNum': 4, 'TriNum': 21}
20 {'rowNum': 6, 'posNum': 5, 'TriNum': 21}
21 {'rowNum': 6, 'posNum': 6, 'TriNum': 21}
22 {'rowNum': 7, 'posNum': 1, 'TriNum': 28}
23 {'rowNum': 7, 'posNum': 2, 'TriNum': 28}
24 {'rowNum': 7, 'posNum': 3, 'TriNum': 28}
25 {'rowNum': 7, 'posNum': 4, 'TriNum': 28}
26 {'rowNum': 7, 'posNum': 5, 'TriNum': 28}
27 {'rowNum': 7, 'posNum': 6, 'TriNum': 28}
28 {'rowNum': 7, 'posNum': 7, 'TriNum': 28}
29 {'rowNum': 8, 'posNum': 1, 'TriNum': 36}
30 {'rowNum': 8, 'posNum': 2, 'TriNum': 36}
31 {'rowNum': 8, 'posNum': 3, 'TriNum': 36}
32 {'rowNum': 8, 'posNum': 4, 'TriNum': 36}
CopyPasteIt
  • 11,366