Files
gikf 67de105117 fix(curriculum): clean-up Project Euler 241-260 (#42879)
* fix: clean-up Project Euler 241-260

* fix: typo

* Update curriculum/challenges/english/10-coding-interview-prep/project-euler/problem-255-rounded-square-roots.md

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
2021-07-16 12:21:45 +02:00

69 lines
2.4 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: 5900f4601000cf542c50ff72
title: 'Problem 244: Sliders'
challengeType: 5
forumTopicId: 301891
dashedName: problem-244-sliders
---
# --description--
You probably know the game Fifteen Puzzle. Here, instead of numbered tiles, we have seven red tiles and eight blue tiles.
A move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration ($S$), by the sequence $LULUR$ we reach the configuration ($E$):
($S$) <img class="img-responsive" alt="configuration S" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-1.gif" style="display: inline-block; background-color: white; padding: 10px;">, ($E$) <img class="img-responsive" alt="configuration E" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-2.gif" style="display: inline-block; background-color: white; padding: 10px;">
For each path, its checksum is calculated by (pseudocode):
$$\begin{align}
& \text{checksum} = 0 \\\\
& \text{checksum} = (\text{checksum} × 243 + m_1) \\; \text{mod} \\; 100\\,000\\,007 \\\\
& \text{checksum} = (\text{checksum} × 243 + m_2) \\; \text{mod} \\; 100\\,000\\,007 \\\\
& \ldots \\\\
& \text{checksum} = (\text{checksum} × 243 + m_n) \\; \text{mod} \\; 100\\,000\\,007
\end{align}$$
where $m_k$ is the ASCII value of the $k^{\text{th}}$ letter in the move sequence and the ASCII values for the moves are:
$$\begin{array}{|c|c|}
\hline
L & 76 \\\\ \hline
R & 82 \\\\ \hline
U & 85 \\\\ \hline
D & 68 \\\\ \hline
\end{array}$$
For the sequence $LULUR$ given above, the checksum would be 19761398. Now, starting from configuration ($S$), find all shortest ways to reach configuration ($T$).
($S$) <img class="img-responsive center-block" alt="configuration S" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-3.gif" style="display: inline-block; background-color: white; padding: 10px;">, ($T$) <img class="img-responsive center-block" alt="configuration T" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliders-4.gif" style="display: inline-block; background-color: white; padding: 10px;">
What is the sum of all checksums for the paths having the minimal length?
# --hints--
`sliders()` should return `96356848`.
```js
assert.strictEqual(sliders(), 96356848);
```
# --seed--
## --seed-contents--
```js
function sliders() {
return true;
}
sliders();
```
# --solutions--
```js
// solution required
```