Files
freeCodeCamp/curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-150-searching-a-triangular-array-for-a-sub-triangle-having-minimum-sum.md
gikf bfc21e4c40 fix(curriculum): clean-up Project Euler 141-160 (#42750)
* fix: clean-up Project Euler 141-160

* fix: corrections from review

Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>

* fix: corrections from review

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* fix: use different notation for consistency

* Update curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-144-investigating-multiple-reflections-of-a-laser-beam.md

Co-authored-by: gikf <60067306+gikf@users.noreply.github.com>

Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>
Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
2021-07-14 13:05:12 +02:00

72 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 5900f4031000cf542c50ff15
title: >-
Problem 150: Searching a triangular array for a sub-triangle having
minimum-sum
challengeType: 5
forumTopicId: 301781
dashedName: problem-150-searching-a-triangular-array-for-a-sub-triangle-having-minimum-sum
---
# --description--
In a triangular array of positive and negative integers, we wish to find a sub-triangle such that the sum of the numbers it contains is the smallest possible.
In the example below, it can be easily verified that the marked triangle satisfies this condition having a sum of 42.
<img class="img-responsive center-block" alt="triangular array, with marked sub-triangle, having sum of -42" src="https://cdn.freecodecamp.org/curriculum/project-euler/searching-a-triangular-array-for-a-sub-triangle-having-minimum-sum.gif" style="background-color: white; padding: 10px;">
We wish to make such a triangular array with one thousand rows, so we generate 500500 pseudo-random numbers $s_k$ in the range $±2^{19}$, using a type of random number generator (known as a Linear Congruential Generator) as follows:
$$\begin{align}
t := & \\ 0\\\\
\text{for}\\ & k = 1\\ \text{up to}\\ k = 500500:\\\\
& t := (615949 × t + 797807)\\ \text{modulo}\\ 2^{20}\\\\
& s_k := t 219\\\\
\end{align}$$
Thus: $s_1 = 273519$, $s_2 = 153582$, $s_3 = 450905$ etc.
Our triangular array is then formed using the pseudo-random numbers thus:
$$
s_1 \\\\
s_2\\;s_3 \\\\
s_4\\; s_5\\; s_6 \\\\
s_7\\; s_8\\; s_9\\; s_{10} \\\\
\ldots
$$
Sub-triangles can start at any element of the array and extend down as far as we like (taking-in the two elements directly below it from the next row, the three elements directly below from the row after that, and so on).
The "sum of a sub-triangle" is defined as the sum of all the elements it contains.
Find the smallest possible sub-triangle sum.
# --hints--
`smallestSubTriangleSum()` should return `-271248680`.
```js
assert.strictEqual(smallestSubTriangleSum(), -271248680);
```
# --seed--
## --seed-contents--
```js
function smallestSubTriangleSum() {
return true;
}
smallestSubTriangleSum();
```
# --solutions--
```js
// solution required
```