chore(i18n,learn): processed translations (#45165)

This commit is contained in:
camperbot
2022-02-19 12:56:08 +05:30
committed by GitHub
parent 8138a07d52
commit ba14990876
134 changed files with 1540 additions and 1511 deletions

View File

@ -23,7 +23,7 @@ myTest();
console.log(loc); console.log(loc);
``` ```
La chiamata alla funzione `myTest()` mostrerà la stringa `foo` nella console. La linea `console.log(loc)` genererà un errore, perché `loc` non è definita al di fuori della funzione. La chiamata alla funzione `myTest()` mostrerà la stringa `foo` nella console. La riga `console.log(loc)` (al di fuori della funzione `myTest`) lancerà un errore visto che `loc` non è definito al di fuori della funzione.
# --instructions-- # --instructions--

View File

@ -21,7 +21,7 @@ console.log(typeof {});
Nell'ordine, la console visualizzerà le stringhe `string`, `number`, `object`, e `object`. Nell'ordine, la console visualizzerà le stringhe `string`, `number`, `object`, e `object`.
JavaScript riconosce sei tipi di dati primitivi (immutabili): `Boolean`, `Null`, `Undefined`, `Number`, `String`, e `Symbol` (introdotto con ES6) e un tipo per gli oggetti mutabili: `Object`. Nota che in JavaScript, gli array sono tecnicamente un tipo di oggetto. JavaScript riconosce sette tipi di dati primitivi (immutabili): `Boolean`, `Null`, `Undefined`, `Number`, `String`, `Symbol` (introdotto con ES6), e `BigInt` (introdotto con ES2020), e un tipo per gli oggetti mutabili: `Object`. Nota che in JavaScript, gli array sono tecnicamente un tipo di oggetto.
# --instructions-- # --instructions--

View File

@ -60,6 +60,12 @@ assert.isUndefined(addTogether(2, '3'));
assert.isUndefined(addTogether(2)([3])); assert.isUndefined(addTogether(2)([3]));
``` ```
`addTogether("2", 3)` dovrebbe restituire `undefined`.
```js
assert.isUndefined(addTogether('2', 3));
```
# --seed-- # --seed--
## --seed-contents-- ## --seed-contents--

View File

@ -49,7 +49,24 @@ assert.sameMembers(
); );
``` ```
Il grafo di input `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` con un nodo di partenza di `1` dovrebbe restituire un array con quattro elementi. Il grafo di input `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` con un nodo iniziale di `3` dovrebbe restituire un array con `3`, `2`, `1`, e `0`.
```js
assert.sameMembers(
(function () {
var graph = [
[0, 1, 0, 0],
[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 0]
];
return dfs(graph, 3);
})(),
[3, 2, 1, 0]
);
```
Il grafo di input `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` con un nodo iniziale di `1` dovrebbe restiture un array con quattro elementi.
```js ```js
assert( assert(
@ -65,7 +82,7 @@ assert(
); );
``` ```
Il grafo di input `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` con un nodo di partenza di `3` dovrebbe restituire un array con `3`. Il grafo di input `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` con un nodo iniziale di `3` dovrebbe restituire un array con `3`.
```js ```js
assert.sameMembers( assert.sameMembers(

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3761000cf542c50fe89 id: 5900f3761000cf542c50fe89
title: 'Problem 10: Summation of primes' title: 'Problema 10: Somma dei numeri primi'
challengeType: 5 challengeType: 5
forumTopicId: 301723 forumTopicId: 301723
dashedName: problem-10-summation-of-primes dashedName: problem-10-summation-of-primes
@ -8,37 +8,37 @@ dashedName: problem-10-summation-of-primes
# --description-- # --description--
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. La somma dei numeri primi sotto 10 è 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below `n`. Trova la somma di tutti i numeri primi sotto `n`.
# --hints-- # --hints--
`primeSummation(17)` should return a number. `primeSummation(17)` dovrebbe restituire un numero.
```js ```js
assert(typeof primeSummation(17) === 'number'); assert(typeof primeSummation(17) === 'number');
``` ```
`primeSummation(17)` should return 41. `primeSummation(17)` dovrebbe restituire 41.
```js ```js
assert.strictEqual(primeSummation(17), 41); assert.strictEqual(primeSummation(17), 41);
``` ```
`primeSummation(2001)` should return 277050. `primeSummation(2001)` dovrebbe ritornare 277050.
```js ```js
assert.strictEqual(primeSummation(2001), 277050); assert.strictEqual(primeSummation(2001), 277050);
``` ```
`primeSummation(140759)` should return 873608362. `primeSummation(140759)` dovrebbe restituire 873608362.
```js ```js
assert.strictEqual(primeSummation(140759), 873608362); assert.strictEqual(primeSummation(140759), 873608362);
``` ```
`primeSummation(2000000)` should return 142913828922. `primeSummation(2000000)` dovrebbe restituire 142913828922.
```js ```js
assert.strictEqual(primeSummation(2000000), 142913828922); assert.strictEqual(primeSummation(2000000), 142913828922);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3781000cf542c50fe8a id: 5900f3781000cf542c50fe8a
title: 'Problem 11: Largest product in a grid' title: 'Problema 11: Prodotto più grande nella griglia'
challengeType: 5 challengeType: 5
forumTopicId: 301734 forumTopicId: 301734
dashedName: problem-11-largest-product-in-a-grid dashedName: problem-11-largest-product-in-a-grid
@ -8,7 +8,7 @@ dashedName: problem-11-largest-product-in-a-grid
# --description-- # --description--
In the 20×20 grid below, four numbers along a diagonal line have been marked in red. Nella griglia 20×20 qui sotto, quattro numeri lungo una linea diagonale sono stati contrassegnati in rosso.
<div style='text-align: center;'> <div style='text-align: center;'>
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08<br> 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08<br>
@ -33,25 +33,25 @@ In the 20×20 grid below, four numbers along a diagonal line have been marked in
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48<br> 01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48<br>
</div> </div>
The product of these numbers is 26 × 63 × 78 × 14 = 1788696. Il prodotto di questi numeri è 26 × 63 × 78 × 14 = 1788696.
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in a given `arr` grid? Qual è il prodotto più grande di quattro numeri adiacenti nella stessa direzione (su, giù, sinistra, destra, o diagonalmente) in una griglia `arr` data?
# --hints-- # --hints--
`largestGridProduct(testGrid)` should return a number. `largestGridProduct(testGrid)` dovrebbe restituire un numero.
```js ```js
assert(typeof largestGridProduct(testGrid) === 'number'); assert(typeof largestGridProduct(testGrid) === 'number');
``` ```
`largestGridProduct(testGrid)` should return 14169081. `largestGridProduct(testGrid)` dovrebbe restituire 14169081.
```js ```js
assert.strictEqual(largestGridProduct(testGrid), 14169081); assert.strictEqual(largestGridProduct(testGrid), 14169081);
``` ```
`largestGridProduct(grid)` should return 70600674. `largestGridProduct(grid)` dovrebbe restituire 70600674.
```js ```js
assert.strictEqual(largestGridProduct(grid), 70600674); assert.strictEqual(largestGridProduct(grid), 70600674);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3781000cf542c50fe8b id: 5900f3781000cf542c50fe8b
title: 'Problem 12: Highly divisible triangular number' title: 'Problema 12: Numero triangolare altamente divisibile'
challengeType: 5 challengeType: 5
forumTopicId: 301746 forumTopicId: 301746
dashedName: problem-12-highly-divisible-triangular-number dashedName: problem-12-highly-divisible-triangular-number
@ -8,11 +8,11 @@ dashedName: problem-12-highly-divisible-triangular-number
# --description-- # --description--
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: La sequenza di numeri triangolari è generata sommando i numeri naturali. Quindi il numero del 7° triangolo sarebbe 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. I primi dieci termini saranno:
<div style='text-align: center;'>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...</div> <div style='text-align: center;'>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...</div>
Let us list the factors of the first seven triangle numbers: Elenchiamo i fattori dei primi sette numeri triangolari:
<div style='padding-left: 4em;'><b>1:</b> 1</div> <div style='padding-left: 4em;'><b>1:</b> 1</div>
<div style='padding-left: 4em;'><b>3:</b> 1, 3</div> <div style='padding-left: 4em;'><b>3:</b> 1, 3</div>
@ -22,43 +22,43 @@ Let us list the factors of the first seven triangle numbers:
<div style='padding-left: 4em;'><b>21:</b> 1, 3, 7, 21</div> <div style='padding-left: 4em;'><b>21:</b> 1, 3, 7, 21</div>
<div style='padding-left: 4em;'><b>28:</b> 1, 2, 4, 7, 14, 28</div> <div style='padding-left: 4em;'><b>28:</b> 1, 2, 4, 7, 14, 28</div>
We can see that 28 is the first triangle number to have over five divisors. Possiamo vedere che 28 è il primo numero triangolare ad avere più di cinque divisori.
What is the value of the first triangle number to have over `n` divisors? Qual è il valore del primo numero triangolare che ha oltre `n` divisori?
# --hints-- # --hints--
`divisibleTriangleNumber(5)` should return a number. `divisibleTriangleNumber(5)` dovrebbe restituire un numero.
```js ```js
assert(typeof divisibleTriangleNumber(5) === 'number'); assert(typeof divisibleTriangleNumber(5) === 'number');
``` ```
`divisibleTriangleNumber(5)` should return 28. `divisibleTriangleNumber(5)` dovrebbe restituire 28.
```js ```js
assert.strictEqual(divisibleTriangleNumber(5), 28); assert.strictEqual(divisibleTriangleNumber(5), 28);
``` ```
`divisibleTriangleNumber(23)` should return 630. `divisibleTriangleNumber(23)` dovrebbe restituire 630.
```js ```js
assert.strictEqual(divisibleTriangleNumber(23), 630); assert.strictEqual(divisibleTriangleNumber(23), 630);
``` ```
`divisibleTriangleNumber(167)` should return 1385280. `divisibleTriangleNumber(167)` dovrebbe restituire 1385280.
```js ```js
assert.strictEqual(divisibleTriangleNumber(167), 1385280); assert.strictEqual(divisibleTriangleNumber(167), 1385280);
``` ```
`divisibleTriangleNumber(374)` should return 17907120. `divisibleTriangleNumber(374)` dovrebbe restituire 17907120.
```js ```js
assert.strictEqual(divisibleTriangleNumber(374), 17907120); assert.strictEqual(divisibleTriangleNumber(374), 17907120);
``` ```
`divisibleTriangleNumber(500)` should return 76576500. `divisibleTriangleNumber(500)` dovrebbe restituire 76576500.
```js ```js
assert.strictEqual(divisibleTriangleNumber(500), 76576500); assert.strictEqual(divisibleTriangleNumber(500), 76576500);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37a1000cf542c50fe8c id: 5900f37a1000cf542c50fe8c
title: 'Problem 13: Large sum' title: 'Problema 13: Grande somma'
challengeType: 5 challengeType: 5
forumTopicId: 301757 forumTopicId: 301757
dashedName: problem-13-large-sum dashedName: problem-13-large-sum
@ -8,7 +8,7 @@ dashedName: problem-13-large-sum
# --description-- # --description--
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. Ottieni le prime 10 cifre della somma dei seguenti cento numeri a 50 cifre.
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
37107287533902102798797998220837590246510135740250<br> 37107287533902102798797998220837590246510135740250<br>
@ -115,19 +115,19 @@ Work out the first ten digits of the sum of the following one-hundred 50-digit n
# --hints-- # --hints--
`largeSum(testNums)` should return a number. `largeSum(testNums)` dovrebbe restituire un numero.
```js ```js
assert(typeof largeSum(testNums) === 'number'); assert(typeof largeSum(testNums) === 'number');
``` ```
`largeSum(testNums)` should return 8348422521. `largeSum(testNums)` dovrebbe restituire 8348422521.
```js ```js
assert.strictEqual(largeSum(testNums), 8348422521); assert.strictEqual(largeSum(testNums), 8348422521);
``` ```
`largeSum(fiftyDigitNums)` should return 5537376230. `largeSum(fiftyDigitNums)` dovrebbe restituire 5537376230.
```js ```js
assert.strictEqual(largeSum(fiftyDigitNums), 5537376230); assert.strictEqual(largeSum(fiftyDigitNums), 5537376230);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37a1000cf542c50fe8d id: 5900f37a1000cf542c50fe8d
title: 'Problem 14: Longest Collatz sequence' title: 'Problema 14: la sequenza di Collatz più lunga'
challengeType: 5 challengeType: 5
forumTopicId: 301768 forumTopicId: 301768
dashedName: problem-14-longest-collatz-sequence dashedName: problem-14-longest-collatz-sequence
@ -8,61 +8,61 @@ dashedName: problem-14-longest-collatz-sequence
# --description-- # --description--
The following iterative sequence is defined for the set of positive integers: La seguente sequenza iterativa è definita per il set degli interi positivi:
<div style='padding-left: 4em;'><var>n</var><var>n</var>/2 (<var>n</var> is even)</div> <div style='padding-left: 4em;'><var>n</var><var>n</var>/2 (<var>n</var> è pari)</div>
<div style='padding-left: 4em;'><var>n</var> → 3<var>n</var> + 1 (<var>n</var> is odd)</div> <div style='padding-left: 4em;'><var>n</var> → 3<var>n</var> + 1 (<var>n</var> è dispari)</div>
Using the rule above and starting with 13, we generate the following sequence: Usando le regole qua sopra e iniziando con 13, generiamo la seguente sequenza:
<div style='text-align: center;'>13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1</div> <div style='text-align: center;'>13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1</div>
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. Puoi vedere che questa sequenza (iniziando con 13 e finedno con 1) contiene 10 termini. Anche se non è ancora stato provato (Problema di Collatz), si pensa che con qualsiasi numeri si parta, si finisce a 1.
Which starting number, under the given `limit`, produces the longest chain? Quale numero iniziale, sotto il dato limite `limit`, produce la catena più lunga?
**Note:** Once the chain starts the terms are allowed to go above one million. **Nota:** Una volta che la catena inizia i termini possono superare `limit`.
# --hints-- # --hints--
`longestCollatzSequence(14)` should return a number. `longestCollatzSequence(14)` dovrebbe restituire un numero.
```js ```js
assert(typeof longestCollatzSequence(14) === 'number'); assert(typeof longestCollatzSequence(14) === 'number');
``` ```
`longestCollatzSequence(14)` should return 9. `longestCollatzSequence(14)` dovrebbe restituire 9.
```js ```js
assert.strictEqual(longestCollatzSequence(14), 9); assert.strictEqual(longestCollatzSequence(14), 9);
``` ```
`longestCollatzSequence(5847)` should return 3711. `longestCollatzSequence(5847)` dovrebbe restituire 3711.
```js ```js
assert.strictEqual(longestCollatzSequence(5847), 3711); assert.strictEqual(longestCollatzSequence(5847), 3711);
``` ```
`longestCollatzSequence(46500)` should return 35655. `longestCollatzSequence(46500)` dovrebbe restituire 35655.
```js ```js
assert.strictEqual(longestCollatzSequence(46500), 35655); assert.strictEqual(longestCollatzSequence(46500), 35655);
``` ```
`longestCollatzSequence(54512)` should return 52527. `longestCollatzSequence(54512)` dovrebbe restituire 52527.
```js ```js
assert.strictEqual(longestCollatzSequence(54512), 52527); assert.strictEqual(longestCollatzSequence(54512), 52527);
``` ```
`longestCollatzSequence(100000)` should return 77031. `longestCollatzSequence(100000)` dovrebbe restituire 77031.
```js ```js
assert.strictEqual(longestCollatzSequence(100000), 77031); assert.strictEqual(longestCollatzSequence(100000), 77031);
``` ```
`longestCollatzSequence(1000000)` should return 837799. `longestCollatzSequence(1000000)` dovrebbe restituire 837799.
```js ```js
assert.strictEqual(longestCollatzSequence(1000000), 837799); assert.strictEqual(longestCollatzSequence(1000000), 837799);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37b1000cf542c50fe8e id: 5900f37b1000cf542c50fe8e
title: 'Problem 15: Lattice paths' title: 'Problema 15: Percorsi nel reticolo'
challengeType: 5 challengeType: 5
forumTopicId: 301780 forumTopicId: 301780
dashedName: problem-15-lattice-paths dashedName: problem-15-lattice-paths
@ -8,33 +8,33 @@ dashedName: problem-15-lattice-paths
# --description-- # --description--
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. Iniziando nell'angolo in alto a sinistra di una griglia 2x2, e avendo l'abilità di muoversi solo verso destra e verso il basso, ci sono esattamente 6 strade verso l'angolo in basso a sinistra.
<img class="img-responsive center-block" alt="a diagram of 6 2 by 2 grids showing all the routes to the bottom right corner" src="https://cdn-media-1.freecodecamp.org/project-euler/1Atixoj.gif" style="background-color: white; padding: 10px;" /> <img class="img-responsive center-block" alt="un diagramma di 6 griglie 2 per 2 che mostra tutte le strade per raggiungere l'angolo in basso a destra" src="https://cdn-media-1.freecodecamp.org/project-euler/1Atixoj.gif" style="background-color: white; padding: 10px;" />
How many such routes are there through a given `gridSize`? Quante strade di questo tipo ci sono data la dimensione della griglia `gridSize`?
# --hints-- # --hints--
`latticePaths(4)` should return a number. `latticePaths(4)` dovrebbe restituire un numero.
```js ```js
assert(typeof latticePaths(4) === 'number'); assert(typeof latticePaths(4) === 'number');
``` ```
`latticePaths(4)` should return 70. `latticePaths(4)` dovrebbe restituire 70.
```js ```js
assert.strictEqual(latticePaths(4), 70); assert.strictEqual(latticePaths(4), 70);
``` ```
`latticePaths(9)` should return 48620. `latticePaths(9)` dovrebbe restituire 48620.
```js ```js
assert.strictEqual(latticePaths(9), 48620); assert.strictEqual(latticePaths(9), 48620);
``` ```
`latticePaths(20)` should return 137846528820. `latticePaths(20)` dovrebbe restituire 137846528820.
```js ```js
assert.strictEqual(latticePaths(20), 137846528820); assert.strictEqual(latticePaths(20), 137846528820);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37d1000cf542c50fe8f id: 5900f37d1000cf542c50fe8f
title: 'Problem 16: Power digit sum' title: 'Problema 16: Somma delle cifre della potenza'
challengeType: 5 challengeType: 5
forumTopicId: 301791 forumTopicId: 301791
dashedName: problem-16-power-digit-sum dashedName: problem-16-power-digit-sum
@ -8,31 +8,31 @@ dashedName: problem-16-power-digit-sum
# --description-- # --description--
2<sup>15</sup> = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. 2<sup>15</sup> = 32768 e la somma delle sue cifre è 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2<sup><code>exponent</code></sup>? Qual'è la somma delle cifre del numero 2<sup><code>exponent</code></sup>?
# --hints-- # --hints--
`powerDigitSum(15)` should return a number. `powerDigitSum(15)` dovrebbe restituire un numero.
```js ```js
assert(typeof powerDigitSum(15) === 'number'); assert(typeof powerDigitSum(15) === 'number');
``` ```
`powerDigitSum(15)` should return 26. `powerDigitSum(15)` dovrebbe restituire 26.
```js ```js
assert.strictEqual(powerDigitSum(15), 26); assert.strictEqual(powerDigitSum(15), 26);
``` ```
`powerDigitSum(128)` should return 166. `powerDigitSum(128)` dovrebbe restituire 166.
```js ```js
assert.strictEqual(powerDigitSum(128), 166); assert.strictEqual(powerDigitSum(128), 166);
``` ```
`powerDigitSum(1000)` should return 1366. `powerDigitSum(1000)` dovrebbe restituire 1366.
```js ```js
assert.strictEqual(powerDigitSum(1000), 1366); assert.strictEqual(powerDigitSum(1000), 1366);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37d1000cf542c50fe90 id: 5900f37d1000cf542c50fe90
title: 'Problem 17: Number letter counts' title: 'Problema 17: conteggio delle lettere dei numeri'
challengeType: 5 challengeType: 5
forumTopicId: 301804 forumTopicId: 301804
dashedName: problem-17-number-letter-counts dashedName: problem-17-number-letter-counts
@ -8,33 +8,33 @@ dashedName: problem-17-number-letter-counts
# --description-- # --description--
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. Se i numeri da 1 a 5 fossero scritti in parole in inglese: one, two, three, four, five, allora ci sono 3 + 3 + 5 + 4 + 4 = 19 lettere usate in totale.
If all the numbers from 1 to given `limit` inclusive were written out in words, how many letters would be used? Se tutti i numeri da 1 al dato limite inclusivo `limit` fossero scritti in parole in inglese, quante lettere sarebbero usate?
**Note:** Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage. **Nota:** Non contare gli spazi o i trattini. Per esempio, 342 (three hundred and forty-two) contiene 23 lettere e 115 (one hundred and fifteen) contiene 20 lettere. L'uso di "and" scrivendo i numeri segue l'uso britannico.
# --hints-- # --hints--
`numberLetterCounts(5)` should return a number. `numberLetterCounts(5)` dovrebbe restituire un numero.
```js ```js
assert(typeof numberLetterCounts(5) === 'number'); assert(typeof numberLetterCounts(5) === 'number');
``` ```
`numberLetterCounts(5)` should return 19. `numberLetterCounts(5)` dovrebbe restituire 19.
```js ```js
assert.strictEqual(numberLetterCounts(5), 19); assert.strictEqual(numberLetterCounts(5), 19);
``` ```
`numberLetterCounts(150)` should return 1903. `numberLetterCounts(150)` dovrebbe restituire 1903.
```js ```js
assert.strictEqual(numberLetterCounts(150), 1903); assert.strictEqual(numberLetterCounts(150), 1903);
``` ```
`numberLetterCounts(1000)` should return 21124. `numberLetterCounts(1000)` dovrebbe restituire 21124.
```js ```js
assert.strictEqual(numberLetterCounts(1000), 21124); assert.strictEqual(numberLetterCounts(1000), 21124);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37e1000cf542c50fe91 id: 5900f37e1000cf542c50fe91
title: 'Problem 18: Maximum path sum I' title: 'Problema 18: Somma massima del percorso I'
challengeType: 5 challengeType: 5
forumTopicId: 301815 forumTopicId: 301815
dashedName: problem-18-maximum-path-sum-i dashedName: problem-18-maximum-path-sum-i
@ -8,7 +8,7 @@ dashedName: problem-18-maximum-path-sum-i
# --description-- # --description--
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. Cominciando dalla parte superiore del triangolo sottostante e spostandosi verso i numeri adiacenti sulla riga sottostante, il totale massimo dall'alto al basso è 23.
<span style='display: block; text-align: center;'> <span style='display: block; text-align: center;'>
<strong style='color: red;'>3</strong><br> <strong style='color: red;'>3</strong><br>
@ -17,9 +17,9 @@ By starting at the top of the triangle below and moving to adjacent numbers on t
8 5 <strong style='color: red;'>9</strong> 3 8 5 <strong style='color: red;'>9</strong> 3
</span> </span>
That is, 3 + 7 + 4 + 9 = 23. Cioè, 3 + 7 + 4 + 9 = 23.
Find the maximum total from top to bottom of the triangle below: Trova il totale massimo dall'alto al basso del triangolo qui sotto:
75 75
95 64 95 64
@ -37,23 +37,23 @@ Find the maximum total from top to bottom of the triangle below:
63 66 04 68 89 53 67 30 73 16 69 87 40 31 63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
**NOTE:** As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o) **NOTA:** Poiché ci sono solo 16384 percorsi, è possibile risolvere questo problema provando ogni percorso. Tuttavia, Problema 67, è la stessa sfida con un triangolo contenente cento righe; non può essere risolto a forza bruta, e richiede un metodo intelligente! ;o)
# --hints-- # --hints--
`maximumPathSumI(testTriangle)` should return a number. `maximumPathSumI(testTriangle)` dovrebbe restituire un numero.
```js ```js
assert(typeof maximumPathSumI(testTriangle) === 'number'); assert(typeof maximumPathSumI(testTriangle) === 'number');
``` ```
`maximumPathSumI(testTriangle)` should return 23. `maximumPathSumI(testTriangle)` dovrebbe restituire 23.
```js ```js
assert.strictEqual(maximumPathSumI(testTriangle), 23); assert.strictEqual(maximumPathSumI(testTriangle), 23);
``` ```
`maximumPathSumI(numTriangle)` should return 1074. `maximumPathSumI(numTriangle)` dovrebbe restituire 1074.
```js ```js
assert.strictEqual(maximumPathSumI(numTriangle), 1074); assert.strictEqual(maximumPathSumI(numTriangle), 1074);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f37f1000cf542c50fe92 id: 5900f37f1000cf542c50fe92
title: 'Problem 19: Counting Sundays' title: 'Problema 19: Contando le domeniche'
challengeType: 5 challengeType: 5
forumTopicId: 301827 forumTopicId: 301827
dashedName: problem-19-counting-sundays dashedName: problem-19-counting-sundays
@ -8,37 +8,37 @@ dashedName: problem-19-counting-sundays
# --description-- # --description--
You are given the following information, but you may prefer to do some research for yourself. Ti sono fornite le seguenti informazioni, ma potresti voler fare un po' di ricerca per conto tuo.
<ul> <ul>
<li>1 Jan 1900 was a Monday.</li> <li>Il 1 Gennaio 1900 era un lunedì.</li>
<li>Thirty days has September,<br>April, June and November.<br>All the rest have thirty-one,<br>Saving February alone,<br>Which has twenty-eight, rain or shine.<br>And on leap years, twenty-nine.</li> <li>Trenta giorni a novembre,<br>con april, giugno e settembre,<br>di ventotto ce n'è uno,<br>tutti gli altri ne han trentuno.</li>
<li>A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.</li> <li>Un anno bisestile si verifica su qualsiasi anno divisibile per 4, ma non in un anno divisibile per 100 a meno che non sia divisibile per 400.</li>
</ul> </ul>
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? Quante domeniche sono cadute il primo del mese durante il ventesimo secolo (dal 1 Gen 1901 al 31 Dic 2000)?
# --hints-- # --hints--
`countingSundays(1943, 1946)` should return a number. `countingSundays(1943, 1946)` dovrebbe restituire un numero.
```js ```js
assert(typeof countingSundays(1943, 1946) === 'number'); assert(typeof countingSundays(1943, 1946) === 'number');
``` ```
`countingSundays(1943, 1946)` should return 6. `countingSundays(1943, 1946)` dovrebbe restituire 6.
```js ```js
assert.strictEqual(countingSundays(1943, 1946), 6); assert.strictEqual(countingSundays(1943, 1946), 6);
``` ```
`countingSundays(1995, 2000)` should return 10. `countingSundays(1995, 2000)` dovrebbe restituire 10.
```js ```js
assert.strictEqual(countingSundays(1995, 2000), 10); assert.strictEqual(countingSundays(1995, 2000), 10);
``` ```
`countingSundays(1901, 2000)` should return 171. `countingSundays(1901, 2000)` dovrebbe restituire 171.
```js ```js
assert.strictEqual(countingSundays(1901, 2000), 171); assert.strictEqual(countingSundays(1901, 2000), 171);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3801000cf542c50fe93 id: 5900f3801000cf542c50fe93
title: 'Problem 20: Factorial digit sum' title: 'Problema 20: somma delle cifre del fattoriale'
challengeType: 5 challengeType: 5
forumTopicId: 301839 forumTopicId: 301839
dashedName: problem-20-factorial-digit-sum dashedName: problem-20-factorial-digit-sum
@ -8,46 +8,46 @@ dashedName: problem-20-factorial-digit-sum
# --description-- # --description--
`n`! means `n` × (`n` 1) × ... × 3 × 2 × 1 `n`! significa `n` × (`n` 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, Ad esempio, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. e la somma delle cifre nel numero 10! è 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits `n`! Trova la somma delle cifre del numero `n`!
# --hints-- # --hints--
`sumFactorialDigits(10)` should return a number. `sumFactorialDigits(10)` dovrebbe restituire un numero.
```js ```js
assert(typeof sumFactorialDigits(10) === 'number'); assert(typeof sumFactorialDigits(10) === 'number');
``` ```
`sumFactorialDigits(10)` should return 27. `sumFactorialDigits(10)` dovrebbe restituire 27.
```js ```js
assert.strictEqual(sumFactorialDigits(10), 27); assert.strictEqual(sumFactorialDigits(10), 27);
``` ```
`sumFactorialDigits(25)` should return 72. `sumFactorialDigits(25)` dovrebbe restituire 72.
```js ```js
assert.strictEqual(sumFactorialDigits(25), 72); assert.strictEqual(sumFactorialDigits(25), 72);
``` ```
`sumFactorialDigits(50)` should return 216. `sumFactorialDigits(50)` dovrebbe restituire 216.
```js ```js
assert.strictEqual(sumFactorialDigits(50), 216); assert.strictEqual(sumFactorialDigits(50), 216);
``` ```
`sumFactorialDigits(75)` should return 432. `sumFactorialDigits(75)` dovrebbe restituire 432.
```js ```js
assert.strictEqual(sumFactorialDigits(75), 432); assert.strictEqual(sumFactorialDigits(75), 432);
``` ```
`sumFactorialDigits(100)` should return 648. `sumFactorialDigits(100)` dovrebbe restituire 648.
```js ```js
assert.strictEqual(sumFactorialDigits(100), 648); assert.strictEqual(sumFactorialDigits(100), 648);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3811000cf542c50fe94 id: 5900f3811000cf542c50fe94
title: 'Problem 21: Amicable numbers' title: 'Problema 21: Numeri amichevoli'
challengeType: 5 challengeType: 5
forumTopicId: 301851 forumTopicId: 301851
dashedName: problem-21-amicable-numbers dashedName: problem-21-amicable-numbers
@ -8,41 +8,41 @@ dashedName: problem-21-amicable-numbers
# --description-- # --description--
Let d(`n`) be defined as the sum of proper divisors of `n` (numbers less than `n` which divide evenly into `n`). Si definisce d(`n`) la somma dei divisori propri di `n` (numeri inferiori a `n` che dividono `n` senza resto).
If d(`a`) = `b` and d(`b`) = `a`, where `a``b`, then `a` and `b` are an amicable pair and each of `a` and `b` are called amicable numbers. Se d(`a`) = `b` e d(`b`) = `a`, dove `a``b`, allora `a` e `b` sono una coppia amichevole e `a` e `b` sono chiamati numeri amichevoli.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. Ad esempio, i divisori propri di 220 sono 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 e 110; quindi d(220) = 284. I divisori propri di 284 sono 1, 2, 4, 71 e 142; quindi d(284) = 220.
Evaluate the sum of all the amicable numbers under `n`. Valutare la somma di tutti i numeri amichevoli inferiori a `n`.
# --hints-- # --hints--
`sumAmicableNum(1000)` should return a number. `sumAmicableNum(1000)` dovrebbe restituire un numero.
```js ```js
assert(typeof sumAmicableNum(1000) === 'number'); assert(typeof sumAmicableNum(1000) === 'number');
``` ```
`sumAmicableNum(1000)` should return 504. `sumAmicableNum(1000)` dovrebbe restituire 504.
```js ```js
assert.strictEqual(sumAmicableNum(1000), 504); assert.strictEqual(sumAmicableNum(1000), 504);
``` ```
`sumAmicableNum(2000)` should return 2898. `sumAmicableNum(2000)` dovrebbe restituire 2898.
```js ```js
assert.strictEqual(sumAmicableNum(2000), 2898); assert.strictEqual(sumAmicableNum(2000), 2898);
``` ```
`sumAmicableNum(5000)` should return 8442. `sumAmicableNum(5000)` dovrebbe restituire 8442.
```js ```js
assert.strictEqual(sumAmicableNum(5000), 8442); assert.strictEqual(sumAmicableNum(5000), 8442);
``` ```
`sumAmicableNum(10000)` should return 31626. `sumAmicableNum(10000)` dovrebbe restituire 31626.
```js ```js
assert.strictEqual(sumAmicableNum(10000), 31626); assert.strictEqual(sumAmicableNum(10000), 31626);

View File

@ -1,6 +1,6 @@
--- ---
id: 5a51eabcad78bf416f316e2a id: 5a51eabcad78bf416f316e2a
title: 'Problem 22: Names scores' title: 'Problema 22: Punteggi dei nomi'
challengeType: 5 challengeType: 5
forumTopicId: 301862 forumTopicId: 301862
dashedName: problem-22-names-scores dashedName: problem-22-names-scores
@ -8,33 +8,33 @@ dashedName: problem-22-names-scores
# --description-- # --description--
Using `names`, an array defined in the background containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. Usando `names`, un array definito in background contenente oltre cinquemila nomi, inizia ordinandolo in ordine alfabetico. Quindi calcolando il valore alfabetico per ogni nome, moltiplica questo valore per la sua posizione alfabetica nella lista per ottenere un punteggio per il nome.
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714. Ad esempio, quando la lista è ordinata in ordine alfabetico, COLIN, che vale 3 + 15 + 12 + 9 + 14 = 53, è il 938-mo nome dell'elenco. Pertanto, COLIN otterrebbe un punteggio di 938 × 53 = 49714.
What is the total of all the name scores in the array? Qual è il totale di tutti i punteggi dei nomi nell'array?
# --hints-- # --hints--
`namesScores(test1)` should return a number. `namesScores(test1)` dovrebbe restituire un numero.
```js ```js
assert(typeof namesScores(test1) === 'number'); assert(typeof namesScores(test1) === 'number');
``` ```
`namesScores(test1)` should return 791. `namesScores(test1)` dovrebbe restituire 791.
```js ```js
assert.strictEqual(namesScores(test1), 791); assert.strictEqual(namesScores(test1), 791);
``` ```
`namesScores(test2)` should return 1468. `namesScores(test2)` dovrebbe restituire 1468.
```js ```js
assert.strictEqual(namesScores(test2), 1468); assert.strictEqual(namesScores(test2), 1468);
``` ```
`namesScores(names)` should return 871198282. `namesScores(names)` dovrebbe restituire 871198282.
```js ```js
assert.strictEqual(namesScores(names), 871198282); assert.strictEqual(namesScores(names), 871198282);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3831000cf542c50fe96 id: 5900f3831000cf542c50fe96
title: 'Problem 23: Non-abundant sums' title: 'Problema 23: Somme non abbondanti'
challengeType: 5 challengeType: 5
forumTopicId: 301873 forumTopicId: 301873
dashedName: problem-23-non-abundant-sums dashedName: problem-23-non-abundant-sums
@ -8,41 +8,41 @@ dashedName: problem-23-non-abundant-sums
# --description-- # --description--
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. Un numero perfetto è un numerp per cui la somma dei suoi divisori propri è uguale al numero stesso. Per esempio, la somma dei divisori propri di 28 sarebbe 1 + 2 + 4 + 7 + 14 = 28, il che significa che 28 è un numero perfetto.
A number `n` is called deficient if the sum of its proper divisors is less than `n` and it is called abundant if this sum exceeds `n`. Un numero `n` è chiamato deficiente se la somma dei suoi divisori è minore di `n` ed è chiamato abbondante se la somma eccede `n`.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Visto che 12 è il numero abbondante più piccolo, 1 + 2 + 3 + 4 + 6 = 16, il numero più piccolo che può essere scritto come somma di due numeri abbondanti è 24. Tramite l'analisi matematica, si può mostrare che tutti gli interi più grandi di 28123 possono essere scritti come somma di due numeri abbondanti. Eppure, questo limite superiore non può essere ridotto ulteriormente tramite analisi, anche se è noto che il numero più grande che non può essere espresso come somma di due numeri abbondanti è più piccolo di questo limite.
Find the sum of all positive integers &lt;= `n` which cannot be written as the sum of two abundant numbers. Trova la somma di tutti i numeri interi positivi &lt;= `n` che non possono essere scritti come somma di due numeri abbondanti.
# --hints-- # --hints--
`sumOfNonAbundantNumbers(10000)` should return a number. `sumOfNonAbundantNumbers(10000)` dovrebbe restituire un numero.
```js ```js
assert(typeof sumOfNonAbundantNumbers(10000) === 'number'); assert(typeof sumOfNonAbundantNumbers(10000) === 'number');
``` ```
`sumOfNonAbundantNumbers(10000)` should return 3731004. `sumOfNonAbundantNumbers(10000)` dovrebbe restituire 3731004.
```js ```js
assert(sumOfNonAbundantNumbers(10000) === 3731004); assert(sumOfNonAbundantNumbers(10000) === 3731004);
``` ```
`sumOfNonAbundantNumbers(15000)` should return 4039939. `sumOfNonAbundantNumbers(15000)` dovrebbe restituire 4039939.
```js ```js
assert(sumOfNonAbundantNumbers(15000) === 4039939); assert(sumOfNonAbundantNumbers(15000) === 4039939);
``` ```
`sumOfNonAbundantNumbers(20000)` should return 4159710. `sumOfNonAbundantNumbers(20000)` dovrebbe restituire 4159710.
```js ```js
assert(sumOfNonAbundantNumbers(20000) === 4159710); assert(sumOfNonAbundantNumbers(20000) === 4159710);
``` ```
`sumOfNonAbundantNumbers(28123)` should return 4179871. `sumOfNonAbundantNumbers(28123)` dovrebbe restituire 4179871.
```js ```js
assert(sumOfNonAbundantNumbers(28123) === 4179871); assert(sumOfNonAbundantNumbers(28123) === 4179871);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3841000cf542c50fe97 id: 5900f3841000cf542c50fe97
title: 'Problem 24: Lexicographic permutations' title: 'Problema 24: permutazioni lessicografiche'
challengeType: 5 challengeType: 5
forumTopicId: 301885 forumTopicId: 301885
dashedName: problem-24-lexicographic-permutations dashedName: problem-24-lexicographic-permutations
@ -8,39 +8,39 @@ dashedName: problem-24-lexicographic-permutations
# --description-- # --description--
A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: Una permutazione è un arrangiamento di oggetti ordinato. Per esempio, 3124 è una possibile permutazione delle cifre 1, 2, 3 e 4. Se tutte le permutazioni sono elencate numericamente o alfabeticamente, lo chiamiamo ordine lessicografico. Le permutazioni lessicografiche di 0, 1 e 2 sono:
<div style='text-align: center;'>012   021   102   120   201   210</div> <div style='text-align: center;'>012   021   102   120   201   210</div>
What is the `n`th lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? Qual è l'`n`-sima permutazione lessicografica delle cifre 0, 1, 2, 3, 4, 5, 6, 7, 8 e 9?
# --hints-- # --hints--
`lexicographicPermutations(699999)` should return a number. `lexicographicPermutations(699999)` dovrebbe restituire un numero.
```js ```js
assert(typeof lexicographicPermutations(699999) === 'number'); assert(typeof lexicographicPermutations(699999) === 'number');
``` ```
`lexicographicPermutations(699999)` should return 1938246570. `lexicographicPermutations(699999)` dovrebbe restituire 1938246570.
```js ```js
assert(lexicographicPermutations(699999) == 1938246570); assert(lexicographicPermutations(699999) == 1938246570);
``` ```
`lexicographicPermutations(899999)` should return 2536987410. `lexicographicPermutations(899999)` dovrebbe restituire 2536987410.
```js ```js
assert(lexicographicPermutations(899999) == 2536987410); assert(lexicographicPermutations(899999) == 2536987410);
``` ```
`lexicographicPermutations(900000)` should return 2537014689. `lexicographicPermutations(900000)` dovrebbe restituire 2537014689.
```js ```js
assert(lexicographicPermutations(900000) == 2537014689); assert(lexicographicPermutations(900000) == 2537014689);
``` ```
`lexicographicPermutations(999999)` should return 2783915460. `lexicographicPermutations(999999)` dovrebbe restituire 2783915460.
```js ```js
assert(lexicographicPermutations(999999) == 2783915460); assert(lexicographicPermutations(999999) == 2783915460);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3851000cf542c50fe98 id: 5900f3851000cf542c50fe98
title: 'Problem 25: 1000-digit Fibonacci number' title: 'Problema 25: numero di Fibonacci a 1000 cifre'
challengeType: 5 challengeType: 5
forumTopicId: 301897 forumTopicId: 301897
dashedName: problem-25-1000-digit-fibonacci-number dashedName: problem-25-1000-digit-fibonacci-number
@ -8,45 +8,45 @@ dashedName: problem-25-1000-digit-fibonacci-number
# --description-- # --description--
The Fibonacci sequence is defined by the recurrence relation: La sequenza di Fibonacci è definita dalla relazione ricorsiva:
<div style='padding-left: 4em;'>F<sub>n</sub> = F<sub>n1</sub> + F<sub>n2</sub>, where F<sub>1</sub> = 1 and F<sub>2</sub> = 1.</div> <div style='padding-left: 4em;'>F<sub>n</sub> = F<sub>n1</sub> + F<sub>n2</sub>, dove F<sub>1</sub> = 1 e F<sub>2</sub> = 1.</div>
Hence the first 12 terms will be: Quindi i primi 12 termini saranno:
<div style='padding-left: 4em; display: inline-grid; grid-template-rows: auto; row-gap: 7px;'><div>F<sub>1</sub> = 1</div><div>F<sub>2</sub> = 1</div><div>F<sub>3</sub> = 2</div><div>F<sub>4</sub> = 3</div><div>F<sub>5</sub> = 5</div><div>F<sub>6</sub> = 8</div><div>F<sub>7</sub> = 13</div><div>F<sub>8</sub> = 21</div><div>F<sub>9</sub> = 34</div><div>F<sub>10</sub> = 55</div><div>F<sub>11</sub> = 89</div><div>F<sub>12</sub> = 144</div></div> <div style='padding-left: 4em; display: inline-grid; grid-template-rows: auto; row-gap: 7px;'><div>F<sub>1</sub> = 1</div><div>F<sub>2</sub> = 1</div><div>F<sub>3</sub> = 2</div><div>F<sub>4</sub> = 3</div><div>F<sub>5</sub> = 5</div><div>F<sub>6</sub> = 8</div><div>F<sub>7</sub> = 13</div><div>F<sub>8</sub> = 21</div><div>F<sub>9</sub> = 34</div><div>F<sub>10</sub> = 55</div><div>F<sub>11</sub> = 89</div><div>F<sub>12</sub> = 144</div></div>
The 12th term, F<sub>12</sub>, is the first term to contain three digits. Il dodicesimo termine, F<sub>12</sub>, è il primo termine a contenere tre cifre.
What is the index of the first term in the Fibonacci sequence to contain `n` digits? Qual è l'indice del primo termine nella sequenza di Fibonacci contenente `n` cifre?
# --hints-- # --hints--
`digitFibonacci(5)` should return a number. `digitFibonacci(5)` dovrebbe restituire un numero.
```js ```js
assert(typeof digitFibonacci(5) === 'number'); assert(typeof digitFibonacci(5) === 'number');
``` ```
`digitFibonacci(5)` should return 21. `digitFibonacci(5)` dovrebbe restituire 21.
```js ```js
assert.strictEqual(digitFibonacci(5), 21); assert.strictEqual(digitFibonacci(5), 21);
``` ```
`digitFibonacci(10)` should return 45. `digitFibonacci(10)` dovrebbe restituire 45.
```js ```js
assert.strictEqual(digitFibonacci(10), 45); assert.strictEqual(digitFibonacci(10), 45);
``` ```
`digitFibonacci(15)` should return 69. `digitFibonacci(15)` dovrebbe restituire 69.
```js ```js
assert.strictEqual(digitFibonacci(15), 69); assert.strictEqual(digitFibonacci(15), 69);
``` ```
`digitFibonacci(20)` should return 93. `digitFibonacci(20)` dovrebbe restituire 93.
```js ```js
assert.strictEqual(digitFibonacci(20), 93); assert.strictEqual(digitFibonacci(20), 93);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3861000cf542c50fe99 id: 5900f3861000cf542c50fe99
title: 'Problem 26: Reciprocal cycles' title: 'Problema 26: Cicli reciproci'
challengeType: 5 challengeType: 5
forumTopicId: 301908 forumTopicId: 301908
dashedName: problem-26-reciprocal-cycles dashedName: problem-26-reciprocal-cycles
@ -8,41 +8,41 @@ dashedName: problem-26-reciprocal-cycles
# --description-- # --description--
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: Una frazione unitaria contiene 1 nel numeratore. La rappresentazione decimale delle frazioni unitarie con i denominatori da 2 a 10 è indicata con:
<div style='padding-left: 4em; display: inline-grid; grid-template-rows: auto; row-gap: 7px;'><div><sup>1</sup>/<sub>2</sub> = 0.5</div><div><sup>1</sup>/<sub>3</sub> = 0.(3)</div><div><sup>1</sup>/<sub>4</sub> = 0.25</div><div><sup>1</sup>/<sub>5</sub> = 0.2</div><div><sup>1</sup>/<sub>6</sub> = 0.1(6)</div><div><sup>1</sup>/<sub>7</sub> = 0.(142857)</div><div><sup>1</sup>/<sub>8</sub> = 0.125</div><div><sup>1</sup>/<sub>9</sub> = 0.(1)</div><div><sup>1</sup>/<sub>10</sub> = 0.1</div></div> <div style='padding-left: 4em; display: inline-grid; grid-template-rows: auto; row-gap: 7px;'><div><sup>1</sup>/<sub>2</sub> = 0.5</div><div><sup>1</sup>/<sub>3</sub> = 0.(3)</div><div><sup>1</sup>/<sub>4</sub> = 0.25</div><div><sup>1</sup>/<sub>5</sub> = 0.2</div><div><sup>1</sup>/<sub>6</sub> = 0.1(6)</div><div><sup>1</sup>/<sub>7</sub> = 0.(142857)</div><div><sup>1</sup>/<sub>8</sub> = 0.125</div><div><sup>1</sup>/<sub>9</sub> = 0.(1)</div><div><sup>1</sup>/<sub>10</sub> = 0.1</div></div>
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that <sup>1</sup>/<sub>7</sub> has a 6-digit recurring cycle. Dove 0.1(6) significa 0.1666..., e ha un periodo di una cifra. Si può vedere che <sup>1</sup>/<sub>7</sub> ha un periodo di 6 cifre.
Find the value of `d` &lt; `n` for which <sup>1</sup>/<sub>d</sub> contains the longest recurring cycle in its decimal fraction part. Trova il valore di `d` &lt; `n` per il quale <sup>1</sup>/<sub>d</sub> contiene il periodo più lungo nella sua parte di frazione decimale.
# --hints-- # --hints--
`reciprocalCycles(700)` should return a number. `reciprocalCycles(700)` dovrebbe restituire un numero.
```js ```js
assert(typeof reciprocalCycles(700) === 'number'); assert(typeof reciprocalCycles(700) === 'number');
``` ```
`reciprocalCycles(700)` should return 659. `reciprocalCycles(700)` dovrebbe restituire 659.
```js ```js
assert(reciprocalCycles(700) == 659); assert(reciprocalCycles(700) == 659);
``` ```
`reciprocalCycles(800)` should return 743. `reciprocalCycles(800)` dovrebbe restituire 743.
```js ```js
assert(reciprocalCycles(800) == 743); assert(reciprocalCycles(800) == 743);
``` ```
`reciprocalCycles(900)` should return 887. `reciprocalCycles(900)` dovrebbe restituire 887.
```js ```js
assert(reciprocalCycles(900) == 887); assert(reciprocalCycles(900) == 887);
``` ```
`reciprocalCycles(1000)` should return 983. `reciprocalCycles(1000)` dovrebbe restituire 983.
```js ```js
assert(reciprocalCycles(1000) == 983); assert(reciprocalCycles(1000) == 983);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3871000cf542c50fe9a id: 5900f3871000cf542c50fe9a
title: 'Problem 27: Quadratic primes' title: 'Problema 27: Primi quadratici'
challengeType: 5 challengeType: 5
forumTopicId: 301919 forumTopicId: 301919
dashedName: problem-27-quadratic-primes dashedName: problem-27-quadratic-primes
@ -8,51 +8,51 @@ dashedName: problem-27-quadratic-primes
# --description-- # --description--
Euler discovered the remarkable quadratic formula: Eulero ha scoperto la notevole formula quadratica:
<div style='margin-left: 4em;'>$n^2 + n + 41$</div> <div style='margin-left: 4em;'>$n^2 + n + 41$</div>
It turns out that the formula will produce 40 primes for the consecutive integer values $0 \\le n \\le 39$. However, when $n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41$ is divisible by 41, and certainly when $n = 41, 41^2 + 41 + 41$ is clearly divisible by 41. Si scopre che la formula produrrà 40 primi per i valori interi consecutivi $0 \\le n \\le 39$. Tuttavia, quando $n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41$ è divisibile per 41, e quando $n = 41, 41^2 + 41 + 41 $ è chiaramente divisibile per 41.
The incredible formula $n^2 - 79n + 1601$ was discovered, which produces 80 primes for the consecutive values $0 \\le n \\le 79$. The product of the coefficients, 79 and 1601, is 126479. Si è scoperta l'incredibile formula $n^2 - 79n + 1601$ che produce 80 primi per i valori consecutivi $0 \\le n \\le 79$. Il prodotto dei coefficienti, 79 e 1601, è 126479.
Considering quadratics of the form: Considerando le quadratiche della forma:
<div style='margin-left: 4em;'> <div style='margin-left: 4em;'>
$n^2 + an + b$, where $|a| < range$ and $|b| \le range$<br> $n^2 + an + b$, dove $|a| < range$ e $|b| \le range$<br>
where $|n|$ is the modulus/absolute value of $n$<br> dove $|n|$ è il valore assoluto di $n$<br>
e.g. $|11| = 11$ and $|-4| = 4$<br> ad esempio $|11| = 11$ e $|-4| = 4$<br>
</div> </div>
Find the product of the coefficients, $a$ and $b$, for the quadratic expression that produces the maximum number of primes for consecutive values of $n$, starting with $n = 0$. Trova il prodotto dei coefficienti, $a$ e $b$ per l'espressione quadratica che produce il numero massimo di primi per valori consecutivi di $n$, a partire da $n = 0$.
# --hints-- # --hints--
`quadraticPrimes(200)` should return a number. `quadraticPrimes(200)` dovrebbe restituire un numero.
```js ```js
assert(typeof quadraticPrimes(200) === 'number'); assert(typeof quadraticPrimes(200) === 'number');
``` ```
`quadraticPrimes(200)` should return -4925. `quadraticPrimes(200)` dovrebbe restituire -4925.
```js ```js
assert(quadraticPrimes(200) == -4925); assert(quadraticPrimes(200) == -4925);
``` ```
`quadraticPrimes(500)` should return -18901. `quadraticPrimes(500)` dovrebbe restituire -18901.
```js ```js
assert(quadraticPrimes(500) == -18901); assert(quadraticPrimes(500) == -18901);
``` ```
`quadraticPrimes(800)` should return -43835. `quadraticPrimes(800)` dovrebbe restituire -43835.
```js ```js
assert(quadraticPrimes(800) == -43835); assert(quadraticPrimes(800) == -43835);
``` ```
`quadraticPrimes(1000)` should return -59231. `quadraticPrimes(1000)` dovrebbe restituire -59231.
```js ```js
assert(quadraticPrimes(1000) == -59231); assert(quadraticPrimes(1000) == -59231);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3881000cf542c50fe9b id: 5900f3881000cf542c50fe9b
title: 'Problem 28: Number spiral diagonals' title: 'Problema 28: le diagonali della spirale di numeri'
challengeType: 5 challengeType: 5
forumTopicId: 301930 forumTopicId: 301930
dashedName: problem-28-number-spiral-diagonals dashedName: problem-28-number-spiral-diagonals
@ -8,7 +8,7 @@ dashedName: problem-28-number-spiral-diagonals
# --description-- # --description--
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: Iniziando con il numero 1 e muovendo a destra in direzione oraria una spirale 5 per 5 è formata come segue:
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
<div style='color: red; display: inline;'>21</div> 22 23 24 <div style='color: red; display: inline;'>25</div><br> <div style='color: red; display: inline;'>21</div> 22 23 24 <div style='color: red; display: inline;'>25</div><br>
@ -18,37 +18,37 @@ Starting with the number 1 and moving to the right in a clockwise direction a 5
<div style='color: red; display: inline;'>17</div> 16 15 14 <div style='color: red; display: inline;'>13</div><br> <div style='color: red; display: inline;'>17</div> 16 15 14 <div style='color: red; display: inline;'>13</div><br>
</div> </div>
It can be verified that the sum of the numbers on the diagonals is 101. Può essere verificato che la somma di tutti i numeri sulle diagonali è 101.
What is the sum of the numbers on the diagonals in an `n` by `n` spiral formed in the same way? Quale è la somma dei numeri sulle diagnonali di una spirale `n` per `n` formata nello stesso modo?
# --hints-- # --hints--
`spiralDiagonals(101)` should return a number. `spiralDiagonals(101)` dovrebbe restituire un numero.
```js ```js
assert(typeof spiralDiagonals(101) === 'number'); assert(typeof spiralDiagonals(101) === 'number');
``` ```
`spiralDiagonals(101)` should return 692101. `spiralDiagonals(101)` dovrebbe restituire 692101.
```js ```js
assert(spiralDiagonals(101) == 692101); assert(spiralDiagonals(101) == 692101);
``` ```
`spiralDiagonals(303)` should return 18591725. `spiralDiagonals(303)` dovrebbe restituire 18591725.
```js ```js
assert(spiralDiagonals(303) == 18591725); assert(spiralDiagonals(303) == 18591725);
``` ```
`spiralDiagonals(505)` should return 85986601. `spiralDiagonals(505)` dovrebbe restituire 85986601.
```js ```js
assert(spiralDiagonals(505) == 85986601); assert(spiralDiagonals(505) == 85986601);
``` ```
`spiralDiagonals(1001)` should return 669171001. `spiralDiagonals(1001)` dovrebbe restituire 669171001.
```js ```js
assert(spiralDiagonals(1001) == 669171001); assert(spiralDiagonals(1001) == 669171001);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3891000cf542c50fe9c id: 5900f3891000cf542c50fe9c
title: 'Problem 29: Distinct powers' title: 'Problema 29: Potenze distinte'
challengeType: 5 challengeType: 5
forumTopicId: 301941 forumTopicId: 301941
dashedName: problem-29-distinct-powers dashedName: problem-29-distinct-powers
@ -8,7 +8,7 @@ dashedName: problem-29-distinct-powers
# --description-- # --description--
Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: Considera tutte le combinazioni intere di $a^b$ per 2 ≤ a ≤ 5 e 2 ≤ b ≤ 5:
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
2<sup>2</sup>=4, 2<sup>3</sup>=8, 2<sup>4</sup>=16, 2<sup>5</sup>=32 <br> 2<sup>2</sup>=4, 2<sup>3</sup>=8, 2<sup>4</sup>=16, 2<sup>5</sup>=32 <br>
@ -17,41 +17,41 @@ Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
5<sup>2</sup>=25, 5<sup>3</sup>=125, 5<sup>4</sup>=625, 5<sup>5</sup>=3125 <br> 5<sup>2</sup>=25, 5<sup>3</sup>=125, 5<sup>4</sup>=625, 5<sup>5</sup>=3125 <br>
</div> </div>
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: Se sono successivamente posizionati in ordine numerico, con eventuali ripetizioni rimosse, otteniamo la seguente sequenza di 15 termini distinti:
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
</div> </div>
How many distinct terms are in the sequence generated by `ab` for 2 ≤ `a``n` and 2 ≤ `b``n`? Quanti termini distinti ci sono nella sequenza generata da $a^b$ per 2 ≤ `a``n` e 2 ≤ `b``n`?
# --hints-- # --hints--
`distinctPowers(15)` should return a number. `distinctPowers(15)` dovrebbe restituire un numero.
```js ```js
assert(typeof distinctPowers(15) === 'number'); assert(typeof distinctPowers(15) === 'number');
``` ```
`distinctPowers(15)` should return 177. `distinctPowers(15)` dovrebbe restituire 177.
```js ```js
assert.strictEqual(distinctPowers(15), 177); assert.strictEqual(distinctPowers(15), 177);
``` ```
`distinctPowers(20)` should return 324. `distinctPowers(20)` dovrebbe restituire 324.
```js ```js
assert.strictEqual(distinctPowers(20), 324); assert.strictEqual(distinctPowers(20), 324);
``` ```
`distinctPowers(25)` should return 519. `distinctPowers(25)` dovrebbe restituire 519.
```js ```js
assert.strictEqual(distinctPowers(25), 519); assert.strictEqual(distinctPowers(25), 519);
``` ```
`distinctPowers(30)` should return 755. `distinctPowers(30)` dovrebbe restituire 755.
```js ```js
assert.strictEqual(distinctPowers(30), 755); assert.strictEqual(distinctPowers(30), 755);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38a1000cf542c50fe9d id: 5900f38a1000cf542c50fe9d
title: 'Problem 30: Digit n powers' title: 'Problema 30: Potenze delle cifre'
challengeType: 5 challengeType: 5
forumTopicId: 301953 forumTopicId: 301953
dashedName: problem-30-digit-n-powers dashedName: problem-30-digit-n-powers
@ -8,7 +8,7 @@ dashedName: problem-30-digit-n-powers
# --description-- # --description--
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: Sorprendentemente ci sono solo tre numeri che possono essere scritti come la somma delle quarte potenze delle loro cifre:
<div style='margin-left: 4em;'> <div style='margin-left: 4em;'>
1634 = 1<sup>4</sup> + 6<sup>4</sup> + 3<sup>4</sup> + 4<sup>4</sup><br> 1634 = 1<sup>4</sup> + 6<sup>4</sup> + 3<sup>4</sup> + 4<sup>4</sup><br>
@ -16,39 +16,39 @@ Surprisingly there are only three numbers that can be written as the sum of four
9474 = 9<sup>4</sup> + 4<sup>4</sup> + 7<sup>4</sup> + 4<sup>4</sup><br> 9474 = 9<sup>4</sup> + 4<sup>4</sup> + 7<sup>4</sup> + 4<sup>4</sup><br>
</div> </div>
As 1 = 1<sup>4</sup> is not a sum it is not included. Dato che 1 = 1<sup>4</sup> non è una somma, esso non è incluso.
The sum of these numbers is 1634 + 8208 + 9474 = 19316. La somma di questi numeri è 1634 + 8208 + 9474 = 19316.
Find the sum of all the numbers that can be written as the sum of `n` powers of their digits. Trova la somma di tutti i numeri che possono essere scritti come la somma di `n` potenze delle loro cifre.
# --hints-- # --hints--
`digitnPowers(2)` should return a number. `digitnPowers(2)` dovrebbe restituire un numero.
```js ```js
assert(typeof digitnPowers(2) === 'number'); assert(typeof digitnPowers(2) === 'number');
``` ```
`digitnPowers(2)` should return 0. `digitnPowers(2)` dovrebbe restituire 0.
```js ```js
assert(digitnPowers(2) == 0); assert(digitnPowers(2) == 0);
``` ```
`digitnPowers(3)` should return 1301. `digitnPowers(3)` dovrebbe restituire 1301.
```js ```js
assert(digitnPowers(3) == 1301); assert(digitnPowers(3) == 1301);
``` ```
`digitnPowers(4)` should return 19316. `digitnPowers(4)` dovrebbe restituire 19316.
```js ```js
assert(digitnPowers(4) == 19316); assert(digitnPowers(4) == 19316);
``` ```
`digitnPowers(5)` should return 443839. `digitnPowers(5)` dovrebbe restituire 443839.
```js ```js
assert(digitnPowers(5) == 443839); assert(digitnPowers(5) == 443839);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38b1000cf542c50fe9e id: 5900f38b1000cf542c50fe9e
title: 'Problem 31: Coin sums' title: 'Problema 31: somme di monete'
challengeType: 5 challengeType: 5
forumTopicId: 301965 forumTopicId: 301965
dashedName: problem-31-coin-sums dashedName: problem-31-coin-sums
@ -8,43 +8,43 @@ dashedName: problem-31-coin-sums
# --description-- # --description--
In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: In Inghilterra la moneta è composta da sterline, £, e pence, p, e ci sono 8 monete in circolazione:
<div style='margin-left: 4em;'>1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).</div> <div style='margin-left: 4em;'>1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) e £2 (200p).</div>
It is possible to make £2 in the following way: È possibile comporre 2 £ nel modo seguente:
<div style='margin-left: 4em;'>1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p</div> <div style='margin-left: 4em;'>1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p</div>
How many different ways can `n` pence be made using any number of coins? In quanti modi diversi si possono ottenere `n` pence usando qualsiasi numero di monete?
# --hints-- # --hints--
`coinSums(50)` should return a number. `coinSums(50)` dovrebbe restituire un numero.
```js ```js
assert(typeof coinSums(50) === 'number'); assert(typeof coinSums(50) === 'number');
``` ```
`coinSums(50)` should return 451. `coinSums(50)` dovrebbe restituire 451.
```js ```js
assert(coinSums(50) == 451); assert(coinSums(50) == 451);
``` ```
`coinSums(100)` should return 4563. `coinSums(100)` dovrebbe restituire 4563.
```js ```js
assert(coinSums(100) == 4563); assert(coinSums(100) == 4563);
``` ```
`coinSums(150)` should return 21873. `coinSums(150)` dovrebbe restituire 21873.
```js ```js
assert(coinSums(150) == 21873); assert(coinSums(150) == 21873);
``` ```
`coinSums(200)` should return 73682. `coinSums(200)` dovrebbe restituire 73682.
```js ```js
assert(coinSums(200) == 73682); assert(coinSums(200) == 73682);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38c1000cf542c50fe9f id: 5900f38c1000cf542c50fe9f
title: 'Problem 32: Pandigital products' title: 'Problema 32: prodotti pandigitali'
challengeType: 5 challengeType: 5
forumTopicId: 301976 forumTopicId: 301976
dashedName: problem-32-pandigital-products dashedName: problem-32-pandigital-products
@ -8,47 +8,47 @@ dashedName: problem-32-pandigital-products
# --description-- # --description--
We shall say that an `n`-digit number is pandigital if it makes use of all the digits 1 to `n` exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital. Possiamo dire che un numero di `n` cifre è pandigitale se usa tutte le cifre da 1 a `n` esattamente una volta; per esempio, il numero a 5 cifre 15234 è pandigitale per le cifre da 1 a 5.
The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital. Il prodotto 7259 è inusuale, in quanto l'identità 39 x 186 = 7254, contenente moltiplicando, moltiplicatore, e prodotto, è pandigitale per le cifre da 1 a 9.
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through `n` pandigital. Trova le somme di tutti i prodotti la cui identità moltiplicando/moltiplicatore/prodotto può essere scritta come pandigitale per le cifre da 1 a `n`.
**Hint:** Some products can be obtained in more than one way so be sure to only include it once in your sum. **Indizio:** Alcuni prodotti possono essere ottenuti in più di un modo quindi assicurati di includerli una volta sola nella tua somma.
# --hints-- # --hints--
`pandigitalProducts(4)` should return a number. `pandigitalProducts(4)` dovrebbe restituire un numero.
```js ```js
assert(typeof pandigitalProducts(4) === 'number'); assert(typeof pandigitalProducts(4) === 'number');
``` ```
`pandigitalProducts(4)` should return `12`. `pandigitalProducts(4)` dovrebbe restituire `12`.
```js ```js
assert.strictEqual(pandigitalProducts(4), 12); assert.strictEqual(pandigitalProducts(4), 12);
``` ```
`pandigitalProducts(6)` should return `162`. `pandigitalProducts(6)` dovrebbe restituire `162`.
```js ```js
assert.strictEqual(pandigitalProducts(6), 162); assert.strictEqual(pandigitalProducts(6), 162);
``` ```
`pandigitalProducts(7)` should return `0`. `pandigitalProducts(7)` dovrebbe restituire `0`.
```js ```js
assert.strictEqual(pandigitalProducts(7), 0); assert.strictEqual(pandigitalProducts(7), 0);
``` ```
`pandigitalProducts(8)` should return `13458`. `pandigitalProducts(8)` dovrebbe restituire `13458`.
```js ```js
assert.strictEqual(pandigitalProducts(8), 13458); assert.strictEqual(pandigitalProducts(8), 13458);
``` ```
`pandigitalProducts(9)` should return `45228`. `pandigitalProducts(9)` dovrebbe restituire `45228`.
```js ```js
assert.strictEqual(pandigitalProducts(9), 45228); assert.strictEqual(pandigitalProducts(9), 45228);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38d1000cf542c50fea0 id: 5900f38d1000cf542c50fea0
title: 'Problem 33: Digit cancelling fractions' title: 'Problemi 33: frazioni cancellando le cifre'
challengeType: 5 challengeType: 5
forumTopicId: 301987 forumTopicId: 301987
dashedName: problem-33-digit-cancelling-fractions dashedName: problem-33-digit-cancelling-fractions
@ -8,23 +8,23 @@ dashedName: problem-33-digit-cancelling-fractions
# --description-- # --description--
The fraction <sup>49</sup>/<sub>98</sub> is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that <sup>49</sup>/<sub>98</sub> = <sup>4</sup>/<sub>8</sub>, which is correct, is obtained by cancelling the 9s. La frazione <sup>49</sup>/<sub>98</sub> è una frazione peculiare, poiché un matematico senza esperienza tentando di semplificarla potrebbe credere incorrettamente che la semplificazione <sup>49</sup>/<sub>98</sub> = <sup>4</sup>/<sub>8</sub>, che è corretta, è ottenuta cancellando i 9.
We shall consider fractions like, <sup>30</sup>/<sub>50</sub> = <sup>3</sup>/<sub>5</sub>, to be trivial examples. Possiamo considerare frazioni come <sup>30</sup>/<sub>50</sub> = <sup>3</sup>/<sub>5</sub> un esempio triviale.
There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator. Ci sono esattamente quattro esempi non triviali di questo tipo di frazioni, con valore minore di 1, e contenenti due cifre al numeratore e denominatore.
If the product of these four fractions is given in its lowest common terms, find the value of the denominator. Se il prodotto di queste quattro frazioni è dato nel formato semplificato, trova il valore del denominatore.
# --hints-- # --hints--
`digitCancellingFractions()` should return a number. `digitCancellingFractions()` dovrebbe restituire un numero.
```js ```js
assert(typeof digitCancellingFractions() === 'number'); assert(typeof digitCancellingFractions() === 'number');
``` ```
`digitCancellingFractions()` should return 100. `digitCancellingFractions()` dovrebbe restituire 100.
```js ```js
assert.strictEqual(digitCancellingFractions(), 100); assert.strictEqual(digitCancellingFractions(), 100);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38e1000cf542c50fea1 id: 5900f38e1000cf542c50fea1
title: 'Problem 34: Digit factorials' title: 'Problema 34: fattoriali delle cifre'
challengeType: 5 challengeType: 5
forumTopicId: 301998 forumTopicId: 301998
dashedName: problem-34-digit-factorials dashedName: problem-34-digit-factorials
@ -8,15 +8,15 @@ dashedName: problem-34-digit-factorials
# --description-- # --description--
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. 145 è un numero curioso, visto che 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the numbers and the sum of the numbers which are equal to the sum of the factorial of their digits. Trova i numeri e le somme dei numeri che sono uguali alla somma dei fattoriali delle loro cifre.
**Note:** as 1! = 1 and 2! = 2 are not sums they are not included. **Nota:** dato che 1! = 1 e 2! = 2 non sono somme essi non sono inclusi.
# --hints-- # --hints--
`digitFactorial()` should return an object. `digitFactorial()` dovrebbe restituire un oggetto.
```js ```js
assert.typeOf(digitFactorial(), 'object'); assert.typeOf(digitFactorial(), 'object');

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f38f1000cf542c50fea2 id: 5900f38f1000cf542c50fea2
title: 'Problem 35: Circular primes' title: 'Problema 35: Primi circolari'
challengeType: 5 challengeType: 5
forumTopicId: 302009 forumTopicId: 302009
dashedName: problem-35-circular-primes dashedName: problem-35-circular-primes
@ -8,55 +8,55 @@ dashedName: problem-35-circular-primes
# --description-- # --description--
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. Il numero 197 è chiamato un primo circolare perché tutte le rotazioni delle cifre: 197, 971 e 719, sono esse stesse prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. Ci sono tredici di questi primi sotto il 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79 e 97.
How many circular primes are there below `n`, whereas 100 ≤ `n` ≤ 1000000? Quanti primi circolari ci sono sotto `n`, dove 100 ≤ `n` ≤ 1000000?
**Note:** **Nota:**
Circular primes individual rotation can exceed `n`. La rotazione individuale di primi circolari può superare `n`.
# --hints-- # --hints--
`circularPrimes(100)` should return a number. `circularPrimes(100)` dovrebbe restituire un numero.
```js ```js
assert(typeof circularPrimes(100) === 'number'); assert(typeof circularPrimes(100) === 'number');
``` ```
`circularPrimes(100)` should return 13. `circularPrimes(100)` dovrebbe restituire 13.
```js ```js
assert(circularPrimes(100) == 13); assert(circularPrimes(100) == 13);
``` ```
`circularPrimes(100000)` should return 43. `circularPrimes(100000)` dovrebbe restituire 43.
```js ```js
assert(circularPrimes(100000) == 43); assert(circularPrimes(100000) == 43);
``` ```
`circularPrimes(250000)` should return 45. `circularPrimes(250000)` dovrebbe restituire 45.
```js ```js
assert(circularPrimes(250000) == 45); assert(circularPrimes(250000) == 45);
``` ```
`circularPrimes(500000)` should return 49. `circularPrimes(500000)` dovrebbe restituire 49.
```js ```js
assert(circularPrimes(500000) == 49); assert(circularPrimes(500000) == 49);
``` ```
`circularPrimes(750000)` should return 49. `circularPrimes(750000)` dovrebbe restituire 49.
```js ```js
assert(circularPrimes(750000) == 49); assert(circularPrimes(750000) == 49);
``` ```
`circularPrimes(1000000)` should return 55. `circularPrimes(1000000)` dovrebbe restituire 55.
```js ```js
assert(circularPrimes(1000000) == 55); assert(circularPrimes(1000000) == 55);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3901000cf542c50fea3 id: 5900f3901000cf542c50fea3
title: 'Problem 36: Double-base palindromes' title: 'Problema 36: palindromi in doppia base'
challengeType: 5 challengeType: 5
forumTopicId: 302020 forumTopicId: 302020
dashedName: problem-36-double-base-palindromes dashedName: problem-36-double-base-palindromes
@ -8,39 +8,39 @@ dashedName: problem-36-double-base-palindromes
# --description-- # --description--
The decimal number, 585 = 1001001001<sub>2</sub> (binary), is palindromic in both bases. Il numero decimale 585 = 1001001001<sub>2</sub> (binary) è un palindromo in entrambe le basi.
Find the sum of all numbers, less than `n`, whereas 1000 ≤ `n` ≤ 1000000, which are palindromic in base 10 and base 2. Trova la somma di tutti i numeri, meno di `n`, dove 1000 ≤ `n` ≤ 1000000, che sono palindromi in base 10 e in base 2.
(Please note that the palindromic number, in either base, may not include leading zeros.) (Si noti che il numero palindromico, in entrambe le basi, non può includere zeri iniziali.)
# --hints-- # --hints--
`doubleBasePalindromes(1000)` should return a number. `doubleBasePalindromes(1000)` dovrebbe restituire un numero.
```js ```js
assert(typeof doubleBasePalindromes(1000) === 'number'); assert(typeof doubleBasePalindromes(1000) === 'number');
``` ```
`doubleBasePalindromes(1000)` should return 1772. `doubleBasePalindromes(1000)` dovrebbe restituire 1772.
```js ```js
assert(doubleBasePalindromes(1000) == 1772); assert(doubleBasePalindromes(1000) == 1772);
``` ```
`doubleBasePalindromes(50000)` should return 105795. `doubleBasePalindromes(50000)` dovrebbe restituire 105795.
```js ```js
assert(doubleBasePalindromes(50000) == 105795); assert(doubleBasePalindromes(50000) == 105795);
``` ```
`doubleBasePalindromes(500000)` should return 286602. `doubleBasePalindromes(500000)` dovrebbe restituire 286602.
```js ```js
assert(doubleBasePalindromes(500000) == 286602); assert(doubleBasePalindromes(500000) == 286602);
``` ```
`doubleBasePalindromes(1000000)` should return 872187. `doubleBasePalindromes(1000000)` dovrebbe restituire 872187.
```js ```js
assert(doubleBasePalindromes(1000000) == 872187); assert(doubleBasePalindromes(1000000) == 872187);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3911000cf542c50fea4 id: 5900f3911000cf542c50fea4
title: 'Problem 37: Truncatable primes' title: 'Problema 37: numeri primi troncabili'
challengeType: 5 challengeType: 5
forumTopicId: 302031 forumTopicId: 302031
dashedName: problem-37-truncatable-primes dashedName: problem-37-truncatable-primes
@ -8,39 +8,39 @@ dashedName: problem-37-truncatable-primes
# --description-- # --description--
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3. Il numero 3797 ha una proprietà interessante. Essendo esso stesso un numero primo, è possibile rimuovere continuosamente cifre da sinistra a destra, e rimane primo ad ogni stadio: 3797, 797, 97, e 7. Allo stesso modo possiamo farlo da destra a sinistra: 3797, 379, 37, e 3.
Find the sum of the only `n` (8 ≤ `n` ≤ 11) primes that are both truncatable from left to right and right to left. Trova la somma dei soli `n` (8 ≤ `n` ≤ 11) numeri primi che sono troncabili sia da sinistra a destra che da destra a sinistra.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes. Nota: 2, 3, 5, e 7 non sono considerati numeri primi troncabili.
# --hints-- # --hints--
`truncatablePrimes(8)` should return a number. `truncatablePrimes(8)` dovrebbe restituire un numero.
```js ```js
assert(typeof truncatablePrimes(8) === 'number'); assert(typeof truncatablePrimes(8) === 'number');
``` ```
`truncatablePrimes(8)` should return 1986. `truncatablePrimes(8)` dovrebbe restituire 1986.
```js ```js
assert(truncatablePrimes(8) == 1986); assert(truncatablePrimes(8) == 1986);
``` ```
`truncatablePrimes(9)` should return 5123. `truncatablePrimes(9)` dovrebbe restituire 5123.
```js ```js
assert(truncatablePrimes(9) == 5123); assert(truncatablePrimes(9) == 5123);
``` ```
`truncatablePrimes(10)` should return 8920. `truncatablePrimes(10)` dovrebbe restituire 8920.
```js ```js
assert(truncatablePrimes(10) == 8920); assert(truncatablePrimes(10) == 8920);
``` ```
`truncatablePrimes(11)` should return 748317. `truncatablePrimes(11)` dovrebbe restituire 748317.
```js ```js
assert(truncatablePrimes(11) == 748317); assert(truncatablePrimes(11) == 748317);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3931000cf542c50fea5 id: 5900f3931000cf542c50fea5
title: 'Problem 38: Pandigital multiples' title: 'Problema 38: Multipli pandigitali'
challengeType: 5 challengeType: 5
forumTopicId: 302042 forumTopicId: 302042
dashedName: problem-38-pandigital-multiples dashedName: problem-38-pandigital-multiples
@ -8,31 +8,31 @@ dashedName: problem-38-pandigital-multiples
# --description-- # --description--
Take the number 192 and multiply it by each of 1, 2, and 3: Prendi il numero 192 e moltiplicalo separatemente per 1, 2, e 3:
$$\begin{align} 192 × 1 = 192\\\\ 192 × 2 = 384\\\\ 192 × 3 = 576\\\\ \end{align}$$ $$\begin{align} 192 × 1 = 192\\\\ 192 × 2 = 384\\\\ 192 × 3 = 576\\\\ \end{align}$$
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1, 2, 3). Concatenando ogni prodotto otteniamo il pandigitale di cifre da 1 a 9, 192384576. Chiamiamo 192384576 il prodotto concatenato di 192 e (1, 2, 3).
The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1, 2, 3, 4, 5). Lo stesso può essere ottenuto iniziando con 9 e moltiplicandolo con 1, 2, 3, 4, e 5, dando il numero pandigitale 918273645, che è il prodotto concatenato di 9 e (1, 2, 3, 4, 5).
What is the largest 1 to `k` pandigital `k`-digit number that can be formed as the concatenated product of an integer with (1, 2, ..., `n`) where `n` > 1? Quale è il pandigitale con cifre da 1 a `k` lungo `k` cifre che può essere formato come prodotto concatenato di un numeri intero (1, 2, ..., `n`) dove `n` > 1?
# --hints-- # --hints--
`pandigitalMultiples(8)` should return a number. `pandigitalMultiples(8)` dovrebbe restituire un numero.
```js ```js
assert(typeof pandigitalMultiples(8) === 'number'); assert(typeof pandigitalMultiples(8) === 'number');
``` ```
`pandigitalMultiples(8)` should return `78156234`. `pandigitalMultiples(8)` dovrebbe restituire `78156234`.
```js ```js
assert.strictEqual(pandigitalMultiples(8), 78156234); assert.strictEqual(pandigitalMultiples(8), 78156234);
``` ```
`pandigitalMultiples(9)` should return `932718654`. `pandigitalMultiples(9)` dovrebbe restituire `932718654`.
```js ```js
assert.strictEqual(pandigitalMultiples(9), 932718654); assert.strictEqual(pandigitalMultiples(9), 932718654);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3931000cf542c50fea6 id: 5900f3931000cf542c50fea6
title: 'Problem 39: Integer right triangles' title: 'Problema 39: triangoli rettangoli interi'
challengeType: 5 challengeType: 5
forumTopicId: 302054 forumTopicId: 302054
dashedName: problem-39-integer-right-triangles dashedName: problem-39-integer-right-triangles
@ -8,39 +8,39 @@ dashedName: problem-39-integer-right-triangles
# --description-- # --description--
If `p` is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120. Se `p` è il perimetro di un triangolo rettangolo con lunghezza dei lati di numeri interi, {a,b,c}, ci sono esattamente tre soluzioni per p = 120.
{20,48,52}, {24,45,51}, {30,40,50} {20,48,52}, {24,45,51}, {30,40,50}
For which value of `p``n`, is the number of solutions maximized? Per quale valore di `p``n` il numero delle soluzioni viene massimizzato?
# --hints-- # --hints--
`intRightTriangles(500)` should return a number. `intRightTriangles(500)` dovrebbe restituire un numero.
```js ```js
assert(typeof intRightTriangles(500) === 'number'); assert(typeof intRightTriangles(500) === 'number');
``` ```
`intRightTriangles(500)` should return 420. `intRightTriangles(500)` dovrebbe restituire 420.
```js ```js
assert(intRightTriangles(500) == 420); assert(intRightTriangles(500) == 420);
``` ```
`intRightTriangles(800)` should return 720. `intRightTriangles(800)` dovrebbe restituire 720.
```js ```js
assert(intRightTriangles(800) == 720); assert(intRightTriangles(800) == 720);
``` ```
`intRightTriangles(900)` should return 840. `intRightTriangles(900)` dovrebbe restituire 840.
```js ```js
assert(intRightTriangles(900) == 840); assert(intRightTriangles(900) == 840);
``` ```
`intRightTriangles(1000)` should return 840. `intRightTriangles(1000)` dovrebbe restituire 840.
```js ```js
assert(intRightTriangles(1000) == 840); assert(intRightTriangles(1000) == 840);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3941000cf542c50fea7 id: 5900f3941000cf542c50fea7
title: 'Problem 40: Champernowne''s constant' title: 'Problema 40: costante di Champernowne'
challengeType: 5 challengeType: 5
forumTopicId: 302066 forumTopicId: 302066
dashedName: problem-40-champernownes-constant dashedName: problem-40-champernownes-constant
@ -8,37 +8,37 @@ dashedName: problem-40-champernownes-constant
# --description-- # --description--
An irrational decimal fraction is created by concatenating the positive integers: Una frazione decimale irrazionale è creata concatenando i numeri interi positivi:
0.12345678910**1**112131415161718192021... 0.12345678910**1**112131415161718192021...
It can be seen that the 12<sup>th</sup> digit of the fractional part is 1. Puoi vedere che la dodicesima cifra della parte frazionale è 1.
If *d<sub>n</sub>* represents the *n*<sup>th</sup> digit of the fractional part, find the value of the following expression. Se *d<sub>n</sub>* rappresenta la *n*-sima cifra della parte frazionale, trova il valore di questa espressione.
d<sub>1</sub> × d<sub>10</sub> × d<sub>100</sub> × d<sub>1000</sub> × d<sub>10000</sub> × d<sub>100000</sub> × d<sub>1000000</sub> d<sub>1</sub> × d<sub>10</sub> × d<sub>100</sub> × d<sub>1000</sub> × d<sub>10000</sub> × d<sub>100000</sub> × d<sub>1000000</sub>
# --hints-- # --hints--
`champernownesConstant(100)` should return a number. `champernownesConstant(100)` dovrebbe restituire un numero.
```js ```js
assert(typeof champernownesConstant(100) === 'number'); assert(typeof champernownesConstant(100) === 'number');
``` ```
`champernownesConstant(100)` should return 5. `champernownesConstant(100)` dovrebbe restituire 5.
```js ```js
assert.strictEqual(champernownesConstant(100), 5); assert.strictEqual(champernownesConstant(100), 5);
``` ```
`champernownesConstant(1000)` should return 15. `champernownesConstant(1000)` dovrebbe restituire 15.
```js ```js
assert.strictEqual(champernownesConstant(1000), 15); assert.strictEqual(champernownesConstant(1000), 15);
``` ```
`champernownesConstant(1000000)` should return 210. `champernownesConstant(1000000)` dovrebbe restituire 210.
```js ```js
assert.strictEqual(champernownesConstant(1000000), 210); assert.strictEqual(champernownesConstant(1000000), 210);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3951000cf542c50fea8 id: 5900f3951000cf542c50fea8
title: 'Problem 41: Pandigital prime' title: 'Problema 41: Primi pandigitali'
challengeType: 5 challengeType: 5
forumTopicId: 302078 forumTopicId: 302078
dashedName: problem-41-pandigital-prime dashedName: problem-41-pandigital-prime
@ -8,25 +8,25 @@ dashedName: problem-41-pandigital-prime
# --description-- # --description--
We shall say that an `n`-digit number is pandigital if it makes use of all the digits 1 to `n` exactly once. For example, 2143 is a 4-digit pandigital and is also prime. Diremo che un numero di cifre `n` è pandigitale se utilizza tutte le cifre da 1 a `n` esattamente una volta. Ad esempio, 2143 è un pandigitale a 4 cifre ed è anche primo.
What is the largest `n`-length digit pandigital prime that exists? Qual è il più grande pandigitale primo a `n` cifre esistente?
# --hints-- # --hints--
`pandigitalPrime(4)` should return a number. `pandigitalPrime(4)` dovrebbe restituire un numero.
```js ```js
assert(typeof pandigitalPrime(4) === 'number'); assert(typeof pandigitalPrime(4) === 'number');
``` ```
`pandigitalPrime(4)` should return 4231. `pandigitalPrime(4)` dovrebbe restituire 4231.
```js ```js
assert(pandigitalPrime(4) == 4231); assert(pandigitalPrime(4) == 4231);
``` ```
`pandigitalPrime(7)` should return 7652413. `pandigitalPrime(7)` dovrebbe restituire 7652413.
```js ```js
assert(pandigitalPrime(7) == 7652413); assert(pandigitalPrime(7) == 7652413);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3961000cf542c50fea9 id: 5900f3961000cf542c50fea9
title: 'Problem 42: Coded triangle numbers' title: 'Problema 42: Numeri codificati triangolari'
challengeType: 5 challengeType: 5
forumTopicId: 302089 forumTopicId: 302089
dashedName: problem-42-coded-triangle-numbers dashedName: problem-42-coded-triangle-numbers
@ -8,41 +8,41 @@ dashedName: problem-42-coded-triangle-numbers
# --description-- # --description--
The `n`<sup>th</sup> term of the sequence of triangle numbers is given by, `tn` = ½`n`(`n`+1); so the first ten triangle numbers are: L'`n`-simo termine di una sequenza di numeri triangolari è data da `tn` = ½`n`(`n`+1); quindi i primi dieci numeri triangolari sono:
<div style='margin-left: 4em;'>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...</div> <div style='margin-left: 4em;'>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...</div>
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = `t`<sub>10</sub>. If the word value is a triangle number then we shall call the word a triangle word. Convertendo ogni lettera in una parola in un numero corrispondente alla sua posizione nell'alfabeto a 26 lettere, e sommando questi valori otteniamo il valore della parola. Per esempio, il valore della parola SKY è 19 + 11 + 25 = 55 = `t`<sub>10</sub>. Se il valore della parola è un numero triangolare allora chiamiamo questa parola triangolare.
Using words array of `n`-length, how many are triangle words? Usando array di parole lungo `n`, quante sono parole triangolari?
# --hints-- # --hints--
`codedTriangleNumbers(1400)` should return a number. `codedTriangleNumbers(1400)` dovrebbe restituire un numero.
```js ```js
assert(typeof codedTriangleNumbers(1400) === 'number'); assert(typeof codedTriangleNumbers(1400) === 'number');
``` ```
`codedTriangleNumbers(1400)` should return 129. `codedTriangleNumbers(1400)` dovrebbe restituire 129.
```js ```js
assert(codedTriangleNumbers(1400) == 129); assert(codedTriangleNumbers(1400) == 129);
``` ```
`codedTriangleNumbers(1500)` should return 137. `codedTriangleNumbers(1500)` dovrebbe restituire 137.
```js ```js
assert(codedTriangleNumbers(1500) == 137); assert(codedTriangleNumbers(1500) == 137);
``` ```
`codedTriangleNumbers(1600)` should return 141. `codedTriangleNumbers(1600)` dovrebbe restituire 141.
```js ```js
assert(codedTriangleNumbers(1600) == 141); assert(codedTriangleNumbers(1600) == 141);
``` ```
`codedTriangleNumbers(1786)` should return 162. `codedTriangleNumbers(1786)` dovrebbe restituire 162.
```js ```js
assert(codedTriangleNumbers(1786) == 162); assert(codedTriangleNumbers(1786) == 162);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3971000cf542c50feaa id: 5900f3971000cf542c50feaa
title: 'Problem 43: Sub-string divisibility' title: 'Problema 43: Divisibilità in sotto-stringhe'
challengeType: 5 challengeType: 5
forumTopicId: 302100 forumTopicId: 302100
dashedName: problem-43-sub-string-divisibility dashedName: problem-43-sub-string-divisibility
@ -8,49 +8,49 @@ dashedName: problem-43-sub-string-divisibility
# --description-- # --description--
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property. Il numero 1406357289 è un numero pandigitale da 0 a 9 perché è costituito da ciascuna delle cifre da 0 a 9 in un certo ordine, ma ha anche una proprietà di divisibilità in sotto-stringhe piuttosto interessante.
Let $d_1$ be the $1^{st}$ digit, $d_2$ be the $2^{nd}$ digit, and so on. In this way, we note the following: Sia $d_1$ il $1^{st}$ numero, $d_2$ sia il $2^{nd}$ numero, e così via. In questo modo, notiamo quanto segue:
- ${d_2}{d_3}{d_4} = 406$ is divisible by 2 - ${d_2}{d_3}{d_4} = 406$ è divisibile per 2
- ${d_3}{d_4}{d_5} = 063$ is divisible by 3 - ${d_3}{d_4}{d_5} = 063$ è divisibile per 3
- ${d_4}{d_5}{d_6} = 635$ is divisible by 5 - ${d_4}{d_5}{d_6} = 635$ è divisibile per 5
- ${d_5}{d_6}{d_7} = 357$ is divisible by 7 - ${d_5}{d_6}{d_7} = 357$ è divisibile per 7
- ${d_6}{d_7}{d_8} = 572$ is divisible by 11 - ${d_6}{d_7}{d_8} = 572$ è divisibile per 11
- ${d_7}{d_8}{d_9} = 728$ is divisible by 13 - ${d_7}{d_8}{d_9} = 728$ è divisibile per 13
- ${d_8}{d_9}{d_{10}} = 289$ is divisible by 17 - ${d_8}{d_9}{d_{10}} = 289$ è divisibile per 17
Find the sum of all 0 to `n` pandigital numbers with sub-strings fulfilling `n - 2` of these divisibility properties. Trova la somma di tutti i numeri pandigitali da 0 a `n` con sotto-stringhe che soddisfano `n - 2` di queste proprietà di divisibilità.
**Note:** Pandigital numbers starting with `0` are to be considered in the result. **Nota:** i numeri pandigitali che iniziano con `0` devono essere considerati nel risultato.
# --hints-- # --hints--
`substringDivisibility(5)` should return a number. `substringDivisibility(5)` dovrebbe restituire un numero.
```js ```js
assert(typeof substringDivisibility(5) === 'number'); assert(typeof substringDivisibility(5) === 'number');
``` ```
`substringDivisibility(5)` should return `12444480`. `substringDivisibility(5)` dovrebbe restituire `12444480`.
```js ```js
assert.strictEqual(substringDivisibility(5), 12444480) assert.strictEqual(substringDivisibility(5), 12444480)
``` ```
`substringDivisibility(7)` should return `1099210170`. `substringDivisibility(7)` dovrebbe restituire `1099210170`.
```js ```js
assert.strictEqual(substringDivisibility(7), 1099210170) assert.strictEqual(substringDivisibility(7), 1099210170)
``` ```
`substringDivisibility(8)` should return `1113342912`. `substringDivisibility(8)` dovrebbe restituire `1113342912`.
```js ```js
assert.strictEqual(substringDivisibility(8), 1113342912) assert.strictEqual(substringDivisibility(8), 1113342912)
``` ```
`substringDivisibility(9)` should return `16695334890`. `substringDivisibility(9)` dovrebbe restituire `16695334890`.
```js ```js
assert.strictEqual(substringDivisibility(9), 16695334890) assert.strictEqual(substringDivisibility(9), 16695334890)

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3981000cf542c50feab id: 5900f3981000cf542c50feab
title: 'Problem 44: Pentagon numbers' title: 'Problema 44: numeri pentagonali'
challengeType: 5 challengeType: 5
forumTopicId: 302111 forumTopicId: 302111
dashedName: problem-44-pentagon-numbers dashedName: problem-44-pentagon-numbers
@ -8,23 +8,23 @@ dashedName: problem-44-pentagon-numbers
# --description-- # --description--
Pentagonal numbers are generated by the formula, P<sub>n</sub>=`n`(3`n`1)/2. The first ten pentagonal numbers are: Numeri pentagonali sono generati dalla formula P<sub>n</sub>=`n`(3`n`1)/2. I primi dieci numeri pentagonali sono:
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ... 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
It can be seen that P<sub>4</sub> + P<sub>7</sub> = 22 + 70 = 92 = P<sub>8</sub>. However, their difference, 70 22 = 48, is not pentagonal. Possiamo vedere che P<sub>4</sub> + P<sub>7</sub> = 22 + 70 = 92 = P<sub>8</sub>. D'altro canto, la loro differenza, 70 22 = 48, non è pentagonale.
Find the pair of pentagonal numbers, P<sub>j</sub> and P<sub>k</sub>, for which their sum and difference are pentagonal and D = |P<sub>k</sub> P<sub>j</sub>| is minimized; what is the value of D? Trova la coppia di numeri, P<sub>j</sub> and P<sub>k</sub>, per cui sia la loro somma che la loro differenza sono pentagonali e D = |P<sub>k</sub> P<sub>j</sub>| è minimizzata; quale è il valore di D?
# --hints-- # --hints--
`pentagonNumbers()` should return a number. `pentagonNumbers()` dovrebbe restituire un numero.
```js ```js
assert(typeof pentagonNumbers() === 'number'); assert(typeof pentagonNumbers() === 'number');
``` ```
`pentagonNumbers()` should return 5482660. `pentagonNumbers()` dovrebbe restituire 5482660.
```js ```js
assert.strictEqual(pentagonNumbers(), 5482660); assert.strictEqual(pentagonNumbers(), 5482660);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3991000cf542c50feac id: 5900f3991000cf542c50feac
title: 'Problem 45: Triangular, pentagonal, and hexagonal' title: 'Problema 45: triangolari, pentagonali ed esagonali'
challengeType: 5 challengeType: 5
forumTopicId: 302122 forumTopicId: 302122
dashedName: problem-45-triangular-pentagonal-and-hexagonal dashedName: problem-45-triangular-pentagonal-and-hexagonal
@ -8,25 +8,25 @@ dashedName: problem-45-triangular-pentagonal-and-hexagonal
# --description-- # --description--
Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Numeri triangolari, pentagonali, ed esagonali sono generati dalle seguenti formule:
<div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Triangle</div><div>T<sub>n</sub>=<var>n</var>(<var>n</var>+1)/2</div><div>1, 3, 6, 10, 15, ...</div></div> <div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Triangolare</div><div>T<sub>n</sub>=<var>n</var>(<var>n</var>+1)/2</div><div>1, 3, 6, 10, 15, ...</div></div>
<div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Pentagonal</div><div>P<sub>n</sub>=<var>n</var>(3<var>n</var>1)/2</div><div>1, 5, 12, 22, 35, ...</div></div> <div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Pentagonale</div><div>P<sub>n</sub>=<var>n</var>(3<var>n</var>1)/2</div><div>1, 5, 12, 22, 35, ...</div></div>
<div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Hexagonal</div><div>H<sub>n</sub>=<var>n</var>(2<var>n</var>1)</div><div>1, 6, 15, 28, 45, ...</div></div> <div style='display: inline-grid; text-align: center; grid-template-columns: 135px 135px 260px; grid-template-rows: auto;'><div>Esagonale</div><div>H<sub>n</sub>=<var>n</var>(2<var>n</var>1)</div><div>1, 6, 15, 28, 45, ...</div></div>
It can be verified that T<sub>285</sub> = P<sub>165</sub> = H<sub>143</sub> = 40755. Si può verificare che T<sub>285</sub> = P<sub>165</sub> = H<sub>143</sub> = 40755.
Find the next triangle number that is also pentagonal and hexagonal. Trova il numero triangolare successivo che è anche pentagonale ed esagonale.
# --hints-- # --hints--
`triPentaHexa(40756)` should return a number. `triPentaHexa(40756)` dovrebbe restituire un numero.
```js ```js
assert(typeof triPentaHexa(40756) === 'number'); assert(typeof triPentaHexa(40756) === 'number');
``` ```
`triPentaHexa(40756)` should return 1533776805. `triPentaHexa(40756)` dovrebbe restituire 1533776805.
```js ```js
assert.strictEqual(triPentaHexa(40756), 1533776805); assert.strictEqual(triPentaHexa(40756), 1533776805);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39a1000cf542c50fead id: 5900f39a1000cf542c50fead
title: 'Problem 46: Goldbach''s other conjecture' title: 'Problema 46: L''altra congettura di Goldbach'
challengeType: 5 challengeType: 5
forumTopicId: 302134 forumTopicId: 302134
dashedName: problem-46-goldbachs-other-conjecture dashedName: problem-46-goldbachs-other-conjecture
@ -8,7 +8,7 @@ dashedName: problem-46-goldbachs-other-conjecture
# --description-- # --description--
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. È stato proposto da Christian Goldbach che ogni numero dispari composito può essere scritto come la somma di un primo e due volte un quadrato.
<div style='margin-left: 2em;'> <div style='margin-left: 2em;'>
9 = 7 + 2×1<sup>2</sup><br> 9 = 7 + 2×1<sup>2</sup><br>
@ -19,19 +19,19 @@ It was proposed by Christian Goldbach that every odd composite number can be wri
33 = 31 + 2×1<sup>2</sup> 33 = 31 + 2×1<sup>2</sup>
</div> </div>
It turns out that the conjecture was false. Si scoprì che la congettura era falsa.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square? Qual è il più piccolo composito dispari che non può essere scritto come la somma di un primo e due volte un quadrato?
# --hints-- # --hints--
`goldbachsOtherConjecture()` should return a number. `goldbachsOtherConjecture()` dovrebbe restituire un numero.
```js ```js
assert(typeof goldbachsOtherConjecture() === 'number'); assert(typeof goldbachsOtherConjecture() === 'number');
``` ```
`goldbachsOtherConjecture()` should return 5777. `goldbachsOtherConjecture()` dovrebbe restituire 5777.
```js ```js
assert.strictEqual(goldbachsOtherConjecture(), 5777); assert.strictEqual(goldbachsOtherConjecture(), 5777);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39c1000cf542c50feae id: 5900f39c1000cf542c50feae
title: 'Problem 47: Distinct primes factors' title: 'Problema 47: Fattori primi distinti'
challengeType: 5 challengeType: 5
forumTopicId: 302145 forumTopicId: 302145
dashedName: problem-47-distinct-primes-factors dashedName: problem-47-distinct-primes-factors
@ -8,14 +8,14 @@ dashedName: problem-47-distinct-primes-factors
# --description-- # --description--
The first two consecutive numbers to have two distinct prime factors are: I primi due numeri consecutivi ad avere due distinti fattori primi sono:
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
14 = 2 × 7<br> 14 = 2 × 7<br>
15 = 3 × 5 15 = 3 × 5
</div> </div>
The first three consecutive numbers to have three distinct prime factors are: I primi tre numeri consecutivi che hanno tre fattori primi distinti sono:
<div style='padding-left: 4em;'> <div style='padding-left: 4em;'>
644 = 2<sup>2</sup> × 7 × 23<br> 644 = 2<sup>2</sup> × 7 × 23<br>
@ -23,29 +23,29 @@ The first three consecutive numbers to have three distinct prime factors are:
646 = 2 × 17 × 19 646 = 2 × 17 × 19
</div> </div>
Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers? Trova i primi quattro interi consecutivi ad avere quattro distinti fattori primi ciascuno. Qual è il primo di questi numeri?
# --hints-- # --hints--
`distinctPrimeFactors(2, 2)` should return a number. `distinctPrimeFactors(2, 2)` dovrebbe restituire un numero.
```js ```js
assert(typeof distinctPrimeFactors(2, 2) === 'number'); assert(typeof distinctPrimeFactors(2, 2) === 'number');
``` ```
`distinctPrimeFactors(2, 2)` should return 14. `distinctPrimeFactors(2, 2)` dovrebbe restituire 14.
```js ```js
assert.strictEqual(distinctPrimeFactors(2, 2), 14); assert.strictEqual(distinctPrimeFactors(2, 2), 14);
``` ```
`distinctPrimeFactors(3, 3)` should return 644. `distinctPrimeFactors(3, 3)` dovrebbe restituire 644.
```js ```js
assert.strictEqual(distinctPrimeFactors(3, 3), 644); assert.strictEqual(distinctPrimeFactors(3, 3), 644);
``` ```
`distinctPrimeFactors(4, 4)` should return 134043. `distinctPrimeFactors(4, 4)` dovrebbe restituire 134043.
```js ```js
assert.strictEqual(distinctPrimeFactors(4, 4), 134043); assert.strictEqual(distinctPrimeFactors(4, 4), 134043);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39c1000cf542c50feaf id: 5900f39c1000cf542c50feaf
title: 'Problem 48: Self powers' title: 'Problema 48: auto-potenze'
challengeType: 5 challengeType: 5
forumTopicId: 302157 forumTopicId: 302157
dashedName: problem-48-self-powers dashedName: problem-48-self-powers
@ -8,37 +8,37 @@ dashedName: problem-48-self-powers
# --description-- # --description--
The series, 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + ... + 10<sup>10</sup> = 10405071317. La serie 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + ... + 10<sup>10</sup> = 10405071317.
Find the last ten digits of the series, 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + ... + 1000<sup>1000</sup>. Trova le ultime dieci cifre della serie 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + ... + 1000<sup>1000</sup>.
# --hints-- # --hints--
`selfPowers(10, 3)` should return a number. `selfPowers(10, 3)` dovrebbe restituire un numero.
```js ```js
assert(typeof selfPowers(10, 3) === 'number'); assert(typeof selfPowers(10, 3) === 'number');
``` ```
`selfPowers(10, 3)` should return 317. `selfPowers(10, 3)` dovrebbe restituire 317.
```js ```js
assert.strictEqual(selfPowers(10, 3), 317); assert.strictEqual(selfPowers(10, 3), 317);
``` ```
`selfPowers(150, 6)` should return 29045. `selfPowers(150, 6)` dovrebbe restituire 29045.
```js ```js
assert.strictEqual(selfPowers(150, 6), 29045); assert.strictEqual(selfPowers(150, 6), 29045);
``` ```
`selfPowers(673, 7)` should return 2473989. `selfPowers(673, 7)` dovrebbe restituire 2473989.
```js ```js
assert.strictEqual(selfPowers(673, 7), 2473989); assert.strictEqual(selfPowers(673, 7), 2473989);
``` ```
`selfPowers(1000, 10)` should return 9110846700. `selfPowers(1000, 10)` dovrebbe restituire 9110846700.
```js ```js
assert.strictEqual(selfPowers(1000, 10), 9110846700); assert.strictEqual(selfPowers(1000, 10), 9110846700);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39d1000cf542c50feb0 id: 5900f39d1000cf542c50feb0
title: 'Problem 49: Prime permutations' title: 'Problema 49: permutazioni di numeri primi'
challengeType: 5 challengeType: 5
forumTopicId: 302159 forumTopicId: 302159
dashedName: problem-49-prime-permutations dashedName: problem-49-prime-permutations
@ -8,21 +8,21 @@ dashedName: problem-49-prime-permutations
# --description-- # --description--
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another. La sequenza aritmetica, 1487, 4817, 8147, in cui ognuno dei termini cresce di 3330, è inusuale in due modi: (i) i tre termini sono primi, e, (ii) i tre numeri sono permutazioni.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence. Non ci sono sequenze aritmetiche fatte di numeri primi a 1, 2 o 3 cifre che esibiscono questa proprietà, ma ce ne è un'altra sequenza crescente a 4 cifre.
What 12-digit number do you form by concatenating the three terms in this sequence? Quale numero a 12 cifre ottieni concatenando i tre termini di questa sequenza?
# --hints-- # --hints--
`primePermutations()` should return a number. `primePermutations()` dovrebbe restituire un numero.
```js ```js
assert(typeof primePermutations() === 'number'); assert(typeof primePermutations() === 'number');
``` ```
`primePermutations()` should return 296962999629. `primePermutations()` dovrebbe restituire 296962999629.
```js ```js
assert.strictEqual(primePermutations(), 296962999629); assert.strictEqual(primePermutations(), 296962999629);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39e1000cf542c50feb1 id: 5900f39e1000cf542c50feb1
title: 'Problem 50: Consecutive prime sum' title: 'Problema 50: somma di primi consecutivi'
challengeType: 5 challengeType: 5
forumTopicId: 302161 forumTopicId: 302161
dashedName: problem-50-consecutive-prime-sum dashedName: problem-50-consecutive-prime-sum
@ -8,31 +8,31 @@ dashedName: problem-50-consecutive-prime-sum
# --description-- # --description--
The prime 41, can be written as the sum of six consecutive primes: Il primo 41, può essere scritto come la somma di sei primi consecutivi:
<div style='text-align: center;'>41 = 2 + 3 + 5 + 7 + 11 + 13</div> <div style='text-align: center;'>41 = 2 + 3 + 5 + 7 + 11 + 13</div>
This is the longest sum of consecutive primes that adds to a prime below one-hundred. Questa è la somma più lunga di primi consecutivi che dà come somma un primo sotto il cento.
The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953. La somma più lunga di primi consecutivi sotto il mille che dà come somma un primo, contiene 21 termini, ed è pari a 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes? Quale primo, al di sotto di un milione, può essere scritto come la somma del maggior numero di numeri primi consecutivi?
# --hints-- # --hints--
`consecutivePrimeSum(1000)` should return a number. `consecutivePrimeSum(1000)` dovrebbe restituire un numero.
```js ```js
assert(typeof consecutivePrimeSum(1000) === 'number'); assert(typeof consecutivePrimeSum(1000) === 'number');
``` ```
`consecutivePrimeSum(1000)` should return 953. `consecutivePrimeSum(1000)` dovrebbe restituire 953.
```js ```js
assert.strictEqual(consecutivePrimeSum(1000), 953); assert.strictEqual(consecutivePrimeSum(1000), 953);
``` ```
`consecutivePrimeSum(1000000)` should return 997651. `consecutivePrimeSum(1000000)` dovrebbe restituire 997651.
```js ```js
assert.strictEqual(consecutivePrimeSum(1000000), 997651); assert.strictEqual(consecutivePrimeSum(1000000), 997651);
@ -54,42 +54,70 @@ consecutivePrimeSum(1000000);
# --solutions-- # --solutions--
```js ```js
// Initalize prime number list with sieve
const NUM_PRIMES = 1000000;
const PRIMES = [2];
const PRIME_SIEVE = Array(Math.floor((NUM_PRIMES-1)/2)).fill(true);
(function initPrimes(num) {
const upper = Math.floor((num - 1) / 2);
const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2);
for (let i = 0; i <= sqrtUpper; i++) {
if (PRIME_SIEVE[i]) {
// Mark value in PRIMES array
const prime = 2 * i + 3;
PRIMES.push(prime);
// Mark all multiples of this number as false (not prime)
const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3;
for (let j = primeSqaredIndex; j < upper; j += prime)
PRIME_SIEVE[j] = false;
}
}
for (let i = sqrtUpper + 1; i < upper; i++) {
if (PRIME_SIEVE[i])
PRIMES.push(2 * i + 3);
}
})(NUM_PRIMES);
function isPrime(num) {
if (num === 2)
return true;
else if (num % 2 === 0)
return false
else
return PRIME_SIEVE[(num - 3) / 2];
}
function consecutivePrimeSum(limit) { function consecutivePrimeSum(limit) {
function isPrime(num) { // Initalize for longest sum < 100
if (num < 2) { let bestPrime = 41;
return false; let bestI = 0;
} else if (num === 2) { let bestJ = 5;
return true;
}
const sqrtOfNum = Math.floor(num ** 0.5);
for (let i = 2; i <= sqrtOfNum + 1; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
function getPrimes(limit) {
const primes = [];
for (let i = 0; i <= limit; i++) {
if (isPrime(i)) primes.push(i);
}
return primes;
}
const primes = getPrimes(limit); // Find longest sum < limit
let primeSum = [...primes]; let sumOfCurrRange = 41;
primeSum.reduce((acc, n, i) => { let i = 0, j = 5;
primeSum[i] += acc; // -- Loop while current some starting at i is < limit
return acc += n; while (sumOfCurrRange < limit) {
}, 0); let currSum = sumOfCurrRange;
// -- Loop while pushing j towards end of PRIMES list
for (let j = primeSum.length - 1; j >= 0; j--) { // keeping sum under limit
for (let i = 0; i < j; i++) { while (currSum < limit) {
const sum = primeSum[j] - primeSum[i]; if (isPrime(currSum)) {
if (sum > limit) break; bestPrime = sumOfCurrRange = currSum;
if (isPrime(sum) && primes.indexOf(sum) > -1) return sum; bestI = i;
bestJ = j;
} }
// -- Increment inner loop
j++;
currSum += PRIMES[j];
} }
// -- Increment outer loop
i++;
j = i + (bestJ - bestI);
sumOfCurrRange -= PRIMES[i - 1];
sumOfCurrRange += PRIMES[j];
}
// Return
return bestPrime;
} }
``` ```

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f39f1000cf542c50feb2 id: 5900f39f1000cf542c50feb2
title: 'Problem 51: Prime digit replacements' title: 'Problema 51: sostituzioni di cifre nei primi'
challengeType: 5 challengeType: 5
forumTopicId: 302162 forumTopicId: 302162
dashedName: problem-51-prime-digit-replacements dashedName: problem-51-prime-digit-replacements
@ -8,33 +8,33 @@ dashedName: problem-51-prime-digit-replacements
# --description-- # --description--
By replacing the 1st digit of the 2-digit number \*3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime. Sostituendo la prima cifra del numero a 2 cifre \*3, si scopre che sei dei nove valori possibili: 13, 23, 43, 53, 73 e 83, sono tutti primi.
By replacing the 3rd and 4th digits of 56\*\*3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property. Sostituendo la terza e la quarta cifra di 56\*\*3 con la stessa cifra, questo numero a 5 cifre è il primo esempio con sette primi tra i dieci numeri generati, della famiglia: 56003, 56113, 56333, 56443, 56663, 56773 e 56993. Di conseguenza, 56003, essendo il primo membro di questa famiglia, è il più piccolo primo con questa proprietà.
Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an `n` prime value family. Trova il primo più piccolo che, sostituendo parte del numero (non necessariamente cifre adiacenti) con la stessa cifra, fa parte di una famiglia di `n` valori primi.
# --hints-- # --hints--
`primeDigitReplacements(6)` should return a number. `primeDigitReplacements(6)` dovrebbe restituire un numero.
```js ```js
assert(typeof primeDigitReplacements(6) === 'number'); assert(typeof primeDigitReplacements(6) === 'number');
``` ```
`primeDigitReplacements(6)` should return `13`. `primeDigitReplacements(6)` dovrebbe restituire `13`.
```js ```js
assert.strictEqual(primeDigitReplacements(6), 13); assert.strictEqual(primeDigitReplacements(6), 13);
``` ```
`primeDigitReplacements(7)` should return `56003`. `primeDigitReplacements(7)` dovrebbe restituire `56003`.
```js ```js
assert.strictEqual(primeDigitReplacements(7), 56003); assert.strictEqual(primeDigitReplacements(7), 56003);
``` ```
`primeDigitReplacements(8)` should return `121313`. `primeDigitReplacements(8)` dovrebbe restituire `121313`.
```js ```js
assert.strictEqual(primeDigitReplacements(8), 121313); assert.strictEqual(primeDigitReplacements(8), 121313);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a01000cf542c50feb3 id: 5900f3a01000cf542c50feb3
title: 'Problem 52: Permuted multiples' title: 'Problema 52: multipli permutati'
challengeType: 5 challengeType: 5
forumTopicId: 302163 forumTopicId: 302163
dashedName: problem-52-permuted-multiples dashedName: problem-52-permuted-multiples
@ -8,25 +8,25 @@ dashedName: problem-52-permuted-multiples
# --description-- # --description--
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Si può notare che il numero 125874 e il suo doppio, 251748, contengono esattamente le stesse cifre, ma in un ordine differente.
Find the smallest positive integer, such that multiplied by integers $\\{2, 3, \ldots, n\\}$, contain the same digits. Trova il più piccolo numero intero positivo, che moltiplicato per gli interi $\\{2, 3, \ldots, n\\}$, contenga le stesse cifre.
# --hints-- # --hints--
`permutedMultiples(2)` should return a number. `permutedMultiples(2)` dovrebbe restituire un numero.
```js ```js
assert(typeof permutedMultiples(2) === 'number'); assert(typeof permutedMultiples(2) === 'number');
``` ```
`permutedMultiples(2)` should return `125874`. `permutedMultiples(2)` dovrebbe restituire `125874`.
```js ```js
assert.strictEqual(permutedMultiples(2), 125874); assert.strictEqual(permutedMultiples(2), 125874);
``` ```
`permutedMultiples(6)` should return `142857`. `permutedMultiples(6)` dovrebbe restituire `142857`.
```js ```js
assert.strictEqual(permutedMultiples(6), 142857); assert.strictEqual(permutedMultiples(6), 142857);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a11000cf542c50feb4 id: 5900f3a11000cf542c50feb4
title: 'Problem 53: Combinatoric selections' title: 'Problema 53: selezione combinatoria'
challengeType: 5 challengeType: 5
forumTopicId: 302164 forumTopicId: 302164
dashedName: problem-53-combinatoric-selections dashedName: problem-53-combinatoric-selections
@ -8,45 +8,45 @@ dashedName: problem-53-combinatoric-selections
# --description-- # --description--
There are exactly ten ways of selecting three from five, 12345: Ci sono esattamente dieci modi di selezionare tre da cinque, 12345:
<div style='text-align: center;'>123, 124, 125, 134, 135, 145, 234, 235, 245, and 345</div> <div style='text-align: center;'>123, 124, 125, 134, 135, 145, 234, 235, 245, e 345</div>
In combinatorics, we use the notation, $\\displaystyle \\binom 5 3 = 10$ In statistica combinatoria, usiamo la notazione, $\\displaystyle \\binom 5 3 = 10$
In general, $\\displaystyle \\binom n r = \\dfrac{n!}{r!(n-r)!}$, where $r \\le n$, $n! = n \\times (n-1) \\times ... \\times 3 \\times 2 \\times 1$, and $0! = 1$. In generals, $\\displaystyle \\binom n r = \\dfrac{n!}{r!(n-r)!}$, dove $r \\le n$, $n! = n \\times (n-1) \\times ... \\times 3 \\times 2 \\times 1$, e $0! = 1$.
It is not until $n = 23$, that a value exceeds one-million: $\\displaystyle \\binom {23} {10} = 1144066$. È solo raggiungendo $n = 23$, che un valore eccede un milione: $\\displaystyle \\binom {23} {10} = 1144066$.
How many, not necessarily distinct, values of $\\displaystyle \\binom n r$ for $1 \\le n \\le 100$, are greater than one-million? Quanti, non necessariamente distinti, valori di $\\displaystyle \\binom n r$ per $1 \\le n \\le 100$, sono più grandi di un milione?
# --hints-- # --hints--
`combinatoricSelections(1000)` should return a number. `combinatoricSelections(1000)` dovrebbe restituire un numero.
```js ```js
assert(typeof combinatoricSelections(1000) === 'number'); assert(typeof combinatoricSelections(1000) === 'number');
``` ```
`combinatoricSelections(1000)` should return 4626. `combinatoricSelections(1000)` dovrebbe restituire 4626.
```js ```js
assert.strictEqual(combinatoricSelections(1000), 4626); assert.strictEqual(combinatoricSelections(1000), 4626);
``` ```
`combinatoricSelections(10000)` should return 4431. `combinatoricSelections(10000)` dovrebbe restituire 4431.
```js ```js
assert.strictEqual(combinatoricSelections(10000), 4431); assert.strictEqual(combinatoricSelections(10000), 4431);
``` ```
`combinatoricSelections(100000)` should return 4255. `combinatoricSelections(100000)` dovrebbe restituire 4255.
```js ```js
assert.strictEqual(combinatoricSelections(100000), 4255); assert.strictEqual(combinatoricSelections(100000), 4255);
``` ```
`combinatoricSelections(1000000)` should return 4075. `combinatoricSelections(1000000)` dovrebbe restituire 4075.
```js ```js
assert.strictEqual(combinatoricSelections(1000000), 4075); assert.strictEqual(combinatoricSelections(1000000), 4075);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a21000cf542c50feb5 id: 5900f3a21000cf542c50feb5
title: 'Problem 54: Poker hands' title: 'Problema 54: mani di poker'
challengeType: 5 challengeType: 5
forumTopicId: 302165 forumTopicId: 302165
dashedName: problem-54-poker-hands dashedName: problem-54-poker-hands
@ -8,54 +8,54 @@ dashedName: problem-54-poker-hands
# --description-- # --description--
In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: Nel gioco di carte del poker, una mano è composta da cinque carte ed esse sono classificate, dalla più bassa alla più alta, nel modo seguente:
<ul> <ul>
<li>High Card: Highest value card.</li> <li>Carta alta: Carta di valore più alto.</li>
<li>One Pair: Two cards of the same value.</li> <li>Una coppia: due carte dello stesso valore.</li>
<li>Two Pairs: Two different pairs.</li> <li>Due coppie: due coppie diverse.</li>
<li>Three of a Kind: Three cards of the same value.</li> <li>Tre di un tipo: tre carte dello stesso valore.</li>
<li>Straight: All cards are consecutive values.</li> <li>Straight: tutte le carte hanno valori consecutivi.</li>
<li>Flush: All cards of the same suit.</li> <li>Flush: Tutte le carte dello stesso seme.</li>
<li>Full House: Three of a kind and a pair.</li> <li>Casa Completa: Tre di un tipo e una coppia.</li>
<li>Four of a Kind: Four cards of the same value.</li> <li>Quattro di un tipo: Quattro carte dello stesso valore.</li>
<li>Straight Flush: All cards are consecutive values of same suit.</li> <li>Scala: Tutte le carte sono valori consecutivi dello stesso seme.</li>
<li>Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.</li> <li>Scala reale: Dieci, Jack, Regina, Re, Asso, nello stesso seme.</li>
</ul> </ul>
The cards are valued in the order: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. Le carte sono valutate nell'ordine: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Regina, Re, Asso.
If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on. Se due giocatori hanno mani dello stesso valore, allora il grado composto dal valore più alto vince; per esempio, un paio di otto batte un paio di cinque (vedi esempio 1 di seguito). Ma se due gradi sono pari, per esempio, entrambi i giocatori hanno un paio di regine, vengono confrontate le carte più alte in ogni mano (vedi esempio 4 in basso); se le carte più alte sonio pari allora vengono confrontate le carte più alte successive, e così via.
Consider the following five hands dealt to two players: Considera le seguenti cinque mani distribuite a due giocatori:
| Hand | Player 1 | Player 2 | Winner | | Mano | Giocatore 1 | Giocatore 2 | Vincitore |
| ------------------------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------- | -------- | | ------------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ----------- |
| <strong>1</strong> | 5H 5C 6S 7S KD <br> Pair of Fives | 2C 3S 8S 8D TD <br> Pair of Eights | Player 2 | | <strong>1</strong> | 5H 5C 6S 7S KD <br> Coppia di cinque | 2C 3S 8S 8D TD <br> Coppia di otto | Giocatore 2 |
| <strong>2</strong> | 5D 8C 9S JS AC <br> Highest card Ace | 2C 5C 7D 8S QH <br> Highest card Queen | Player 1 | | <strong>2</strong> | 5D 8C 9S JS AC <br> Carta più alta Asso | 2C 5C 7D 8S QH <br> Carta più alta Regina | Giocatore 1 |
| <strong>3</strong> | 2D 9C AS AH AC <br> Three Aces | 3D 6D 7D TD QD <br> Flush with Diamonds | Player 2 | | <strong>3</strong> | 2D 9C AS AH AC <br> Tre assi | 3D 6D 7D TD QD <br> Full di quadri | Giocatore 2 |
| <strong>4</strong> | 4D 6S 9H QH QC <br> Pair of Queens <br> Highest card Nine | 3D 6D 7H QD QS <br> Pair of Queens <br> Highest card Seven | Player 1 | | <strong>4</strong> | 4D 6S 9H QH QC <br> Coppia di Regine <br> Carta più alta Nove | 3D 6D 7H QD QS <br> Coppia di Regine <br> Carta più alta Sette | Giocatore 1 |
| <strong>5</strong> | 2H 2D 4C 4D 4S <br> Full House <br> with Three Fours | 3C 3D 3S 9S 9D <br> Full House <br> with Three Threes | Player 1 | | <strong>5</strong> | 2H 2D 4C 4D 4S <br> Full <br> con tre Quattro | 3C 3D 3S 9S 9D <br> Full <br> con tre Tre | Giocatore 1 |
The global array (`handsArr`) passed to the function, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1's cards and the last five are Player 2's cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player's hand is in no specific order, and in each hand there is a clear winner. L'array globale (`handsArr`) passato alla funzione, contiene mille mani casuali distribuite a due giocatori. Ogni riga del file contiene dieci carte (separate da uno spazio singolo): le prime cinque sono carte del giocatore 1 e le ultime cinque sono carte del giocatore 2. Si può presumere che tutte le mani siano valide (nessun carattere non valido o carte ripetute), la mano di ogni giocatore non è in ordine specifico, e in ogni mano c'è un chiaro vincitore.
How many hands does Player 1 win? In quante mani vince Giocatore 1?
# --hints-- # --hints--
`pokerHands(testArr)` should return a number. `pokerHands(testArr)` dovrebbe restituire un numero.
```js ```js
assert(typeof pokerHands(testArr) === 'number'); assert(typeof pokerHands(testArr) === 'number');
``` ```
`pokerHands(testArr)` should return 2. `pokerHands(testArr)` dovrebbe restituire 2.
```js ```js
assert.strictEqual(pokerHands(testArr), 2); assert.strictEqual(pokerHands(testArr), 2);
``` ```
`pokerHands(handsArr)` should return 376. `pokerHands(handsArr)` dovrebbe restituire 376.
```js ```js
assert.strictEqual(pokerHands(handsArr), 376); assert.strictEqual(pokerHands(handsArr), 376);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a31000cf542c50feb6 id: 5900f3a31000cf542c50feb6
title: 'Problem 55: Lychrel numbers' title: 'Problema 55: numeri di Lychrel'
challengeType: 5 challengeType: 5
forumTopicId: 302166 forumTopicId: 302166
dashedName: problem-55-lychrel-numbers dashedName: problem-55-lychrel-numbers
@ -8,9 +8,9 @@ dashedName: problem-55-lychrel-numbers
# --description-- # --description--
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Se prendiamo 47, e gli sommiamo lo speculare, 47 + 74 = 121, che è palindromo.
Not all numbers produce palindromes so quickly. For example, Non tutti i numeri producono palindromi così rapidamente. Ad esempio,
<div style="margin-left: 4em;"> <div style="margin-left: 4em;">
349 + 943 = 1292,<br> 349 + 943 = 1292,<br>
@ -18,49 +18,49 @@ Not all numbers produce palindromes so quickly. For example,
4213 + 3124 = 7337<br> 4213 + 3124 = 7337<br>
</div> </div>
That is, 349 took three iterations to arrive at a palindrome. Cioè 349 richiede tre iterazioni per arrivare a un palindromo.
Although no one has proved it yet, it is thought that some numbers, like 196, never produce a palindrome. A number that never forms a palindrome through the reverse and add process is called a Lychrel number. Due to the theoretical nature of these numbers, and for the purpose of this problem, we shall assume that a number is Lychrel until proven otherwise. In addition you are given that for every number below ten-thousand, it will either (i) become a palindrome in less than fifty iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome. In fact, 10677 is the first number to be shown to require over fifty iterations before producing a palindrome: 4668731596684224866951378664 (53 iterations, 28-digits). Anche se nessuno lo ha ancora dimostrato, si pensa che alcuni numeri, come il 196, non producano mai un palindromo. Un numero che non forma mai un palindromo attraverso un processo di inversione e addizione è chiamato numero di Lychrel. Data la teoretica natura di questi numeri, e per il proposito di questo problema, assumiamo che un numero è un numeri di Lychrel fino a prova contraria. In aggiunta ti è dato che per ogni numero al di sotto di diecimila, questo (i) diventerà un palindromo in meno di cinquanta iterazioni, oppure, (ii), nessuno, con tutto il potere computazionale che esiste, è riuscito fin ora a mapparlo ad un palindromo. Infatti, 10677 è il primo numero trovato per cui sono necessarie più di cinquanta iterazioni prima di produrre un palindromo: 4668731596684224866951378664 (53 iterazioni, 28-cifre).
Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is 4994. Sorprendentemente, ci sono numeri palindromi che sono a loro volta numeri di Lychrel; il primo esempio è 4994.
How many Lychrel numbers are there below `num`? Quanti numeri di Lychrel ci sono sotto `num`?
**Note:** Wording was modified slightly on 24 April 2007 to emphasize the theoretical nature of Lychrel numbers. **Nota:** La descrizione è stata modificata leggermente il giorno 24 Aprile 2007 per enfatizzare la natura teoretica dei numeri di Lychrel.
# --hints-- # --hints--
`countLychrelNumbers(1000)` should return a number. `countLychrelNumbers(1000)` dovrebbe restituire un numero.
```js ```js
assert(typeof countLychrelNumbers(1000) === 'number'); assert(typeof countLychrelNumbers(1000) === 'number');
``` ```
`countLychrelNumbers(1000)` should return 13. `countLychrelNumbers(1000)` dovrebbe restituire 13.
```js ```js
assert.strictEqual(countLychrelNumbers(1000), 13); assert.strictEqual(countLychrelNumbers(1000), 13);
``` ```
`countLychrelNumbers(3243)` should return 39. `countLychrelNumbers(3243)` dovrebbe restituire 39.
```js ```js
assert.strictEqual(countLychrelNumbers(3243), 39); assert.strictEqual(countLychrelNumbers(3243), 39);
``` ```
`countLychrelNumbers(5000)` should return 76. `countLychrelNumbers(5000)` dovrebbe restituire 76.
```js ```js
assert.strictEqual(countLychrelNumbers(5000), 76); assert.strictEqual(countLychrelNumbers(5000), 76);
``` ```
`countLychrelNumbers(7654)` should return 140. `countLychrelNumbers(7654)` dovrebbe restituire 140.
```js ```js
assert.strictEqual(countLychrelNumbers(7654), 140); assert.strictEqual(countLychrelNumbers(7654), 140);
``` ```
`countLychrelNumbers(10000)` should return 249. `countLychrelNumbers(10000)` dovrebbe restituire 249.
```js ```js
assert.strictEqual(countLychrelNumbers(10000), 249); assert.strictEqual(countLychrelNumbers(10000), 249);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a41000cf542c50feb7 id: 5900f3a41000cf542c50feb7
title: 'Problem 56: Powerful digit sum' title: 'Problema 56: Somma delle cifre della potenza'
challengeType: 5 challengeType: 5
forumTopicId: 302167 forumTopicId: 302167
dashedName: problem-56-powerful-digit-sum dashedName: problem-56-powerful-digit-sum
@ -8,43 +8,43 @@ dashedName: problem-56-powerful-digit-sum
# --description-- # --description--
A googol ($10^{100}$) is a massive number: one followed by one-hundred zeros; $100^{100}$ is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1. Un googol ($10^{100}$) è un numero massivo: uno seguito da cento zeri; $100^{100}$ è un numero inimmaginabilmente grande: uno seguito da duecento zeri. Nonostante la loro dimensione, la somma delle cifre in ogni numero è solo 1.
Considering natural numbers of the form, $a^b$, where `a`, `b` &lt; `n`, what is the maximum digital sum? Considerando numeri naturali nella forma, $a^b$, dove `a`, `b` &lt; `n`, qual è la somma massima delle cifre?
# --hints-- # --hints--
`powerfulDigitSum(3)` should return a number. `powerfulDigitSum(3)` dovrebbe restituire un numero.
```js ```js
assert(typeof powerfulDigitSum(3) === 'number'); assert(typeof powerfulDigitSum(3) === 'number');
``` ```
`powerfulDigitSum(3)` should return `4`. `powerfulDigitSum(3)` dovrebbe restituire `4`.
```js ```js
assert.strictEqual(powerfulDigitSum(3), 4); assert.strictEqual(powerfulDigitSum(3), 4);
``` ```
`powerfulDigitSum(10)` should return `45`. `powerfulDigitSum(10)` dovrebbe restituire `45`.
```js ```js
assert.strictEqual(powerfulDigitSum(10), 45); assert.strictEqual(powerfulDigitSum(10), 45);
``` ```
`powerfulDigitSum(50)` should return `406`. `powerfulDigitSum(50)` dovrebbe restituire `406`.
```js ```js
assert.strictEqual(powerfulDigitSum(50), 406); assert.strictEqual(powerfulDigitSum(50), 406);
``` ```
`powerfulDigitSum(75)` should return `684`. `powerfulDigitSum(75)` dovrebbe restituire `684`.
```js ```js
assert.strictEqual(powerfulDigitSum(75), 684); assert.strictEqual(powerfulDigitSum(75), 684);
``` ```
`powerfulDigitSum(100)` should return `972`. `powerfulDigitSum(100)` dovrebbe restituire `972`.
```js ```js
assert.strictEqual(powerfulDigitSum(100), 972); assert.strictEqual(powerfulDigitSum(100), 972);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a51000cf542c50feb8 id: 5900f3a51000cf542c50feb8
title: 'Problem 57: Square root convergents' title: 'Problema 57: Radici quadrate convergenti'
challengeType: 5 challengeType: 5
forumTopicId: 302168 forumTopicId: 302168
dashedName: problem-57-square-root-convergents dashedName: problem-57-square-root-convergents
@ -8,11 +8,11 @@ dashedName: problem-57-square-root-convergents
# --description-- # --description--
It is possible to show that the square root of two can be expressed as an infinite continued fraction. È possibile dimostrare che la radice quadrata di due può essere espressa come una frazione infinita continua.
<div style='text-align: center;'>$\sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}}$</div> <div style='text-align: center;'>$\sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}}$</div>
By expanding this for the first four iterations, we get: Espandendola per le prime quattro iterazioni, otteniamo:
$1 + \\frac 1 2 = \\frac 32 = 1.5$ $1 + \\frac 1 2 = \\frac 32 = 1.5$
@ -22,31 +22,31 @@ $1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 2}} = \\frac {17}{12} = 1.41666 \\dots$
$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 {2+\\frac 1 2}}} = \\frac {41}{29} = 1.41379 \\dots$ $1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 {2+\\frac 1 2}}} = \\frac {41}{29} = 1.41379 \\dots$
The next three expansions are $\\frac {99}{70}$, $\\frac {239}{169}$, and $\\frac {577}{408}$, but the eighth expansion, $\\frac {1393}{985}$, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator. Le prossime tre espansioni sono $\\frac {99}{70}$, $\\frac {239}{169}$, e $\\frac {577}{408}$, ma l'ottava espansione, $\\frac {1393}{985}$, è il primo esempio in cui il numero di cifre nel numeratore supera il numero di cifre nel denominatore.
In the first `n` expansions, how many fractions contain a numerator with more digits than denominator? Nelle prime espansioni `n`, quante frazioni contengono un numeratore con più cifre di denominatore?
# --hints-- # --hints--
`squareRootConvergents(10)` should return a number. `squareRootConvergents(10)` dovrebbe restituire un numero.
```js ```js
assert(typeof squareRootConvergents(10) === 'number'); assert(typeof squareRootConvergents(10) === 'number');
``` ```
`squareRootConvergents(10)` should return 1. `squareRootConvergents(10)` dovrebbe restituire 1.
```js ```js
assert.strictEqual(squareRootConvergents(10), 1); assert.strictEqual(squareRootConvergents(10), 1);
``` ```
`squareRootConvergents(100)` should return 15. `squareRootConvergents(100)` dovrebbe restituire 15.
```js ```js
assert.strictEqual(squareRootConvergents(100), 15); assert.strictEqual(squareRootConvergents(100), 15);
``` ```
`squareRootConvergents(1000)` should return 153. `squareRootConvergents(1000)` dovrebbe restituire 153.
```js ```js
assert.strictEqual(squareRootConvergents(1000), 153); assert.strictEqual(squareRootConvergents(1000), 153);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a61000cf542c50feb9 id: 5900f3a61000cf542c50feb9
title: 'Problem 58: Spiral primes' title: 'Problema 58: Primi a spirale'
challengeType: 5 challengeType: 5
forumTopicId: 302169 forumTopicId: 302169
dashedName: problem-58-spiral-primes dashedName: problem-58-spiral-primes
@ -8,7 +8,7 @@ dashedName: problem-58-spiral-primes
# --description-- # --description--
Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed. Partendo da 1 e a spirale antioraria nel modo seguente, si forma una spirale quadrata con lunghezza laterale 7.
<div style='text-align: center;'> <div style='text-align: center;'>
<strong><span style='color: red;'>37</span></strong> 36 35 34 33 32 <strong><span style='color: red;'>31</span></strong><br> <strong><span style='color: red;'>37</span></strong> 36 35 34 33 32 <strong><span style='color: red;'>31</span></strong><br>
@ -20,31 +20,31 @@ Starting with 1 and spiralling anticlockwise in the following way, a square spir
<strong><span style='color: red;'>43</span></strong> 44 45 46 47 48 49<br> <strong><span style='color: red;'>43</span></strong> 44 45 46 47 48 49<br>
</div> </div>
It is interesting to note that the odd squares lie along the bottom right diagonal, but what is more interesting is that 8 out of the 13 numbers lying along both diagonals are prime; that is, a ratio of 8/13 ≈ 62%. È interessante notare che i quadrati dispari si trovano lungo la diagonale in basso a destra, ma ciò che è più interessante è che 8 dei 13 numeri che si trovano lungo entrambe le diagonali sono primi, cioè un rapporto di 8/13 ≈ 62%.
If one complete new layer is wrapped around the spiral above, a square spiral with side length 9 will be formed. If this process is continued, what is the side length of the square spiral for which the percent of primes along both diagonals first falls below `percent`? Se un nuovo strato completo è avvolto intorno alla spirale sopra, verrà formata una spirale quadrata con lunghezza laterale 9. Se si prosegue con questo processo, qual è la lunghezza laterale della spirale quadrata per la quale la percentuale di primi lungo entrambe le diagonali cade prima al di sotto del `percent`?
# --hints-- # --hints--
`spiralPrimes(50)` should return a number. `spiralPrimes(50)` dovrebbe restituire un numero.
```js ```js
assert(typeof spiralPrimes(50) === 'number'); assert(typeof spiralPrimes(50) === 'number');
``` ```
`spiralPrimes(50)` should return `11`. `spiralPrimes(50)` dovrebbe restituire `11`.
```js ```js
assert.strictEqual(spiralPrimes(50), 11); assert.strictEqual(spiralPrimes(50), 11);
``` ```
`spiralPrimes(15)` should return `981`. `spiralPrimes(15)` dovrebbe restituire `981`.
```js ```js
assert.strictEqual(spiralPrimes(15), 981); assert.strictEqual(spiralPrimes(15), 981);
``` ```
`spiralPrimes(10)` should return `26241`. `spiralPrimes(10)` dovrebbe restituire `26241`.
```js ```js
assert.strictEqual(spiralPrimes(10), 26241); assert.strictEqual(spiralPrimes(10), 26241);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a81000cf542c50feba id: 5900f3a81000cf542c50feba
title: 'Problem 59: XOR decryption' title: 'Problema 59: decifrazione di XOR'
challengeType: 5 challengeType: 5
forumTopicId: 302170 forumTopicId: 302170
dashedName: problem-59-xor-decryption dashedName: problem-59-xor-decryption
@ -8,25 +8,25 @@ dashedName: problem-59-xor-decryption
# --description-- # --description--
Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (\*) = 42, and lowercase k = 107. Ogni carattere in un computer ha assegnato un unico codice e lo standard preferito è ASCII (American Standard Code for Information Interchange - Codice standard americano per l'interscambio delle informazioni). Per esempio, A maiuscola = 65, asterisco (\*) = 42, e k minuscola = 107.
A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65. Un metodo moderno di codifica è di prendere un file di testo, convertire i byte in ASCII, e poi usare l'operatore XOR su ogni byte con un valore dato, preso da una chiave segreta. Il vantaggio della funzione XOR è che usare la stessa chiave di codifica sul testo cifrato, rigenera il testo iniziare; per esempio, 65 XOR 42 = 107, e 107 XOR 42 = 65.
For unbreakable encryption, the key is the same length as the plain text message, and the key is made up of random bytes. The user would keep the encrypted message and the encryption key in different locations, and without both "halves", it is impossible to decrypt the message. Per una codifica non decodificabile, la chiave è della stessa lunghezza del messaggio e la chiave è fatta di byte random. L'utente deve tenere il messaggio cifrato e la chiave di codifica in due posti diversi, e senza le due "metà", è impossibile decifrare il messaggio.
Unfortunately, this method is impractical for most users, so the modified method is to use a password as a key. If the password is shorter than the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long password key for security, but short enough to be memorable. Sfortunatamente, questo metodo non è pratico per la maggior parte degli utenti, quindi il metodo modificato è di usare una password come chiave. Se la password è più corta del messaggio, cosa che è probabile, allora la chiave è ripetuta ciclicamente lungo il messaggio. L'equilibrio per questo metodo è usare una password sufficientemente lunga per questioni di sicurezza, ma abbastanza corta da essere memorizzabile.
Your task has been made easy, as the encryption key consists of three lower case characters. Using `cipher`, an array containing the encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the ASCII values in the original text. Il tuo compito è stato reso facile, la chiave di sicurezza consiste di tre lettere minuscole. Usando `cipher`, un array contenente i codici ASCII cifrati, e la conoscenza che il messaggio deve contenere parole comuni inglesi, decifra il messaggio e fai la somma dei valori ASCII del messaggio originale.
# --hints-- # --hints--
`XORDecryption(cipher)` should return a number. `XORDecryption(cipher)` dovrebbe restituire un numero.
```js ```js
assert(typeof XORDecryption(cipher) === 'number'); assert(typeof XORDecryption(cipher) === 'number');
``` ```
`XORDecryption(cipher)` should return 129448. `XORDecryption(cipher)` dovrebbe restituire 129448.
```js ```js
assert.strictEqual(XORDecryption(cipher), 129448); assert.strictEqual(XORDecryption(cipher), 129448);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3721000cf542c50fe85 id: 5900f3721000cf542c50fe85
title: 'Problem 6: Sum square difference' title: 'Problema 6: Somma differenza quadrata'
challengeType: 5 challengeType: 5
forumTopicId: 302171 forumTopicId: 302171
dashedName: problem-6-sum-square-difference dashedName: problem-6-sum-square-difference
@ -8,39 +8,39 @@ dashedName: problem-6-sum-square-difference
# --description-- # --description--
The sum of the squares of the first ten natural numbers is, La somma dei quadrati dei primi dieci numeri naturali è,
<div style='text-align: center;'>1<sup>2</sup> + 2<sup>2</sup> + ... + 10<sup>2</sup> = 385</div> <div style='text-align: center;'>1<sup>2</sup> + 2<sup>2</sup> + ... + 10<sup>2</sup> = 385</div>
The square of the sum of the first ten natural numbers is, Il quadrato della somma dei primi dieci numeri naturali è
<div style='text-align: center;'>(1 + 2 + ... + 10)<sup>2</sup> = 55<sup>2</sup> = 3025</div> <div style='text-align: center;'>(1 + 2 + ... + 10)<sup>2</sup> = 55<sup>2</sup> = 3025</div>
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640. Da qui la differenza tra la somma dei quadrati dei primi dieci numeri naturali e il quadrato della somma è 3025 385 = 2640.
Find the difference between the sum of the squares of the first `n` natural numbers and the square of the sum. Trova la differenza tra la somma dei quadrati dei primi `n` numeri naturali e il quadrato della loro somma.
# --hints-- # --hints--
`sumSquareDifference(10)` should return a number. `sumSquareDifference(10)` dovrebbe restituire un numero.
```js ```js
assert(typeof sumSquareDifference(10) === 'number'); assert(typeof sumSquareDifference(10) === 'number');
``` ```
`sumSquareDifference(10)` should return 2640. `sumSquareDifference(10)` dovrebbe restituire 2640.
```js ```js
assert.strictEqual(sumSquareDifference(10), 2640); assert.strictEqual(sumSquareDifference(10), 2640);
``` ```
`sumSquareDifference(20)` should return 41230. `sumSquareDifference(20)` dovrebbe restituire 41230.
```js ```js
assert.strictEqual(sumSquareDifference(20), 41230); assert.strictEqual(sumSquareDifference(20), 41230);
``` ```
`sumSquareDifference(100)` should return 25164150. `sumSquareDifference(100)` dovrebbe restituire 25164150.
```js ```js
assert.strictEqual(sumSquareDifference(100), 25164150); assert.strictEqual(sumSquareDifference(100), 25164150);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a81000cf542c50febb id: 5900f3a81000cf542c50febb
title: 'Problem 60: Prime pair sets' title: 'Problema 60: set di coppie di numeri primi'
challengeType: 5 challengeType: 5
forumTopicId: 302172 forumTopicId: 302172
dashedName: problem-60-prime-pair-sets dashedName: problem-60-prime-pair-sets
@ -8,19 +8,19 @@ dashedName: problem-60-prime-pair-sets
# --description-- # --description--
The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property. I primi 3, 7, 109, e 673 sono degni di nota. Prendendo qualsiasi due di questi numeri e concatenandoli in qualsiasi ordine, il risultato sarà sempre un numero primo. Per esempio, prendendo 7 e 109, sia 7109 che 1097 sono primi. La somma di questi quattro numeri primi, 792, rappresenta la somma più piccola per un set di 4 numeri primi con questa proprietà.
Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime. Trova la somma più piccola per un set di cinque numeri primi in cui due numeri qualsiasi concatenati producono un altri numero primo.
# --hints-- # --hints--
`primePairSets()` should return a number. `primePairSets()` dovrebbe restituire un numero.
```js ```js
assert(typeof primePairSets() === 'number'); assert(typeof primePairSets() === 'number');
``` ```
`primePairSets()` should return 26033. `primePairSets()` dovrebbe restituire 26033.
```js ```js
assert.strictEqual(primePairSets(), 26033); assert.strictEqual(primePairSets(), 26033);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3a91000cf542c50febc id: 5900f3a91000cf542c50febc
title: 'Problem 61: Cyclical figurate numbers' title: 'Problema 61: Numeri ciclici figurati'
challengeType: 5 challengeType: 5
forumTopicId: 302173 forumTopicId: 302173
dashedName: problem-61-cyclical-figurate-numbers dashedName: problem-61-cyclical-figurate-numbers
@ -8,52 +8,52 @@ dashedName: problem-61-cyclical-figurate-numbers
# --description-- # --description--
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae: Numeri triangolari, quadrati, pentagonali, esagonali, eptagonali e ottagonali sono tutti numeri che sono figurati (poligonali) e sono generati dalle seguenti formule:
| Type of Number | Formula | Sequence | | Tipo di numero | Formula | Sequenza |
| -------------- | ----------------------------- | --------------------- | | -------------- | ----------------------------- | --------------------- |
| Triangle | $P_3(n) = \frac{n(n+1)}{2}$ | 1, 3, 6, 10, 15, ... | | Triangolare | $P_3(n) = \frac{n(n+1)}{2}$ | 1, 3, 6, 10, 15, ... |
| Square | $P_4(n) = n^2$ | 1, 4, 9, 16, 25, ... | | Quadrato | $P_4(n) = n^2$ | 1, 4, 9, 16, 25, ... |
| Pentagonal | $P_5(n) = \frac{n(3n1)}2$ | 1, 5, 12, 22, 35, ... | | Pentagonale | $P_5(n) = \frac{n(3n1)}2$ | 1, 5, 12, 22, 35, ... |
| Hexagonal | $P_6(n) = n(2n1)$ | 1, 6, 15, 28, 45, ... | | Esagonale | $P_6(n) = n(2n1)$ | 1, 6, 15, 28, 45, ... |
| Heptagonal | $P_7(n) = \frac{n(5n3)}{2}$ | 1, 7, 18, 34, 55, ... | | Eptagonale | $P_7(n) = \frac{n(5n3)}{2}$ | 1, 7, 18, 34, 55, ... |
| Octagonal | $P_8(n) = n(3n2)$ | 1, 8, 21, 40, 65, ... | | Ottagonale | $P_8(n) = n(3n2)$ | 1, 8, 21, 40, 65, ... |
The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three interesting properties. Il set ordinato nei numeri a 4 cifre: 8128, 2882, 8281, ha tre interessanti proprietà.
1. The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first). 1. Il set è ciclico, in quanto le ultime due cifre di ogni numero sono le prime due cifre del seguente (incluso l'ultimo numero con il primo).
2. Each polygonal type: triangle ($P_3(127) = 8128$), square ($P_4(91) = 8281$), and pentagonal ($P_5(44) = 2882$), is represented by a different number in the set. 2. Ogni tipo poligonale: triangolare ($P_3(127) = 8128$), quadrato ($P_4(91) = 8281$), e pentagonale ($P_5(44) = 2882$), è rappresentato da un diverso numero nel set.
3. This is the only set of 4-digit numbers with this property. 3. Questo è l'unico set con numeri a quattro cifre con questa proprietà.
Find the sum of all numbers in ordered sets of `n` cyclic 4-digit numbers for which each of the $P_3$ to $P_{n + 2}$ polygonal types, is represented by a different number in the set. Trova la somma di tutti i numeri in set ordinati di `n` numeri ciclici a quattro cifre per cui ognuno dei tipi poligonali da $P_3$ a $P_{n + 2}$ è rappresentato da un diverso numero nel set.
# --hints-- # --hints--
`cyclicalFigurateNums(3)` should return a number. `cyclicalFigurateNums(3)` dovrebbe restituire un numero.
```js ```js
assert(typeof cyclicalFigurateNums(3) === 'number'); assert(typeof cyclicalFigurateNums(3) === 'number');
``` ```
`cyclicalFigurateNums(3)` should return `19291`. `cyclicalFigurateNums(3)` dovrebbe restituire `19291`.
```js ```js
assert.strictEqual(cyclicalFigurateNums(3), 19291); assert.strictEqual(cyclicalFigurateNums(3), 19291);
``` ```
`cyclicalFigurateNums(4)` should return `28684`. `cyclicalFigurateNums(4)` dovrebbe restituire `28684`.
```js ```js
assert.strictEqual(cyclicalFigurateNums(4), 28684); assert.strictEqual(cyclicalFigurateNums(4), 28684);
``` ```
`cyclicalFigurateNums(5)` should return `76255`. `cyclicalFigurateNums(5)` dovrebbe restituire `76255`.
```js ```js
assert.strictEqual(cyclicalFigurateNums(5), 76255); assert.strictEqual(cyclicalFigurateNums(5), 76255);
``` ```
`cyclicalFigurateNums(6)` should return `28684`. `cyclicalFigurateNums(6)` dovrebbe restituire `28684`.
```js ```js
assert.strictEqual(cyclicalFigurateNums(6), 28684); assert.strictEqual(cyclicalFigurateNums(6), 28684);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3aa1000cf542c50febd id: 5900f3aa1000cf542c50febd
title: 'Problem 62: Cubic permutations' title: 'Problema 62: permutazioni cubiche'
challengeType: 5 challengeType: 5
forumTopicId: 302174 forumTopicId: 302174
dashedName: problem-62-cubic-permutations dashedName: problem-62-cubic-permutations
@ -8,37 +8,37 @@ dashedName: problem-62-cubic-permutations
# --description-- # --description--
The cube, 41063625 ($345^3$), can be permuted to produce two other cubes: 56623104 ($384^3$) and 66430125 ($405^3$). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube. Il cubo 41063625 ($345^3$), può essere permutato per produrre altri due cubi: 56623104 ($384^3$) e 66430125 ($405^3$). Infatti, 41063625 è il cubo più piccolo che ha esattamente tre permutazioni delle sue cifre che sono anch'esse dei cubi.
Find the smallest cube for which exactly `n` permutations of its digits are cube. Trova il cubo più piccolo per il quale esattamente `n` permutazioni delle sue cifre sono dei cubi.
# --hints-- # --hints--
`cubicPermutations(2)` should return a number. `cubicPermutations(2)` dovrebbe restituire un numero.
```js ```js
assert(typeof cubicPermutations(2) === 'number'); assert(typeof cubicPermutations(2) === 'number');
``` ```
`cubicPermutations(2)` should return `125`. `cubicPermutations(2)` dovrebbe restituire `125`.
```js ```js
assert.strictEqual(cubicPermutations(2), 125); assert.strictEqual(cubicPermutations(2), 125);
``` ```
`cubicPermutations(3)` should return `41063625`. `cubicPermutations(3)` dovrebbe restituire `41063625`.
```js ```js
assert.strictEqual(cubicPermutations(3), 41063625); assert.strictEqual(cubicPermutations(3), 41063625);
``` ```
`cubicPermutations(4)` should return `1006012008`. `cubicPermutations(4)` dovrebbe restituire `1006012008`.
```js ```js
assert.strictEqual(cubicPermutations(4), 1006012008); assert.strictEqual(cubicPermutations(4), 1006012008);
``` ```
`cubicPermutations(5)` should return `127035954683`. `cubicPermutations(5)` dovrebbe restituire `127035954683`.
```js ```js
assert.strictEqual(cubicPermutations(5), 127035954683); assert.strictEqual(cubicPermutations(5), 127035954683);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3ab1000cf542c50febe id: 5900f3ab1000cf542c50febe
title: 'Problem 63: Powerful digit counts' title: 'Problema 63: Conteggio cifre potenti'
challengeType: 5 challengeType: 5
forumTopicId: 302175 forumTopicId: 302175
dashedName: problem-63-powerful-digit-counts dashedName: problem-63-powerful-digit-counts
@ -8,73 +8,73 @@ dashedName: problem-63-powerful-digit-counts
# --description-- # --description--
The 5-digit number, 16807 = 7<sup>5</sup>, is also a fifth power. Similarly, the 9-digit number, 134217728 = 8<sup>9</sup>, is a ninth power. Il numero a 5 cifre, 16807 = 7<sup>5</sup>, è anche una quinta potenza. Analogamente, il numero a 9 cifre, 134217728 = 8<sup>9</sup>, è una nona potenza.
Complete the function so that it returns how many positive integers are of length `n` and an `n`th power. Completa la funzione in modo che restituisca quanti interi positivi siano di lunghezza `n` e `n`ma potenza.
# --hints-- # --hints--
`powerfulDigitCounts(1)` should return a number. `powerfulDigitCounts(1)` dovrebbe restituire un numero.
```js ```js
assert(typeof powerfulDigitCounts(1) === 'number'); assert(typeof powerfulDigitCounts(1) === 'number');
``` ```
`powerfulDigitCounts(1)` should return `9`. `powerfulDigitCounts(1)` dovrebbe restituire `9`.
```js ```js
assert.strictEqual(powerfulDigitCounts(1), 9); assert.strictEqual(powerfulDigitCounts(1), 9);
``` ```
`powerfulDigitCounts(2)` should return `6`. `powerfulDigitCounts(2)` dovrebbe restituire `6`.
```js ```js
assert.strictEqual(powerfulDigitCounts(2), 6); assert.strictEqual(powerfulDigitCounts(2), 6);
``` ```
`powerfulDigitCounts(3)` should return `5`. `powerfulDigitCounts(3)` dovrebbe restituire `5`.
```js ```js
assert.strictEqual(powerfulDigitCounts(3), 5); assert.strictEqual(powerfulDigitCounts(3), 5);
``` ```
`powerfulDigitCounts(4)` should return `4`. `powerfulDigitCounts(4)` dovrebbe restituire `4`.
```js ```js
assert.strictEqual(powerfulDigitCounts(4), 4); assert.strictEqual(powerfulDigitCounts(4), 4);
``` ```
`powerfulDigitCounts(5)` should return `3`. `powerfulDigitCounts(5)` dovrebbe restituire `3`.
```js ```js
assert.strictEqual(powerfulDigitCounts(5), 3); assert.strictEqual(powerfulDigitCounts(5), 3);
``` ```
`powerfulDigitCounts(6)` should return `3`. `powerfulDigitCounts(6)` dovrebbe restituire `3`.
```js ```js
assert.strictEqual(powerfulDigitCounts(6), 3); assert.strictEqual(powerfulDigitCounts(6), 3);
``` ```
`powerfulDigitCounts(7)` should return `2`. `powerfulDigitCounts(7)` dovrebbe restituire `2`.
```js ```js
assert.strictEqual(powerfulDigitCounts(7), 2); assert.strictEqual(powerfulDigitCounts(7), 2);
``` ```
`powerfulDigitCounts(8)` should return `2`. `powerfulDigitCounts(8)` dovrebbe restituire `2`.
```js ```js
assert.strictEqual(powerfulDigitCounts(8), 2); assert.strictEqual(powerfulDigitCounts(8), 2);
``` ```
`powerfulDigitCounts(10)` should return `2`. `powerfulDigitCounts(10)` dovrebbe restituire `2`.
```js ```js
assert.strictEqual(powerfulDigitCounts(10), 2); assert.strictEqual(powerfulDigitCounts(10), 2);
``` ```
`powerfulDigitCounts(21)` should return `1`. `powerfulDigitCounts(21)` dovrebbe restituire `1`.
```js ```js
assert.strictEqual(powerfulDigitCounts(21), 1); assert.strictEqual(powerfulDigitCounts(21), 1);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3731000cf542c50fe86 id: 5900f3731000cf542c50fe86
title: 'Problem 7: 10001st prime' title: 'Problema 7: 10001esimo primo'
challengeType: 5 challengeType: 5
forumTopicId: 302182 forumTopicId: 302182
dashedName: problem-7-10001st-prime dashedName: problem-7-10001st-prime
@ -8,43 +8,43 @@ dashedName: problem-7-10001st-prime
# --description-- # --description--
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. Elencando i primi sei numeri principali: 2, 3, 5, 7, 11 e 13, possiamo vedere che il sesto primo è 13.
What is the `n`th prime number? Qual è il `n`-simo numero primo?
# --hints-- # --hints--
`nthPrime(6)` should return a number. `nthPrime(6)` dovrebbe restituire un numero.
```js ```js
assert(typeof nthPrime(6) === 'number'); assert(typeof nthPrime(6) === 'number');
``` ```
`nthPrime(6)` should return 13. `nthPrime(6)` dovrebbe restituire 13.
```js ```js
assert.strictEqual(nthPrime(6), 13); assert.strictEqual(nthPrime(6), 13);
``` ```
`nthPrime(10)` should return 29. `nthPrime(10)` dovrebbe restituire 29.
```js ```js
assert.strictEqual(nthPrime(10), 29); assert.strictEqual(nthPrime(10), 29);
``` ```
`nthPrime(100)` should return 541. `nthPrime(100)` dovrebbe restituire 541.
```js ```js
assert.strictEqual(nthPrime(100), 541); assert.strictEqual(nthPrime(100), 541);
``` ```
`nthPrime(1000)` should return 7919. `nthPrime(1000)` dovrebbe restituire 7919.
```js ```js
assert.strictEqual(nthPrime(1000), 7919); assert.strictEqual(nthPrime(1000), 7919);
``` ```
`nthPrime(10001)` should return 104743. `nthPrime(10001)` dovrebbe restituire 104743.
```js ```js
assert.strictEqual(nthPrime(10001), 104743); assert.strictEqual(nthPrime(10001), 104743);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3741000cf542c50fe87 id: 5900f3741000cf542c50fe87
title: 'Problem 8: Largest product in a series' title: 'Problema 8: Prodotto più grande in una serie'
challengeType: 5 challengeType: 5
forumTopicId: 302193 forumTopicId: 302193
dashedName: problem-8-largest-product-in-a-series dashedName: problem-8-largest-product-in-a-series
@ -8,7 +8,7 @@ dashedName: problem-8-largest-product-in-a-series
# --description-- # --description--
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. Le quattro cifre adiacenti del numero a 1000 cifre che hanno il prodotto più grande sono 9 × 9 × 8 × 9 = 5832.
<div style='text-align: center;'>73167176531330624919225119674426574742355349194934</div> <div style='text-align: center;'>73167176531330624919225119674426574742355349194934</div>
<div style='text-align: center;'>96983520312774506326239578318016984801869478851843</div> <div style='text-align: center;'>96983520312774506326239578318016984801869478851843</div>
@ -31,23 +31,23 @@ The four adjacent digits in the 1000-digit number that have the greatest product
<div style='text-align: center;'>05886116467109405077541002256983155200055935729725</div> <div style='text-align: center;'>05886116467109405077541002256983155200055935729725</div>
<div style='text-align: center;'>71636269561882670428252483600823257530420752963450</div> <div style='text-align: center;'>71636269561882670428252483600823257530420752963450</div>
Find the `n` adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? Trova le `n` cifre adiacenti nel numero a 1000 cifre che hanno il prodotto più grande. Qual è il valore di questo prodotto?
# --hints-- # --hints--
`largestProductinaSeries(4)` should return a number. `largestProductinaSeries(4)` dovrebbe restituire un numero.
```js ```js
assert(typeof largestProductinaSeries(4) === 'number'); assert(typeof largestProductinaSeries(4) === 'number');
``` ```
`largestProductinaSeries(4)` should return 5832. `largestProductinaSeries(4)` dovrebbe restituire 5832.
```js ```js
assert.strictEqual(largestProductinaSeries(4), 5832); assert.strictEqual(largestProductinaSeries(4), 5832);
``` ```
`largestProductinaSeries(13)` should return 23514624000. `largestProductinaSeries(13)` dovrebbe restituire 23514624000.
```js ```js
assert.strictEqual(largestProductinaSeries(13), 23514624000); assert.strictEqual(largestProductinaSeries(13), 23514624000);

View File

@ -1,6 +1,6 @@
--- ---
id: 5900f3761000cf542c50fe88 id: 5900f3761000cf542c50fe88
title: 'Problem 9: Special Pythagorean triplet' title: 'Problema 9: Tripletta Pitagorica Speciale'
challengeType: 5 challengeType: 5
forumTopicId: 302205 forumTopicId: 302205
dashedName: problem-9-special-pythagorean-triplet dashedName: problem-9-special-pythagorean-triplet
@ -8,35 +8,35 @@ dashedName: problem-9-special-pythagorean-triplet
# --description-- # --description--
A Pythagorean triplet is a set of three natural numbers, `a` &lt; `b` &lt; `c`, for which, Una tripletta pitagorica è una serie di tre numeri naturali, `a` &lt; `b` &lt; `c` tali per cui
<div style='text-align: center;'><var>a</var><sup>2</sup> + <var>b</var><sup>2</sup> = <var>c</var><sup>2</sup></div> <div style='text-align: center;'><var>a</var><sup>2</sup> + <var>b</var><sup>2</sup> = <var>c</var><sup>2</sup></div>
For example, 3<sup>2</sup> + 4<sup>2</sup> = 9 + 16 = 25 = 5<sup>2</sup>. Ad esempio, 3<sup>2</sup> + 4<sup>2</sup> = 9 + 16 = 25 = 5<sup>2</sup>.
There exists exactly one Pythagorean triplet for which `a` + `b` + `c` = 1000. Find the product `abc` such that `a` + `b` + `c` = `n`. Esiste esattamente una tripletta pitagorica per la quale `a` + `b` + `c` = 1000. Trova il prodotto `abc` tale che `a` + `b` + `c` = `n`.
# --hints-- # --hints--
`specialPythagoreanTriplet(24)` should return a number. `specialPythagoreanTriplet(24)` dovrebbe restituire un numero.
```js ```js
assert(typeof specialPythagoreanTriplet(24) === 'number'); assert(typeof specialPythagoreanTriplet(24) === 'number');
``` ```
`specialPythagoreanTriplet(24)` should return 480. `specialPythagoreanTriplet(24)` dovrebbe restituire 480.
```js ```js
assert.strictEqual(specialPythagoreanTriplet(24), 480); assert.strictEqual(specialPythagoreanTriplet(24), 480);
``` ```
`specialPythagoreanTriplet(120)` should return 49920, 55080 or 60000 `specialPythagoreanTriplet(120)` dovrebbe restituire 49920, 55080 o 60000
```js ```js
assert([49920, 55080, 60000].includes(specialPythagoreanTriplet(120))); assert([49920, 55080, 60000].includes(specialPythagoreanTriplet(120)));
``` ```
`specialPythagoreanTriplet(1000)` should return 31875000. `specialPythagoreanTriplet(1000)` dovrebbe restituire 31875000.
```js ```js
assert.strictEqual(specialPythagoreanTriplet(1000), 31875000); assert.strictEqual(specialPythagoreanTriplet(1000), 31875000);

View File

@ -1,6 +1,6 @@
--- ---
id: 5e4ce2bbac708cc68c1df25f id: 5e4ce2bbac708cc68c1df25f
title: Letter frequency title: Frequenza delle lettere
challengeType: 5 challengeType: 5
forumTopicId: 385263 forumTopicId: 385263
dashedName: letter-frequency dashedName: letter-frequency
@ -8,33 +8,33 @@ dashedName: letter-frequency
# --description-- # --description--
Given a string, calculate the frequency of each character. Data una stringa, calcolare la frequenza di ogni carattere.
All characters should be counted. This includes lower and upper case letters, digits, whitespace, special characters, or any other distinct characters. Tutti i caratteri devono essere contati. Questo include lettere maiuscole e minuscole, cifre, spazi bianchi, caratteri speciali o qualsiasi altro carattere distinto.
# --instructions-- # --instructions--
Write a function to count the occurrences of each character in a given string. Scrivi una funzione per contare le occorrenze di ogni carattere in una determinata stringa.
The function should return a 2D array with each of the elements in the following form: `['char', freq]`. The character should be a string with a length of 1, and frequency is a number denoting the count. La funzione dovrebbe restituire un array 2D con ciascuno degli elementi nella seguente forma: `['char', freq]`. Il carattere deve essere una stringa con una lunghezza di 1, e la frequenza è un numero che indica il conteggio.
For example, given the string "ab", your function should return `[['a', 1], ['b', 1]]`. Per esempio, data la stringa "ab", la tua funzione dovrebbe restituire `[['a', 1], ['b', 1]]`.
# --hints-- # --hints--
`letterFrequency` should be a function. `letterFrequency` dovrebbe essere una funzione.
```js ```js
assert(typeof letterFrequency == 'function'); assert(typeof letterFrequency == 'function');
``` ```
`letterFrequency("Not all that Mrs. Bennet, however")` should return an array. `letterFrequency("Not all that Mrs. Bennet, however")` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(letterFrequency('Not all that Mrs. Bennet, however'))); assert(Array.isArray(letterFrequency('Not all that Mrs. Bennet, however')));
``` ```
`letterFrequency("Not all that Mrs. Bennet, however")` should return `[[" ", 5], [",", 1], [".", 1], ["B", 1], ["M", 1], ["N", 1], ["a", 2], ["e", 4], ["h", 2], ["l", 2], ["n", 2], ["o", 2], ["r", 2], ["s", 1], ["t", 4], ["v", 1], ["w", 1]]`. `letterFrequency("Not all that Mrs. Bennet, however")` dovrebbe restituire `[[" ", 5], [",", 1], [".", 1], ["B", 1], ["M", 1], ["N", 1], ["a", 2], ["e", 4], ["h", 2], ["l", 2], ["n", 2], ["o", 2], ["r", 2], ["s", 1], ["t", 4], ["v", 1], ["w", 1]]`.
```js ```js
assert.deepEqual(letterFrequency('Not all that Mrs. Bennet, however'), [ assert.deepEqual(letterFrequency('Not all that Mrs. Bennet, however'), [
@ -58,7 +58,7 @@ assert.deepEqual(letterFrequency('Not all that Mrs. Bennet, however'), [
]); ]);
``` ```
`letterFrequency("daughters, could ask on the ")` should return `[[" ", 5],[",", 1],["a", 2],["c", 1],["d", 2],["e", 2],["g", 1],["h", 2],["k", 1],["l", 1],["n", 1],["o", 2],["r", 1],["s", 2],["t", 2],["u", 2]]`. `letterFrequency("daughters, could ask on the ")` dovrebbe restituire `[[" ", 5],[",", 1],["a", 2],["c", 1],["d", 2],["e", 2],["g", 1],["h", 2],["k", 1],["l", 1],["n", 1],["o", 2],["r", 1],["s", 2],["t", 2],["u", 2]]`.
```js ```js
assert.deepEqual(letterFrequency('daughters, could ask on the '), [ assert.deepEqual(letterFrequency('daughters, could ask on the '), [
@ -81,7 +81,7 @@ assert.deepEqual(letterFrequency('daughters, could ask on the '), [
]); ]);
``` ```
`letterFrequency("husband any satisfactory description")` should return `[[" ", 3], ["a", 4], ["b", 1], ["c", 2], ["d", 2], ["e", 1], ["f", 1], ["h", 1], ["i", 3], ["n", 3], ["o", 2], ["p", 1], ["r", 2], ["s", 4], ["t", 3], ["u", 1], ["y", 2]]`. `letterFrequency("husband any satisfactory description")` dovrebbe restituire `[[" ", 3], ["a", 4], ["b", 1], ["c", 2], ["d", 2], ["e", 1], ["f", 1], ["h", 1], ["i", 3], ["n", 3], ["o", 2], ["p", 1], ["r", 2], ["s", 4], ["t", 3], ["u", 1], ["y", 2]]`.
```js ```js
assert.deepEqual(letterFrequency('husband any satisfactory description'), [ assert.deepEqual(letterFrequency('husband any satisfactory description'), [
@ -105,7 +105,7 @@ assert.deepEqual(letterFrequency('husband any satisfactory description'), [
]); ]);
``` ```
`letterFrequency("in various ways--with barefaced")` should return `[[" ", 3], ["-", 2], ["a", 4], ["b", 1], ["c", 1], ["d", 1], ["e", 2], ["f", 1], ["h", 1], ["i", 3], ["n", 1], ["o", 1], ["r", 2], ["s", 2], ["t", 1], ["u", 1], ["v", 1], ["w", 2], ["y", 1]]`. `letterFrequency("in various ways--with barefaced")` dovrebbe restituire `[[" ", 3], ["-", 2], ["a", 4], ["b", 1], ["c", 1], ["d", 1], ["e", 2], ["f", 1], ["h", 1], ["i", 3], ["n", 1], ["o", 1], ["r", 2], ["s", 2], ["t", 1], ["u", 1], ["v", 1], ["w", 2], ["y", 1]]`.
```js ```js
assert.deepEqual(letterFrequency('in various ways--with barefaced'), [ assert.deepEqual(letterFrequency('in various ways--with barefaced'), [
@ -131,7 +131,7 @@ assert.deepEqual(letterFrequency('in various ways--with barefaced'), [
]); ]);
``` ```
`letterFrequency("distant surmises; but he eluded")` should return `[[" ", 4], [";", 1], ["a", 1], ["b", 1], ["d", 3], ["e", 4], ["h", 1], ["i", 2], ["l", 1], ["m", 1], ["n", 1], ["r", 1], ["s", 4], ["t", 3], ["u", 3]]`. `letterFrequency("distant surmises; but he eluded")` dovrebbe restituire `[[" ", 4], [";", 1], ["a", 1], ["b", 1], ["d", 3], ["e", 4], ["h", 1], ["i", 2], ["l", 1], ["m", 1], ["n", 1], ["r", 1], ["s", 4], ["t", 3], ["u", 3]]`.
```js ```js
assert.deepEqual(letterFrequency('distant surmises; but he eluded'), [ assert.deepEqual(letterFrequency('distant surmises; but he eluded'), [
@ -153,7 +153,7 @@ assert.deepEqual(letterFrequency('distant surmises; but he eluded'), [
]); ]);
``` ```
`letterFrequency("last obliged to accept the second-hand,")` should return `[[" ", 5], [",", 1], ["-", 1], ["a", 3], ["b", 1], ["c", 3], ["d", 3], ["e", 4], ["g", 1], ["h", 2], ["i", 1], ["l", 2], ["n", 2], ["o", 3], ["p", 1], ["s", 2], ["t", 4]]`. `letterFrequency("last obliged to accept the second-hand,")` dovrebbe restituire `[[" ", 5], [",", 1], ["-", 1], ["a", 3], ["b", 1], ["c", 3], ["d", 3], ["e", 4], ["g", 1], ["h", 2], ["i", 1], ["l", 2], ["n", 2], ["o", 3], ["p", 1], ["s", 2], ["t", 4]]`.
```js ```js
assert.deepEqual(letterFrequency('last obliged to accept the second-hand,'), [ assert.deepEqual(letterFrequency('last obliged to accept the second-hand,'), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dd1278e6ca105cde40ea9 id: 5e6dd1278e6ca105cde40ea9
title: Longest common subsequence title: Più lunga successione comune
challengeType: 5 challengeType: 5
forumTopicId: 385271 forumTopicId: 385271
dashedName: longest-common-subsequence dashedName: longest-common-subsequence
@ -8,65 +8,65 @@ dashedName: longest-common-subsequence
# --description-- # --description--
The **longest common subsequence** (or [**LCS**](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem)) of groups A and B is the longest group of elements from A and B that are common between the two groups and in the same order in each group. For example, the sequences "1234" and "1224533324" have an LCS of "1234": La **sottosequenza comune più lunga** (o [**LCS**](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem)) dei gruppi A e B è il gruppo più lungo di elementi provenienti da A e B che sono comuni tra i due gruppi e nello stesso ordine in ogni gruppo. Per esempio, le sequenze "1234" e "1224533324" hanno un LCS di "1234":
***1234*** ***1234***
***12***245***3***332***4*** ***12***245***3***332***4***
For a string example, consider the sequences "thisisatest" and "testing123testing". An LCS would be "tsitest": Per un esempio di stringa, considera le sequenze "thisisatest" e "testing123testing". Un LCS sarebbe "tsitest":
***t***hi***si***sa***test*** ***t***hi***si***sa***test***
***t***e***s***t***i***ng123***test***ing. ***t***e***s***t***i***ng123***test***ing.
Your code only needs to deal with strings. Il tuo codice deve riguardare solo le stringhe.
For more information on this problem please see [Wikipedia](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem). Per ulteriori informazioni su questo problema consulta [Wikipedia](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem).
# --instructions-- # --instructions--
Write a case-sensitive function that returns the LCS of two strings. You don't need to show multiple LCS's. Scrivi una funzione sensibile alle maiuscole/minuscole che restituisce l'LCS di due stringhe. Non è necessario mostrare più LCS.
# --hints-- # --hints--
`lcs` should be a function. `lcs` dovrebbe essere una funzione.
```js ```js
assert(typeof lcs == 'function'); assert(typeof lcs == 'function');
``` ```
`lcs("thisisatest", "testing123testing")` should return a string. `lcs("thisisatest", "testing123testing")` dovrebbe restituire una stringa.
```js ```js
assert(typeof lcs('thisisatest', 'testing123testing') == 'string'); assert(typeof lcs('thisisatest', 'testing123testing') == 'string');
``` ```
`lcs("thisisatest", "testing123testing")` should return `"tsitest"`. `lcs("thisisatest", "testing123testing")` dovrebbe restituire `"tsitest"`.
```js ```js
assert.equal(lcs('thisisatest', 'testing123testing'), 'tsitest'); assert.equal(lcs('thisisatest', 'testing123testing'), 'tsitest');
``` ```
`lcs("ABCDGH", "AEDFHR")` should return `"ADH"`. `lcs("ABCDGH", "AEDFHR")` dovrebbe restituire `"ADH"`.
```js ```js
assert.equal(lcs('ABCDGH', 'AEDFHR'), 'ADH'); assert.equal(lcs('ABCDGH', 'AEDFHR'), 'ADH');
``` ```
`lcs("AGGTAB", "GXTXAYB")` should return `"GTAB"`. `lcs("AGGTAB", "GXTXAYB")` dovrebbe restituire `"GTAB"`.
```js ```js
assert.equal(lcs('AGGTAB', 'GXTXAYB'), 'GTAB'); assert.equal(lcs('AGGTAB', 'GXTXAYB'), 'GTAB');
``` ```
`lcs("BDACDB", "BDCB")` should return `"BDCB"`. `lcs("BDACDB", "BDCB")` dovrebbe restituire `"BDCB"`.
```js ```js
assert.equal(lcs('BDACDB', 'BDCB'), 'BDCB'); assert.equal(lcs('BDACDB', 'BDCB'), 'BDCB');
``` ```
`lcs("ABAZDC", "BACBAD")` should return `"ABAD"`. `lcs("ABAZDC", "BACBAD")` dovrebbe restituire `"ABAD"`.
```js ```js
assert.equal(lcs('ABAZDC', 'BACBAD'), 'ABAD'); assert.equal(lcs('ABAZDC', 'BACBAD'), 'ABAD');

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dd139859c290b6ab80292 id: 5e6dd139859c290b6ab80292
title: Longest increasing subsequence title: Più lunga sottosequenza crescente
challengeType: 5 challengeType: 5
forumTopicId: 385272 forumTopicId: 385272
dashedName: longest-increasing-subsequence dashedName: longest-increasing-subsequence
@ -8,57 +8,57 @@ dashedName: longest-increasing-subsequence
# --description-- # --description--
The longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as possible. An example: Il problema di della più lunga sottosequenza crescente è quello di trovare una sottosequenza di una data sequenza in cui gli elementi successivi sono in ordine, dal più basso al più alto, e in cui la sottosequenza è la più lunga possibile. Un esempio:
For the following array: Per il seguente array:
$\\{3, 10, 2, 1, 20\\}$ $\\{3, 10, 2, 1, 20\\}$
Longest increasing sequence is: La sequenza crescente più lunga è:
$\\{3, 10, 20\\}$ $\\{3, 10, 20\\}$
For more information on this problem please see [Wikipedia](https://en.wikipedia.org/wiki/Longest increasing subsequence). Per ulteriori informazioni su questo problema consulta [Wikipedia](https://en.wikipedia.org/wiki/Longest increasing subsequence).
# --instructions-- # --instructions--
Write a function that takes an array of numbers as a parameter and returns the longest increasing subsequence. Scrivere una funzione che prende un array di numeri come parametro e restituisce la più lunga sottosequenza crescente.
It is guaranteed that every array will have a longest increasing subsequence. È garantito che ogni array avrà una sottosequenza crescente più lunga.
# --hints-- # --hints--
`findSequence` should be a function. `findSequence` dovrebbe essere una funzione.
```js ```js
assert(typeof findSequence == 'function'); assert(typeof findSequence == 'function');
``` ```
`findSequence([3, 10, 2, 1, 20])` should return a array. `findSequence([3, 10, 2, 1, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(findSequence([3, 10, 2, 1, 20]))); assert(Array.isArray(findSequence([3, 10, 2, 1, 20])));
``` ```
`findSequence([3, 10, 2, 1, 20])` should return `[3, 10, 20]`. `findSequence([3, 10, 2, 1, 20])` dovrebbe restituire `[3, 10, 20]`.
```js ```js
assert.deepEqual(findSequence([3, 10, 2, 1, 20]), [3, 10, 20]); assert.deepEqual(findSequence([3, 10, 2, 1, 20]), [3, 10, 20]);
``` ```
`findSequence([2, 7, 3, 5, 8])` should return `[2, 3, 5, 8]`. `findSequence([2, 7, 3, 5, 8])` dovrebbe restituire `[2, 3, 5, 8]`.
```js ```js
assert.deepEqual(findSequence([2, 7, 3, 5, 8]), [2, 3, 5, 8]); assert.deepEqual(findSequence([2, 7, 3, 5, 8]), [2, 3, 5, 8]);
``` ```
`findSequence([2, 6, 4, 5, 1])` should return `[2, 4, 5]`. `findSequence([2, 6, 4, 5, 1])` dovrebbe restituire `[2, 4, 5]`.
```js ```js
assert.deepEqual(findSequence([2, 6, 4, 5, 1]), [2, 4, 5]); assert.deepEqual(findSequence([2, 6, 4, 5, 1]), [2, 4, 5]);
``` ```
`findSequence([10, 22, 9, 33, 21, 50, 60, 80])` should return `[10, 22, 33, 50, 60, 80]`. `findSequence([10, 22, 9, 33, 21, 50, 60, 80])` dovrebbe restituire `[10, 22, 33, 50, 60, 80]`.
```js ```js
assert.deepEqual(findSequence([10, 22, 9, 33, 21, 50, 60, 80]), [ assert.deepEqual(findSequence([10, 22, 9, 33, 21, 50, 60, 80]), [
@ -71,7 +71,7 @@ assert.deepEqual(findSequence([10, 22, 9, 33, 21, 50, 60, 80]), [
]); ]);
``` ```
`findSequence([0, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])` should return `[0, 2, 6, 9, 11, 15`. `findSequence([0, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])` dovrebbe restituire `[0, 2, 6, 9, 11, 15`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dd14192286d95fc43046e id: 5e6dd14192286d95fc43046e
title: Longest string challenge title: Sfida della stringa più lunga
challengeType: 5 challengeType: 5
forumTopicId: 385275 forumTopicId: 385275
dashedName: longest-string-challenge dashedName: longest-string-challenge
@ -8,27 +8,27 @@ dashedName: longest-string-challenge
# --description-- # --description--
In this challenge, you have to find the strings that are the longest among the given strings. In questa sfida, devi trovare le stringhe che sono le più lunghe tra le stringhe date.
# --instructions-- # --instructions--
Write a function that takes an array of strings and returns the strings that have a length equal to the longest length. Scrivi una funzione che richiede un array di stringhe e restituisce le stringhe che hanno una lunghezza uguale alla lunghezza più lunga.
# --hints-- # --hints--
`longestString` should be a function. `longestString` dovrebbe essere una funzione.
```js ```js
assert(typeof longestString == 'function'); assert(typeof longestString == 'function');
``` ```
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` should return a array. `longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']))); assert(Array.isArray(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg'])));
``` ```
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` should return `["ccc", "ggg"]'`. `longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` dovrebbe restituire `["ccc", "ggg"]`.
```js ```js
assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [ assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [
@ -37,7 +37,7 @@ assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [
]); ]);
``` ```
`longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"])` should return `["afedg", "sdccc", "efdee", "geegg"]`. `longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"])` dovrebbe restituire `["afedg", "sdccc", "efdee", "geegg"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -46,7 +46,7 @@ assert.deepEqual(
); );
``` ```
`longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"])` should return `["bhghgb", "fssdrr"]`. `longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"])` dovrebbe restituire `["bhghgb", "fssdrr"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -55,7 +55,7 @@ assert.deepEqual(
); );
``` ```
`longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"])` should return `["ahgfhg", "bdsfsb", "ggdsfg"]`. `longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"])` dovrebbe restituire `["ahgfhg", "bdsfsb", "ggdsfg"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -64,7 +64,7 @@ assert.deepEqual(
); );
``` ```
`longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"])` should return `["gzzzgg"]`. `longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"])` dovrebbe restituire `["gzzzgg"]`.
```js ```js
assert.deepEqual(longestString(['a', 'bbdsf', 'ccc', 'edfe', 'gzzzgg']), [ assert.deepEqual(longestString(['a', 'bbdsf', 'ccc', 'edfe', 'gzzzgg']), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dd14797f5ce267c2f19d0 id: 5e6dd14797f5ce267c2f19d0
title: Look-and-say sequence title: Successione Look-and-say
challengeType: 5 challengeType: 5
forumTopicId: 385277 forumTopicId: 385277
dashedName: look-and-say-sequence dashedName: look-and-say-sequence
@ -8,64 +8,64 @@ dashedName: look-and-say-sequence
# --description-- # --description--
The [Look and say sequence](https://en.wikipedia.org/wiki/Look and say sequence) is a recursively defined sequence of numbers. La successione [Look and say](https://en.wikipedia.org/wiki/Look and say sequence) è una sequenza di numeri definita ricorsivamente.
Sequence Definition Definizione della successione
<ul><li>Take a decimal number</li> <ul><li>Prendi un numero decimale</li>
<li><span>Look</span> at the number, visually grouping consecutive runs of the same digit.</li> <li><span>Guarda</span> (look) il numero, raggruppando visivamente le successioni consecutive della stessa cifra.</li>
<li><span>Say</span> the number, from left to right, group by group; as how many of that digit there are - followed by the digit grouped.</li></ul><span> This becomes the next number of the sequence.</span> <li><span>Leggi</span> (say) il numero, da sinistra a destra, gruppo per gruppo; quante ripetizioni di quella cifra ci sono - seguita dalla cifra raggruppata.</li></ul><span> Questo diventa il numero successivo della successione.</span>
An example: Un esempio:
<ul><li>Starting with the number 1, you have <span>one</span> 1 which produces 11</li> <ul><li>A partire dal numero 1, hai <span>un</span> 1 che produce 11</li>
<li>Starting with 11, you have <span>two</span> 1's. I.E.: 21</li> <li>A partire da 11, hai <span>due</span> 1. Cioè: 21</li>
<li>Starting with 21, you have <span>one</span> 2, then <span>one</span> 1. I.E.: (12)(11) which becomes 1211</li> <li>A partire da 21, hai <span>un</span> 2, poi <span>un</span> 1. Cioè: (12)(11) che diventa 1211</li>
<li>Starting with 1211, you have <span>one</span> 1, <span>one</span> 2, then <span>two</span> 1's. I.E.: (11)(12)(21) which becomes 111221</li></ul> <li>A partire da 1211, hai <span>un</span> 1, <span>un</span> 2, poi <span>due</span> 1. Cioè: (11)(12)(21) che diventa 111221</li></ul>
# --instructions-- # --instructions--
Write a function that accepts a string as a parameter, processes it, and returns the resultant string. Scrivi una funzione che accetta una stringa come parametro, la elabora e restituisce la stringa risultante.
# --hints-- # --hints--
`lookAndSay` should be a function. `lookAndSay` dovrebbe essere una funzione.
```js ```js
assert(typeof lookAndSay == 'function'); assert(typeof lookAndSay == 'function');
``` ```
`lookAndSay("1")` should return a string. `lookAndSay("1")` dovrebbe restituire una stringa.
```js ```js
assert(typeof lookAndSay('1') == 'string'); assert(typeof lookAndSay('1') == 'string');
``` ```
`lookAndSay("1")` should return `"11"`. `lookAndSay("1")` dovrebbe restituire `"11"`.
```js ```js
assert.equal(lookAndSay('1'), '11'); assert.equal(lookAndSay('1'), '11');
``` ```
`lookAndSay("11")` should return `"21"`. `lookAndSay("11")` dovrebbe restituire `"21"`.
```js ```js
assert.equal(lookAndSay('11'), '21'); assert.equal(lookAndSay('11'), '21');
``` ```
`lookAndSay("21")` should return `"1211"`. `lookAndSay("21")` dovrebbe restituire `"1211"`.
```js ```js
assert.equal(lookAndSay('21'), '1211'); assert.equal(lookAndSay('21'), '1211');
``` ```
`lookAndSay("1211")` should return `"111221"`. `lookAndSay("1211")` dovrebbe restituire `"111221"`.
```js ```js
assert.equal(lookAndSay('1211'), '111221'); assert.equal(lookAndSay('1211'), '111221');
``` ```
`lookAndSay("3542")` should return `"13151412"`. `lookAndSay("3542")` dovrebbe restituire `"13151412"`.
```js ```js
assert.equal(lookAndSay('3542'), '13151412'); assert.equal(lookAndSay('3542'), '13151412');

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dd15004c88cf00d2a78b3 id: 5e6dd15004c88cf00d2a78b3
title: Loop over multiple arrays simultaneously title: Iterare su più matrici simultaneamente
challengeType: 5 challengeType: 5
forumTopicId: 385279 forumTopicId: 385279
dashedName: loop-over-multiple-arrays-simultaneously dashedName: loop-over-multiple-arrays-simultaneously
@ -8,15 +8,15 @@ dashedName: loop-over-multiple-arrays-simultaneously
# --description-- # --description--
Loop over multiple arrays and create a new array whose $i^{th}$ element is the concatenation of $i^{th}$ element of each of the given. Itera su più array e crea un nuovo array il cui elemento $i^{mo}$ è la concatenazione dell'$i^{mo}$ elemento di ciascuno dei dati forniti.
For this example, if you are given this array of arrays: Per questo esempio, se le viene dato questo array di array:
```js ```js
[ ["a", "b", "c"], ["A", "B", "C"], [1, 2, 3] ] [ ["a", "b", "c"], ["A", "B", "C"], [1, 2, 3] ]
``` ```
the output should be: l'output dovrebbe essere:
```js ```js
["aA1","bB2","cC3"] ["aA1","bB2","cC3"]
@ -24,17 +24,17 @@ the output should be:
# --instructions-- # --instructions--
Write a function that takes an array of arrays as a parameter and returns an array of strings satisfying the given description. Scrivi una funzione che prende un array di array come parametro e restituisce un array di stringhe che soddisfano la descrizione data.
# --hints-- # --hints--
`loopSimult` should be a function. `loopSimult` dovrebbe essere una funzione.
```js ```js
assert(typeof loopSimult == 'function'); assert(typeof loopSimult == 'function');
``` ```
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` should return a array. `loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -48,7 +48,7 @@ assert(
); );
``` ```
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` should return `["aA1", "bB2", "cC3"]`. `loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` dovrebbe restituire `["aA1", "bB2", "cC3"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -61,7 +61,7 @@ assert.deepEqual(
); );
``` ```
`loopSimult([["c", "b", "c"], ["4", "5", "C"], [7, 7, 3]])` should return `["c47", "b57", "cC3"]`. `loopSimult([["c", "b", "c"], ["4", "5", "C"], [7, 7, 3]])` dovrebbe restituire `["c47", "b57", "cC3"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -74,7 +74,7 @@ assert.deepEqual(
); );
``` ```
`loopSimult([["a", "b", "c", "d"], ["A", "B", "C", "d"], [1, 2, 3, 4]])` should return `["aA1", "bB2", "cC3", "dd4"]`. `loopSimult([["a", "b", "c", "d"], ["A", "B", "C", "d"], [1, 2, 3, 4]])` dovrebbe restituire `["aA1", "bB2", "cC3", "dd4"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -87,7 +87,7 @@ assert.deepEqual(
); );
``` ```
`loopSimult([["a", "b"], ["A", "B"], [1, 2]])` should return `["aA1", "bB2"]`. `loopSimult([["a", "b"], ["A", "B"], [1, 2]])` dovrebbe restituire `["aA1", "bB2"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -100,7 +100,7 @@ assert.deepEqual(
); );
``` ```
`loopSimult([["b", "c"], ["B", "C"], [2, 3]])` should return `["bB2", "cC3"]`. `loopSimult([["b", "c"], ["B", "C"], [2, 3]])` dovrebbe restituire `["bB2", "cC3"]`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6decd8ec8d7db960950d1c id: 5e6decd8ec8d7db960950d1c
title: LU decomposition title: Scomposizione LU
challengeType: 5 challengeType: 5
forumTopicId: 385280 forumTopicId: 385280
dashedName: lu-decomposition dashedName: lu-decomposition
@ -8,21 +8,21 @@ dashedName: lu-decomposition
# --description-- # --description--
Every square matrix $A$ can be decomposed into a product of a lower triangular matrix $L$ and a upper triangular matrix $U$, as described in [LU decomposition](https://en.wikipedia.org/wiki/LU decomposition). Ogni matrice quadrata $A$ può essere scomposta in un prodotto di una matrice triangolare inferiore $L$ e una matrice triangolare superiore $U$, come descritto in [decomposizione LU](https://it.wikipedia.org/wiki/Decomposizione_LU).
$A = LU$ $A = LU$
It is a modified form of Gaussian elimination. È una forma modificata di eliminazione gaussiana.
While the [Cholesky decomposition](http://rosettacode.org/wiki/Cholesky decomposition) only works for symmetric, positive definite matrices, the more general LU decomposition works for any square matrix. Mentre la decomposizione [Cholesky](http://rosettacode.org/wiki/Cholesky decomposition) funziona solo per matrici definite simmetriche e positive, la decomposizione LU più generale funziona per qualsiasi matrice quadrata.
There are several algorithms for calculating $L$ and $U$. Ci sono diversi algoritmi per calcolare $L$ e $U$.
To derive *Crout's algorithm* for a 3x3 example, we have to solve the following system: Per ricavare l'algoritmo *di Crout* per un esempio 3x3, dobbiamo risolvere il seguente sistema:
\\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix}= \\begin{pmatrix} l\_{11} & 0 & 0 \\\\ l\_{21} & l\_{22} & 0 \\\\ l\_{31} & l\_{32} & l\_{33}\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = LU\\end{align} \\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix}= \\begin{pmatrix} l\_{11} & 0 & 0 \\\\ l\_{21} & l\_{22} & 0 \\\\ l\_{31} & l\_{32} & l\_{33}\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = LU\\end{align}
We now would have to solve 9 equations with 12 unknowns. To make the system uniquely solvable, usually the diagonal elements of $L$ are set to 1 Ora dovremmo risolvere 9 equazioni con 12 incognite. Per rendere il sistema unicamente risolvibile, di solito gli elementi diagonali di $L$ sono impostati a 1
$l\_{11}=1$ $l\_{11}=1$
@ -30,11 +30,11 @@ $l\_{22}=1$
$l\_{33}=1$ $l\_{33}=1$
so we get a solvable system of 9 unknowns and 9 equations. così otteniamo un sistema risolvibile con 9 equazioni e 9 incognite.
\\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix} = \\begin{pmatrix} 1 & 0 & 0 \\\\ l\_{21} & 1 & 0 \\\\ l\_{31} & l\_{32} & 1\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ u\_{11}l\_{21} & u\_{12}l\_{21}+u\_{22} & u\_{13}l\_{21}+u\_{23} \\\\ u\_{11}l\_{31} & u\_{12}l\_{31}+u\_{22}l\_{32} & u\_{13}l\_{31} + u\_{23}l\_{32}+u\_{33} \\end{pmatrix} = LU\\end{align} \\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix} = \\begin{pmatrix} 1 & 0 & 0 \\\\ l\_{21} & 1 & 0 \\\\ l\_{31} & l\_{32} & 1\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ u\_{11}l\_{21} & u\_{12}l\_{21}+u\_{22} & u\_{13}l\_{21}+u\_{23} \\\\ u\_{11}l\_{31} & u\_{12}l\_{31}+u\_{22}l\_{32} & u\_{13}l\_{31} + u\_{23}l\_{32}+u\_{33} \\end{pmatrix} = LU\\end{align}
Solving for the other $l$ and $u$, we get the following equations: Risolvendo gli altri $l$ e $u$, otteniamo le seguenti equazioni:
$u\_{11}=a\_{11}$ $u\_{11}=a\_{11}$
@ -48,7 +48,7 @@ $u\_{23}=a\_{23} - u\_{13}l\_{21}$
$u\_{33}=a\_{33} - (u\_{13}l\_{31} + u\_{23}l\_{32})$ $u\_{33}=a\_{33} - (u\_{13}l\_{31} + u\_{23}l\_{32})$
and for $l$: e per $l$:
$l\_{21}=\\frac{1}{u\_{11}} a\_{21}$ $l\_{21}=\\frac{1}{u\_{11}} a\_{21}$
@ -56,41 +56,41 @@ $l\_{31}=\\frac{1}{u\_{11}} a\_{31}$
$l\_{32}=\\frac{1}{u\_{22}} (a\_{32} - u\_{12}l\_{31})$ $l\_{32}=\\frac{1}{u\_{22}} (a\_{32} - u\_{12}l\_{31})$
We see that there is a calculation pattern, which can be expressed as the following formulas, first for $U$ Vediamo che esiste un modello di calcolo, che può essere espresso come le seguenti formule, prima per $U$
$u\_{ij} = a\_{ij} - \\sum\_{k=1}^{i-1} u\_{kj}l\_{ik}$ $u\_{ij} = a\_{ij} - \\sum\_{k=1}^{i-1} u\_{kj}l\_{ik}$
and then for $L$ e poi per $L$
$l\_{ij} = \\frac{1}{u\_{jj}} (a\_{ij} - \\sum\_{k=1}^{j-1} u\_{kj}l\_{ik})$ $l\_{ij} = \\frac{1}{u\_{jj}} (a\_{ij} - \\sum\_{k=1}^{j-1} u\_{kj}l\_{ik})$
We see in the second formula that to get the $l\_{ij}$ below the diagonal, we have to divide by the diagonal element (pivot) $u\_{jj}$, so we get problems when $u\_{jj}$ is either 0 or very small, which leads to numerical instability. Vediamo nella seconda formula che per ottenere $l\_{ij}$ sotto la diagonale, dobbiamo dividere per l'elemento diagonale (pivot) $u\_{jj}$, così abbiamo problemi quando $u\_{jj}$ è 0 o molto piccolo, il che porta all'instabilità numerica.
The solution to this problem is *pivoting* $A$, which means rearranging the rows of $A$, prior to the $LU$ decomposition, in a way that the largest element of each column gets onto the diagonal of $A$. Rearranging the rows means to multiply $A$ by a permutation matrix $P$: La soluzione a questo problema è il *pivoting* $A$, il che significa riordinare le righe di $A$, prima della scomposizione di $LU$, in un modo che lelemento più grande di ogni colonna entri nella diagonale di $A$. Riorganizzare le righe significa moltiplicare $A$ per una matrice di permutazione $P$:
$PA \\Rightarrow A'$ $PA \\Rightarrow A'$
Example: Esempio:
\\begin{align} \\begin{pmatrix} 0 & 1 \\\\ 1 & 0 \\end{pmatrix} \\begin{pmatrix} 1 & 4 \\\\ 2 & 3 \\end{pmatrix} \\Rightarrow \\begin{pmatrix} 2 & 3 \\\\ 1 & 4 \\end{pmatrix} \\end{align} \\begin{align} \\begin{pmatrix} 0 & 1 \\\\ 1 & 0 \\end{pmatrix} \\begin{pmatrix} 1 & 4 \\\\ 2 & 3 \\end{pmatrix} \\Rightarrow \\begin{pmatrix} 2 & 3 \\\\ 1 & 4 \\end{pmatrix} \\end{align}
The decomposition algorithm is then applied on the rearranged matrix so that L'algoritmo di scomposizione viene quindi applicato sulla matrice riarrangiata in modo che
$PA = LU$ $PA = LU$
# --instructions-- # --instructions--
The task is to implement a routine which will take a square nxn matrix $A$ and return a lower triangular matrix $L$, a upper triangular matrix $U$ and a permutation matrix $P$, so that the above equation is fullfilled. The returned value should be in the form `[L, U, P]`. Il compito è quello di implementare una routine che richiederà una matrice quadrata nxn $A$ e restituirà una matrice triangolare inferiore $L$, una matrice triangolare superiore $U$ e una matrice di permutazione $P$, in modo che l'equazione di cui sopra sia soddisfatta. Il valore restituito dovrebbe essere nella forma `[L, U, P]`.
# --hints-- # --hints--
`luDecomposition` should be a function. `luDecomposition` dovrebbe essere una funzione.
```js ```js
assert(typeof luDecomposition == 'function'); assert(typeof luDecomposition == 'function');
``` ```
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` should return a array. `luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -104,7 +104,7 @@ assert(
); );
``` ```
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` should return `[[[1, 0, 0], [0.5, 1, 0], [0.5, -1, 1]], [[2, 4, 7], [0, 1, 1.5], [0, 0, -2]], [[0, 1, 0], [1, 0, 0], [0, 0, 1]]]`. `luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` dovrebbe restituire `[[[1, 0, 0], [0.5, 1, 0], [0.5, -1, 1]], [[2, 4, 7], [0, 1, 1.5], [0, 0, -2]], [[0, 1, 0], [1, 0, 0], [0, 0, 1]]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -133,7 +133,7 @@ assert.deepEqual(
); );
``` ```
`luDecomposition([[11, 9, 24, 2], [1, 5, 2, 6], [3, 17, 18, 1], [2, 5, 7, 1]])` should return `[[[1, 0, 0, 0], [0.2727272727272727, 1, 0, 0], [0.09090909090909091, 0.2875, 1, 0], [0.18181818181818182, 0.23124999999999996, 0.0035971223021580693, 1]], [[11, 9, 24, 2], [0, 14.545454545454547, 11.454545454545455, 0.4545454545454546], [0, 0, -3.4749999999999996, 5.6875], [0, 0, 0, 0.510791366906476]], [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]]`. `luDecomposition([[11, 9, 24, 2], [1, 5, 2, 6], [3, 17, 18, 1], [2, 5, 7, 1]])` dovrebbe restituire `[[1, 0, 0, 0], [0. 7272727272727, 1, 0, 0], [0.0909090909091, 0.2875, 1, 0], [0.1818181818181818182, 0.231249999999996, 0. 035971223021580693, 1]], [[11, 9, 24, 2], [0, 14.5454545454545447, 11.45454545454545455, 0.45454545454546], [0, 0, -3. 74999999996, 5.6875], [0, 0, 0, 0.510791366906476]], [[1, 0, 0, 0], [0, 1, 0], [0, 1, 0], [0, 0, 0, 1]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -166,7 +166,7 @@ assert.deepEqual(
); );
``` ```
`luDecomposition([[1, 1, 1], [4, 3, -1], [3, 5, 3]])` should return `[[[1, 0, 0], [0.75, 1, 0], [0.25, 0.09090909090909091, 1]], [[4, 3, -1], [0, 2.75, 3.75], [0, 0, 0.9090909090909091]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`. `luDecomposition([[1, 1, 1], [4, 3, -1], [3, 5, 3]])` dovrebbe restituire `[[[1, 0, 0], [0.75, 1, 0], [0.25, 0.09090909090909091, 1]], [[4, 3, -1], [0, 2.75, 3.75], [0, 0, 0.9090909090909091]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -195,7 +195,7 @@ assert.deepEqual(
); );
``` ```
`luDecomposition([[1, -2, 3], [2, -5, 12], [0, 2, -10]])` should return `[[[1, 0, 0], [0, 1, 0], [0.5, 0.25, 1]], [[2, -5, 12], [0, 2, -10], [0, 0, -0.5]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`. `luDecomposition([[1, -2, 3], [2, -5, 12], [0, 2, -10]])` dovrebbe restituire `[[[1, 0, 0], [0, 1, 0], [0.5, 0.25, 1]], [[2, -5, 12], [0, 2, -10], [0, 0, -0.5]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -1,6 +1,6 @@
--- ---
id: 5e6dee7749a0b85a3f1fc7d5 id: 5e6dee7749a0b85a3f1fc7d5
title: Lucas-Lehmer test title: Test di Lucas-Lehmer
challengeType: 5 challengeType: 5
forumTopicId: 385281 forumTopicId: 385281
dashedName: lucas-lehmer-test dashedName: lucas-lehmer-test
@ -8,57 +8,57 @@ dashedName: lucas-lehmer-test
# --description-- # --description--
Lucas-Lehmer Test: for $p$ an odd prime, the Mersenne number $2^p-1$ is prime if and only if $2^p-1$ divides $S(p-1)$ where $S(n+1)=(S(n))^2-2$, and $S(1)=4$. Test di Lucas-Lehmer: dato $p$ numero primo dispari, il numero di Mersenne $2^p-1$ è primo se e solo se $2^p-1$ divide $S(p-1)$ dove $S(n+1)=(S(n))^2-2$, e $S(1)=4$.
# --instructions-- # --instructions--
Write a function that returns whether the given Mersenne number is prime or not. Scrivi una funzione che restituisce se il numero Mersenne dato è primo o no.
# --hints-- # --hints--
`lucasLehmer` should be a function. `lucasLehmer` dovrebbe essere una funzione.
```js ```js
assert(typeof lucasLehmer == 'function'); assert(typeof lucasLehmer == 'function');
``` ```
`lucasLehmer(11)` should return a boolean. `lucasLehmer(11)` dovrebbe restituire un booleano.
```js ```js
assert(typeof lucasLehmer(11) == 'boolean'); assert(typeof lucasLehmer(11) == 'boolean');
``` ```
`lucasLehmer(11)` should return `false`. `lucasLehmer(11)` dovrebbe restituire `false`.
```js ```js
assert.equal(lucasLehmer(11), false); assert.equal(lucasLehmer(11), false);
``` ```
`lucasLehmer(15)` should return `false`. `lucasLehmer(15)` dovrebbe restituire `false`.
```js ```js
assert.equal(lucasLehmer(15), false); assert.equal(lucasLehmer(15), false);
``` ```
`lucasLehmer(13)` should return `true`. `lucasLehmer(13)` dovrebbe restituire `true`.
```js ```js
assert.equal(lucasLehmer(13), true); assert.equal(lucasLehmer(13), true);
``` ```
`lucasLehmer(17)` should return `true`. `lucasLehmer(17)` dovrebbe restituire `true`.
```js ```js
assert.equal(lucasLehmer(17), true); assert.equal(lucasLehmer(17), true);
``` ```
`lucasLehmer(19)` should return `true`. `lucasLehmer(19)` dovrebbe restituire `true`.
```js ```js
assert.equal(lucasLehmer(19), true); assert.equal(lucasLehmer(19), true);
``` ```
`lucasLehmer(21)` should return `false`. `lucasLehmer(21)` dovrebbe restituire `false`.
```js ```js
assert.equal(lucasLehmer(21), false); assert.equal(lucasLehmer(21), false);

View File

@ -1,6 +1,6 @@
--- ---
id: 5ea281203167d2b0bdefca00 id: 5ea281203167d2b0bdefca00
title: Ludic numbers title: Numeri ludici
challengeType: 5 challengeType: 5
forumTopicId: 385282 forumTopicId: 385282
dashedName: ludic-numbers dashedName: ludic-numbers
@ -8,91 +8,91 @@ dashedName: ludic-numbers
# --description-- # --description--
[Ludic numbers](https://oeis.org/wiki/Ludic_numbers) are related to prime numbers as they are generated by a sieve quite like the [Sieve of Eratosthenes](https://rosettacode.org/wiki/Sieve_of_Eratosthenes) is used to generate prime numbers. [I numeri ludici](https://oeis.org/wiki/Ludic_numbers) sono legati ai numeri primi perché sono generati da un setaccio come il [Crivello di Eratosthenes](https://rosettacode.org/wiki/Sieve_of_Eratosthenes) è usato per generare numeri primi.
The first ludic number is 1. Il primo numero ludico è 1.
To generate succeeding ludic numbers create an array of increasing integers starting from 2. Per generare numeri ludici funzionanti creare un array di numeri interi crescenti a partire da 2.
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'>2</span> 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...</code> <code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'>2</span> 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...</code>
(Loop) (Ciclo)
<ul> <ul>
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>2</span>.</li> <li>Prendi il primo membro dell'array risultante come prossimo numero ludico <span style='color:blue;font-weight:bold'>2</span>.</li>
<li>Remove every <strong>2<sup>nd</sup></strong> indexed item from the array (including the first).</li> <li>Rimuovi ogni <strong>secondo</strong> elemento indicizzato dall'array (incluso il primo).</li>
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold;'><s>2</s></span> 3 <s>4</s> 5 <s>6</s> 7 <s>8</s> 9 <s>10</s> 11 <s>12</s> 13 <s>14</s> 15 <s>16</s> 17 <s>18</s> 19 <s>20</s> 21 <s>22</s> 23 <s>24</s> 25 <s>26</s> ...</code> <code style='margin-left: 2em;'><span style='color:blue;font-weight:bold;'><s>2</s></span> 3 <s>4</s> 5 <s>6</s> 7 <s>8</s> 9 <s>10</s> 11 <s>12</s> 13 <s>14</s> 15 <s>16</s> 17 <s>18</s> 19 <s>20</s> 21 <s>22</s> 23 <s>24</s> 25 <s>26</s> ...</code>
</ul> </ul>
<ul> <ul>
<li>(Unrolling a few loops...)</li> <li>(Srotolando alcuni cicli...)</li>
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>3</span>.</li> <li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>3</span>.</li>
<li>Remove every <strong>3<sup>rd</sup></strong> indexed item from the array (including the first).</li> <li>Rimuovi ogni <strong>terzo</strong> elemento indicizzato dall'array (incluso il primo).</li>
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>3</s></span> 5 7 <s>9</s> 11 13 <s>15</s> 17 19 <s>21</s> 23 25 <s>27</s> 29 31 <s>33</s> 35 37 <s>39</s> 41 43 <s>45</s> 47 49 <s>51</s> ...</code> <code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>3</s></span> 5 7 <s>9</s> 11 13 <s>15</s> 17 19 <s>21</s> 23 25 <s>27</s> 29 31 <s>33</s> 35 37 <s>39</s> 41 43 <s>45</s> 47 49 <s>51</s> ...</code>
</ul> </ul>
<ul> <ul>
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>5</span>.</li> <li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>5</span>.</li>
<li>Remove every <strong>5<sup>th</sup></strong> indexed item from the array (including the first).</li> <li>Rimuovi ogni <strong>quinto</strong> elemento indicizzato dall'array (incluso il primo).</li>
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>5</s></span> 7 11 13 17 <s>19</s> 23 25 29 31 <s>35</s> 37 41 43 47 <s>49</s> 53 55 59 61 <s>65</s> 67 71 73 77 ...</code> <code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>5</s></span> 7 11 13 17 <s>19</s> 23 25 29 31 <s>35</s> 37 41 43 47 <s>49</s> 53 55 59 61 <s>65</s> 67 71 73 77 ...</code>
</ul> </ul>
<ul> <ul>
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>7</span>.</li> <li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>7</span>.</li>
<li>Remove every <strong>7<sup>th</sup></strong> indexed item from the array (including the first).</li> <li>Rimuovi ogni <strong>settimo</strong> elemento indicizzato dall'array (incluso il primo).</li>
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>7</s></span> 11 13 17 23 25 29 <s>31</s> 37 41 43 47 53 55 <s>59</s> 61 67 71 73 77 83 <s>85</s> 89 91 97 ...</code> <code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>7</s></span> 11 13 17 23 25 29 <s>31</s> 37 41 43 47 53 55 <s>59</s> 61 67 71 73 77 83 <s>85</s> 89 91 97 ...</code>
</ul> </ul>
<ul> <ul>
<li><big><b> ... </b></big></li> <li><big><b> ... </b></big></li>
<li>Take the first member of the current array as the next ludic number <span style='color:blue;font-weight:bold'>L</span>.</li> <li>Prendi il primo membro dell'array corrente come prossimo numero ludico <span style='color:blue;font-weight:bold'>L</span>.</li>
<li>Remove every <strong>L<sup>th</sup></strong> indexed item from the array (including the first).</li> <li>Rimuovi ogni elemento indicizzato <strong>L<sup>mo</sup></strong> dall'array (incluso il primo).</li>
<li><big><b> ... </b></big></li> <li><big><b> ... </b></big></li>
</ul> </ul>
# --instructions-- # --instructions--
Write a function that returns all the ludic numbers less than or equal to the given number. Scrivi una funzione che restituisce tutti i numeri ludici minori o uguali al numero indicato.
# --hints-- # --hints--
`ludic` should be a function. `ludic` dovrebbe essere una funzione.
```js ```js
assert(typeof ludic === 'function', '<code>ludic</code> should be a function.'); assert(typeof ludic === 'function', '<code>ludic</code> should be a function.');
``` ```
`ludic(2)` should return a array. `ludic(2)` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(ludic(2))); assert(Array.isArray(ludic(2)));
``` ```
`ludic(2)` should return `[1, 2]`. `ludic(2)` dovrebbe restituire `[1, 2]`.
```js ```js
assert.deepEqual(ludic(2), [1, 2]); assert.deepEqual(ludic(2), [1, 2]);
``` ```
`ludic(3)` should return `[1, 2, 3]`. `ludic(3)` dovrebbe restituire `[1, 2, 3]`.
```js ```js
assert.deepEqual(ludic(3), [1, 2, 3]); assert.deepEqual(ludic(3), [1, 2, 3]);
``` ```
`ludic(5)` should return `[1, 2, 3, 5]`. `ludic(5)` dovrebbe restituire `[1, 2, 3, 5]`.
```js ```js
assert.deepEqual(ludic(5), [1, 2, 3, 5]); assert.deepEqual(ludic(5), [1, 2, 3, 5]);
``` ```
`ludic(20)` should return `[1, 2, 3, 5, 7, 11, 13, 17]`. `ludic(20)` dovrebbe restituire `[1, 2, 3, 5, 7, 11, 13, 17]`.
```js ```js
assert.deepEqual(ludic(20), [1, 2, 3, 5, 7, 11, 13, 17]); assert.deepEqual(ludic(20), [1, 2, 3, 5, 7, 11, 13, 17]);
``` ```
`ludic(26)` should return `[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]`. `ludic(26)` dovrebbe restituire `[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]`.
```js ```js
assert.deepEqual(ludic(26), [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]); assert.deepEqual(ludic(26), [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]);

View File

@ -1,6 +1,6 @@
--- ---
id: 5ea28156e79528a9ab248f27 id: 5ea28156e79528a9ab248f27
title: Luhn test of credit card numbers title: Test di Luhn dei numeri delle carte di credito
challengeType: 5 challengeType: 5
forumTopicId: 385284 forumTopicId: 385284
dashedName: luhn-test-of-credit-card-numbers dashedName: luhn-test-of-credit-card-numbers
@ -8,22 +8,22 @@ dashedName: luhn-test-of-credit-card-numbers
# --description-- # --description--
The [Luhn test](https://en.wikipedia.org/wiki/Luhn algorithm) is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Il test di [Luhn](https://en.wikipedia.org/wiki/Luhn algorithm) è utilizzato da alcune aziende di carte di credito per distinguere i numeri di carta di credito validi da quella che potrebbe essere una selezione casuale di cifre.
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Le società che utilizzano numeri di carta di credito che possono essere convalidati dal test di Luhn hanno numeri che superano il seguente test:
<ol> <ol>
<li> Reverse the order of the digits in the number.</li> <li> Inverte l'ordine delle cifre nel numero.</li>
<li> Take the first, third, ... and every other odd digit in the reversed digits and sum them to form the partial sum s1</li> <li> Prende la prima, la terza, ... e ogni altra cifra dispari nelle cifre invertite e le somma per formare la somma parziale s1</li>
<li> Taking the second, fourth ... and every other even digit in the reversed digits:</li> <li> Prende la seconda, la quarta... e ogni altra cifra pari nelle cifre invertite:</li>
<ol> <ol>
<li>Multiply each digit by two and sum the digits if the answer is greater than nine to form partial sums for the even digits.</li> <li>Moltiplica ogni cifra per due e somma le cifre se la risposta è maggiore di nove per formare somme parziali per le cifre pari.</li>
<li>Sum the partial sums of the even digits to form s2.</li> <li>Somma le somme parziali delle cifre pari per formare s2.</li>
</ol> </ol>
<li>If s1 + s2 ends in zero then the original number is in the form of a valid credit card number as verified by the Luhn test.</li> <li>Se s1 + s2 termina in zero allora il numero originale ha la forma di un numero di carta di credito valido, stando alla verifica del test di Luhn.</li>
</ol> </ol>
For example, if the trial number is 49927398716: Ad esempio, se il numero da testare è 49927398716:
```bash ```bash
Reverse the digits: Reverse the digits:
@ -44,53 +44,53 @@ s1 + s2 = 70 which ends in zero which means that 49927398716 passes the Luhn tes
# --instructions-- # --instructions--
Write a function that will validate a number with the Luhn test. Return true if it's a valid number. Otherwise, return false. Scrivi una funzione che convaliderà un numero con il test Luhn. Restituisce vero se è un numero valido. Altrimenti, restituisci falso.
# --hints-- # --hints--
`luhnTest` should be a function. `luhnTest` dovrebbe essere una funzione.
```js ```js
assert(typeof luhnTest === 'function'); assert(typeof luhnTest === 'function');
``` ```
`luhnTest("4111111111111111")` should return a boolean. `luhnTest("4111111111111111")` dovrebbe restituire un booleano.
```js ```js
assert(typeof luhnTest('4111111111111111') === 'boolean'); assert(typeof luhnTest('4111111111111111') === 'boolean');
``` ```
`luhnTest("4111111111111111")` should return `true`. `luhnTest("4111111111111111")` dovrebbe restituire `true`.
```js ```js
assert.equal(luhnTest('4111111111111111'), true); assert.equal(luhnTest('4111111111111111'), true);
``` ```
`luhnTest("4111111111111112")` should return `false`. `luhnTest("4111111111111112")` dovrebbe restituire `false`.
```js ```js
assert.equal(luhnTest('4111111111111112'), false); assert.equal(luhnTest('4111111111111112'), false);
``` ```
`luhnTest("49927398716")` should return `true`. `luhnTest("49927398716")` dovrebbe restituire `true`.
```js ```js
assert.equal(luhnTest('49927398716'), true); assert.equal(luhnTest('49927398716'), true);
``` ```
`luhnTest("49927398717")` should return `false`. `luhnTest("49927398717")` dovrebbe restituire `false`.
```js ```js
assert.equal(luhnTest('49927398717'), false); assert.equal(luhnTest('49927398717'), false);
``` ```
`luhnTest("1234567812345678")` should return `false`. `luhnTest("1234567812345678")` dovrebbe restituire `false`.
```js ```js
assert.equal(luhnTest('1234567812345678'), false); assert.equal(luhnTest('1234567812345678'), false);
``` ```
`luhnTest("1234567812345670")` should return `true`. `luhnTest("1234567812345670")` dovrebbe restituire `true`.
```js ```js
assert.equal(luhnTest('1234567812345670'), true); assert.equal(luhnTest('1234567812345670'), true);

View File

@ -1,6 +1,6 @@
--- ---
id: 5ea2815a8640bcc6cb7dab3c id: 5ea2815a8640bcc6cb7dab3c
title: Lychrel numbers title: Numeri di Lychrel
challengeType: 5 challengeType: 5
forumTopicId: 385287 forumTopicId: 385287
dashedName: lychrel-numbers dashedName: lychrel-numbers
@ -9,21 +9,21 @@ dashedName: lychrel-numbers
# --description-- # --description--
<ol> <ol>
<li>Take an integer <code>n₀</code>, greater than zero.</li> <li>Prendi un numero intero <code>n₀</code> maggiore di zero.</li>
<li>Form the next number <code>n</code> of the series by reversing <code>n₀</code> and adding it to <code>n₀</code></li> <li>Forma il prossimo numero <code>n</code> della serie invertendo <code>n₀</code> e aggiungendolo a <code>n₀</code></li>
<li>Stop when <code>n</code> becomes palindromic - i.e. the digits of <code>n</code> in reverse order == <code>n</code>.</li> <li>Termina quando <code>n</code> diventa palindromo - cioè le cifre di <code>n</code> in ordine inverso == <code>n</code>.</li>
</ol> </ol>
The above recurrence relation when applied to most starting numbers `n` = 1, 2, ... terminates in a palindrome quite quickly. La relazione di ricorrenza sopra riportata quando applicata alla maggior parte dei numeri iniziali `n` = 1, 2, ... termina in un palindromo abbastanza rapidamente.
For example if `n₀` = 12 we get: Per esempio se `n₀` = 12 otteniamo:
```bash ```bash
12 12
12 + 21 = 33, a palindrome! 12 + 21 = 33, a palindrome!
``` ```
And if `n₀` = 55 we get: E se `n₀` = 55 otteniamo:
```bash ```bash
55 55
@ -31,17 +31,17 @@ And if `n₀` = 55 we get:
110 + 011 = 121, a palindrome! 110 + 011 = 121, a palindrome!
``` ```
Notice that the check for a palindrome happens *after* an addition. Nota che il controllo per un palindromo viene fatto *dopo* una somma.
Some starting numbers seem to go on forever; the recurrence relation for 196 has been calculated for millions of repetitions forming numbers with millions of digits, without forming a palindrome. These numbers that do not end in a palindrome are called **Lychrel numbers**. Alcuni numeri iniziali sembrano andare avanti per sempre; la relazione di ricorrenza per 196 è stata calcolata per milioni di ripetizioni formando numeri con milioni di cifre, senza formare un palindromo. Questi numeri che non terminano in un palindromo sono chiamati **numeri di Lychrel**.
For the purposes of this task a Lychrel number is any starting number that does not form a palindrome within 500 (or more) iterations. Ai fini di questo compito un numero di Lychrel è qualsiasi numero iniziale che non forma un palindromo entro 500 (o più) iterazioni.
**Seed and related Lychrel numbers:** **Seme e numeri di Lychrel correlati:**
Any integer produced in the sequence of a Lychrel number is also a Lychrel number. Qualsiasi numero intero prodotto nella sequenza di un numero di Lychrel è anche un numero di Lychrel.
In general, any sequence from one Lychrel number *might* converge to join the sequence from a prior Lychrel number candidate; for example the sequences for the numbers 196 and then 689 begin: In generale, qualsiasi sequenza da un numero di Lychrel *potrebbe* convergere alla sequenza formata da un precedente numero di Lychrel; per esempio le sequenze per i numeri 196 e poi 689 iniziano:
```bash ```bash
196 196
@ -58,59 +58,59 @@ In general, any sequence from one Lychrel number *might* converge to join the se
... ...
``` ```
So we see that the sequence starting with 689 converges to, and continues with the same numbers as that for 196. Quindi vediamo che la sequenza a partire da 689 converge e continua con gli stessi numeri di quella del 196.
Because of this we can further split the Lychrel numbers into true **Seed** Lychrel number candidates, and **Related** numbers that produce no palindromes but have integers in their sequence seen as part of the sequence generated from a lower Lychrel number. A causa di questo possiamo ulteriormente dividere i numeri di Lychrel in veri **Seed** di numeri di Lychrel, e numeri **Correlati** che non producono palindromi ma hanno interi nella loro sequenza visti come parte della sequenza generata da un numero di Lychrel inferiore.
# --instructions-- # --instructions--
Write a function that takes a number as a parameter. Return true if the number is a Lynchrel number. Otherwise, return false. Remember that the iteration limit is 500. Scrivi una funzione che prende un numero come parametro. Restituisce vero se il numero è un numero di Lychrel. Altrimenti, restituisci falso. Ricorda che il limite di iterazioni è 500.
# --hints-- # --hints--
`isLychrel` should be a function. `isLychrel` dovrebbe essere una funzione.
```js ```js
assert(typeof isLychrel === 'function'); assert(typeof isLychrel === 'function');
``` ```
`isLychrel(12)` should return a boolean. `isLychrel(12)` dovrebbe restituire un booleano.
```js ```js
assert(typeof isLychrel(12) === 'boolean'); assert(typeof isLychrel(12) === 'boolean');
``` ```
`isLychrel(12)` should return `false`. `isLychrel(12)` dovrebbe restituire `false`.
```js ```js
assert.equal(isLychrel(12), false); assert.equal(isLychrel(12), false);
``` ```
`isLychrel(55)` should return `false`. `isLychrel(55)` dovrebbe restituire `false`.
```js ```js
assert.equal(isLychrel(55), false); assert.equal(isLychrel(55), false);
``` ```
`isLychrel(196)` should return `true`. `isLychrel(196)` dovrebbe restituire `true`.
```js ```js
assert.equal(isLychrel(196), true); assert.equal(isLychrel(196), true);
``` ```
`isLychrel(879)` should return `true`. `isLychrel(879)` dovrebbe restituire `true`.
```js ```js
assert.equal(isLychrel(879), true); assert.equal(isLychrel(879), true);
``` ```
`isLychrel(44987)` should return `false`. `isLychrel(44987)` dovrebbe restituire `false`.
```js ```js
assert.equal(isLychrel(44987), false); assert.equal(isLychrel(44987), false);
``` ```
`isLychrel(7059)` should return `true`. `isLychrel(7059)` dovrebbe restituire `true`.
```js ```js
assert.equal(isLychrel(7059), true); assert.equal(isLychrel(7059), true);

View File

@ -1,6 +1,6 @@
--- ---
id: 5ea2815e364d9a2222ea55f8 id: 5ea2815e364d9a2222ea55f8
title: LZW compression title: Compressione LZW
challengeType: 5 challengeType: 5
forumTopicId: 385288 forumTopicId: 385288
dashedName: lzw-compression dashedName: lzw-compression
@ -8,29 +8,29 @@ dashedName: lzw-compression
# --description-- # --description--
The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression. L'algoritmo Lempel-Ziv-Welch (LZW) fornisce compressione di dati senza perdite.
You can read a complete description of it in the [Wikipedia article](https://en.wikipedia.org/wiki/Lempel-Ziv-Welch) on the subject. Puoi leggerne una descrizione completa nell'articolo [Wikipedia](https://en.wikipedia.org/wiki/Lempel-Ziv-Welch) sull'argomento.
# --instructions-- # --instructions--
Write a function that takes two parameters. The first parameter is a boolean where `true` indicates compress and `false` indicates decompress. The second parameter is either a string or an array to be processed. If it is a string to be compressed, return an array of numbers. If it's an array of numbers to be decompressed, return a string. Scrivi una funzione che prende due parametri. Il primo parametro è un booleano dove `true` indica compressione e `false` indica decompressione. Il secondo parametro è una stringa o un array da elaborare. Se si tratta di una stringa da comprimere, restituisce un array di numeri. Se si tratta di un array di numeri da decomprimere restituisce una stringa.
# --hints-- # --hints--
`LZW` should be a function. `LZW` dovrebbe essere una funzione.
```js ```js
assert(typeof LZW === 'function'); assert(typeof LZW === 'function');
``` ```
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` should return a array. `LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'))); assert(Array.isArray(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT')));
``` ```
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` should return a string. `LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` dovrebbe restituire una stringa.
```js ```js
assert( assert(
@ -55,7 +55,7 @@ assert(
); );
``` ```
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` should return `[84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263]`. `LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` dovrebbe restituire `[84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263]`.
```js ```js
assert.deepEqual(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'), [ assert.deepEqual(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'), [
@ -78,7 +78,7 @@ assert.deepEqual(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'), [
]); ]);
``` ```
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` should return `"TOBEORNOTTOBEORTOBEORNOT"`. `LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` dovrebbe restituire `"TOBEORNOTTOBEORTOBEORNOT"`.
```js ```js
assert.equal( assert.equal(
@ -104,7 +104,7 @@ assert.equal(
); );
``` ```
`LZW(true, "0123456789")` should return `[48, 49, 50, 51, 52, 53, 54, 55, 56, 57]`. `LZW(true, "0123456789")` dovrebbe restituire `[48, 49, 50, 51, 52, 53, 54, 55, 56, 57]`.
```js ```js
assert.deepEqual(LZW(true, '0123456789'), [ assert.deepEqual(LZW(true, '0123456789'), [
@ -121,7 +121,7 @@ assert.deepEqual(LZW(true, '0123456789'), [
]); ]);
``` ```
`LZW(false, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57])` should return `"0123456789"`. `LZW(false, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57])` dovrebbe restituire `"0123456789"`.
```js ```js
assert.equal( assert.equal(
@ -130,13 +130,13 @@ assert.equal(
); );
``` ```
`LZW(true, "BABAABAAA")` should return `[66, 65, 256, 257, 65, 260]`. `LZW(true, "BABAABAAA")` dovrebbe restituire `[66, 65, 256, 257, 65, 260]`.
```js ```js
assert.deepEqual(LZW(true, 'BABAABAAA'), [66, 65, 256, 257, 65, 260]); assert.deepEqual(LZW(true, 'BABAABAAA'), [66, 65, 256, 257, 65, 260]);
``` ```
`LZW(false, [66, 65, 256, 257, 65, 260])` should return `"BABAABAAA"`. `LZW(false, [66, 65, 256, 257, 65, 260])` dovrebbe restituire `"BABAABAAA"`.
```js ```js
assert.equal(LZW(false, [66, 65, 256, 257, 65, 260]), 'BABAABAAA'); assert.equal(LZW(false, [66, 65, 256, 257, 65, 260]), 'BABAABAAA');

View File

@ -8,47 +8,47 @@ dashedName: s-expressions
# --description-- # --description--
[S-Expressions](https://en.wikipedia.org/wiki/S-Expression "wp: S-Expression") are one convenient way to parse and store data. Le [S-Expressions](https://en.wikipedia.org/wiki/S-Expression "wp: S-Expression") sono un modo comodo per analizzare e memorizzare i dati.
# --instructions-- # --instructions--
Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats. Scrivi un semplice lettore/analizzatore di S-Expressions che gestisce stringhe, interi e float.
The function should read a single but nested S-Expression from a string and return it as a (nested) array. La funzione dovrebbe leggere una singola ma annidata S-Espressione da una stringa e restituire un array annidato.
Newlines and other whitespace may be ignored unless contained within a quoted string. I caratteri di nuova linea e gli altri spazi bianchi possono essere ignorati a meno che non siano contenuti in una stringa tra virgolette.
"`()`" inside quoted strings are not interpreted, but treated as part of the string. "`()`" all'interno delle stringhe quotate non vengono interpretate, ma trattate come parte della stringa.
Handling escaped quotes inside a string is optional; thus "`(foo"bar)`" may be treated as a string "`foo"bar`", or as an error. La gestione delle virgolette con escape all'interno di una stringa è facoltativa; quindi "`(foo"bar)`" può essere trattato come una stringa "`foo"bar`", o come un errore.
For this, the reader need not recognize `\` for escaping, but should, in addition, recognize numbers if the language has appropriate data types. Per questo, il lettore non deve riconoscere `\` per l'escape, ma dovrebbe inoltre riconoscere i numeri se il linguaggio ha tipi di dati appropriati.
Note that with the exception of `()"` (`\` if escaping is supported) and whitespace, there are no special characters. Anything else is allowed without quotes. Si noti che ad eccezione di `()"` (`\` se è supportato l'escaping) e spazi bianchi, non ci sono caratteri speciali. Qualsiasi altra cosa è consentita senza virgolette.
The reader should be able to read the following input Il lettore dovrebbe essere in grado di leggere il seguente input
<pre>((data "quoted data" 123 4.5) <pre>((data "quoted data" 123 4.5)
(data (!@# (4.5) "(more" "data)"))) (data (!@# (4.5) "(more" "data)")))
</pre> </pre>
and turn it into a native data structure. (See the [Pike](https://rosettacode.org/wiki/S-Expressions#Pike "\#Pike"), [Python](https://rosettacode.org/wiki/S-Expressions#Python "\#Python") and [Ruby](https://rosettacode.org/wiki/S-Expressions#Ruby "\#Ruby") implementations for examples of native data structures.) e trasformarlo in una struttura di dati nativa. (Vedi le implementazioni in [Pike](https://rosettacode.org/wiki/S-Expressions#Pike "\#Pike"), [Python](https://rosettacode.org/wiki/S-Expressions#Python "\#Python") e [Ruby](https://rosettacode.org/wiki/S-Expressions#Ruby "\#Ruby") per esempi di strutture di dati native.)
# --hints-- # --hints--
`parseSexpr` should be a function. `parseSexpr` dovrebbe essere una funzione.
```js ```js
assert(typeof parseSexpr === 'function'); assert(typeof parseSexpr === 'function');
``` ```
`parseSexpr('(data1 data2 data3)')` should return `['data1', 'data2', 'data3']` `parseSexpr('(data1 data2 data3)')` dovrebbe restituire `['data1', 'data2', 'data3']`
```js ```js
assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution); assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
``` ```
`parseSexpr('((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))')` should return `[['data', '"quoted data"', 123, 4.5], ['data', ['!@#', [4.5], '"(more"', '"data)"']]]`. `parseSexpr('((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))')` dovrebbe restituire `[['data', '"quoted data"', 123, 4.5], ['data', ['!@#', [4.5], '"(more"', '"data)"']]]`.
```js ```js
assert.deepEqual(parseSexpr(basicSExpr), basicSolution); assert.deepEqual(parseSexpr(basicSExpr), basicSolution);

View File

@ -1,6 +1,6 @@
--- ---
id: 59da22823d04c95919d46269 id: 59da22823d04c95919d46269
title: 'Sailors, coconuts and a monkey problem' title: 'Problema dei marinai, scimmie e noci di cocco'
challengeType: 5 challengeType: 5
forumTopicId: 302304 forumTopicId: 302304
dashedName: sailors-coconuts-and-a-monkey-problem dashedName: sailors-coconuts-and-a-monkey-problem
@ -8,38 +8,38 @@ dashedName: sailors-coconuts-and-a-monkey-problem
# --description-- # --description--
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and then hides "his" one of the five equally sized piles of coconuts and pushes the other four piles together to form a single visible pile of coconuts again and goes to bed. To cut a long story short, each of the sailors in turn gets up once during the night and performs the same actions of dividing the coconut pile into five, finding that one coconut is left over and giving that single remainder coconut to the monkey. In the morning (after the surreptitious and separate action of each of the five sailors during the night), the remaining coconuts are divided into five equal piles for each of the sailors, whereupon it is found that the pile of coconuts divides equally amongst the sailors with no remainder. (Nothing for the monkey in the morning.) Cinque marinai sono naufragati su un'isola e raccolgono un grande mucchio di noci di cocco durante il giorno. Quella notte il primo marinaio si sveglia e decide di prendere la sua prima parte presto, così cerca di dividere il mucchio di noci di cocco ugualmente in cinque pile, ma scopre che c'è un cocco rimasto, così lo lancia ad una scimmia e poi nasconde la "sua" pila di cocco, di pari dimensione, e spinge le altre quattro insieme per formare nuovamente un unico mucchio visibile di noci di cocco e va a letto. Per farla breve, ciascuno dei marinai a sua volta si alza una volta durante la notte ed esegue le stesse azioni di divisione del mucchio di cocco in cinque, scopre che un cocco è rimasto e da quel singolo cocco alla scimmia. Al mattino (dopo l'azione surrettizia e separata di ciascuno dei cinque marinai durante la notte), le noci di cocco restanti sono suddivise in cinque pile uguali per ciascuno dei marinai, dopodiché si scopre che il mucchio di noci di cocco si divide ugualmente tra i marinai senza resto. (Niente per la scimmia al mattino.)
# --instructions-- # --instructions--
Create a function that returns the minimum possible size of the initial pile of coconuts collected during the day for `N` sailors. **Note:** Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc. can occur in time fitting the story line, so as not to affect the mathematics. **C.f:** Crea una funzione che restituisca la dimensione minima possibile del mucchio iniziale di noci di cocco raccolto durante il giorno per `N` marinai. **Nota:** Naturalmente la storia è raccontata in un mondo in cui la raccolta di qualsiasi quantità di noci di cocco in un giorno e divisioni multiple del mucchio, ecc. possono verificarsi nel tempo della storia, in modo da non influenzare la matematica. **Confronta:**
<ul> <ul>
<li><a href="https://www.youtube.com/watch?v=U9qU20VmvaU" target="_blank"> Monkeys and Coconuts - Numberphile</a> (Video) Analytical solution.</li> <li><a href="https://www.youtube.com/watch?v=U9qU20VmvaU" target="_blank"> Monkeys and Coconuts - Numberphile</a> (Video) Analytical solution.</li>
<li><a href="https://oeis.org/A002021" target="_blank">A002021 Pile of coconuts problem</a> The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).</li> <li><a href="https://oeis.org/A002021" target="_blank">A002021 Problema del mucchio di noci di cocco</a> L'Enciclopedia online delle sequenze di numeri interi. (Anche se alcuni dei suoi riferimenti possono utilizzare la forma alternativa del racconto).</li>
</ul> </ul>
# --hints-- # --hints--
`splitCoconuts` should be a function. `splitCoconuts` dovrebbe essere una funzione.
```js ```js
assert(typeof splitCoconuts === 'function'); assert(typeof splitCoconuts === 'function');
``` ```
`splitCoconuts(5)` should return 3121. `splitCoconuts(5)` dovrebbe restituire 3121.
```js ```js
assert(splitCoconuts(5) === 3121); assert(splitCoconuts(5) === 3121);
``` ```
`splitCoconuts(6)` should return 233275. `splitCoconuts(6)` dovrebbe restituire 233275.
```js ```js
assert(splitCoconuts(6) === 233275); assert(splitCoconuts(6) === 233275);
``` ```
`splitCoconuts(7)` should return 823537. `splitCoconuts(7)` dovrebbe restituire 823537.
```js ```js
assert(splitCoconuts(7) === 823537); assert(splitCoconuts(7) === 823537);

View File

@ -1,6 +1,6 @@
--- ---
id: 5eb3e497b8d6d7f63c5517ea id: 5eb3e497b8d6d7f63c5517ea
title: Search a list of records title: Cerca in una lista di record
challengeType: 5 challengeType: 5
forumTopicId: 385315 forumTopicId: 385315
dashedName: search-a-list-of-records dashedName: search-a-list-of-records
@ -8,51 +8,51 @@ dashedName: search-a-list-of-records
# --description-- # --description--
A record consists of attributes that describe an entity. Each attribute has a name and a value. For example, a person can have an attribute `age` with a value of 25. An important operation on a list of records is to find a record with a particular attribute value. Un record è costituito da attributi che descrivono un'entità. Ogni attributo ha un nome e un valore. Ad esempio, una persona può avere un attributo `age` con un valore di 25. Un'operazione importante su un elenco di record è quella di trovare un record con un particolare valore di attributo.
# --instructions-- # --instructions--
Write a function that takes a string as a parameter. The function should return the index of the item in `list` for which the value of the `name` attribute matches the given string. Scrivi una funzione che prende una stringa come parametro. La funzione dovrebbe restituire l'indice dell'elemento nella `list` per cui il valore dell'attributo `name` combacia con la stringa data.
# --hints-- # --hints--
`searchCity` should be a function. `searchCity` dovrebbe essere una funzione.
```js ```js
assert(typeof searchCity === 'function'); assert(typeof searchCity === 'function');
``` ```
`searchCity("Dar Es Salaam")` should return a number. `searchCity("Dar Es Salaam")` dovrebbe restituire un numero.
```js ```js
assert(typeof searchCity('Dar Es Salaam') === 'number'); assert(typeof searchCity('Dar Es Salaam') === 'number');
``` ```
`searchCity("Dar Es Salaam")` should return `6`. `searchCity("Dar Es Salaam")` dovrebbe restituire `6`.
```js ```js
assert.equal(searchCity('Dar Es Salaam'), 6); assert.equal(searchCity('Dar Es Salaam'), 6);
``` ```
`searchCity("Casablanca")` should return `9`. `searchCity("Casablanca")` dovrebbe restituire `9`.
```js ```js
assert.equal(searchCity('Casablanca'), 9); assert.equal(searchCity('Casablanca'), 9);
``` ```
`searchCity("Cairo")` should return `1`. `searchCity("Cairo")` dovrebbe restituire `1`.
```js ```js
assert.equal(searchCity('Cairo'), 1); assert.equal(searchCity('Cairo'), 1);
``` ```
`searchCity("Mogadishu")` should return `4`. `searchCity("Mogadishu")` dovrebbe restituire `4`.
```js ```js
assert.equal(searchCity('Mogadishu'), 4); assert.equal(searchCity('Mogadishu'), 4);
``` ```
`searchCity("Lagos")` should return `0`. `searchCity("Lagos")` dovrebbe restituire `0`.
```js ```js
assert.equal(searchCity('Lagos'), 0); assert.equal(searchCity('Lagos'), 0);

View File

@ -8,7 +8,7 @@ dashedName: sedols
# --description-- # --description--
For each number list of 6-digit [SEDOL](https://en.wikipedia.org/wiki/SEDOL "wp: SEDOL")s, calculate and append the checksum digit. That is, given the input string on the left, your function should return the corresponding string on the right: Per ogni elenco di numeri di 6 cifre [SEDOL](https://en.wikipedia.org/wiki/SEDOL "wp: SEDOL"), calcolare e aggiungere la cifra di checksum. Cioè, data la stringa di input a sinistra, la funzione dovrebbe restituire la stringa corrispondente a destra:
<pre> <pre>
710889 => 7108899 710889 => 7108899
@ -24,35 +24,35 @@ B0YBKT => B0YBKT7
B00030 => B000300 B00030 => B000300
</pre> </pre>
Check that each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string. Your function should return `null` on an invalid input. Controllare che ogni input sia formato correttamente, soprattutto per quanto riguarda i caratteri validi consentiti in una stringa SEDOL. La tua funzione dovrebbe restituire `null` per un input non valido.
# --hints-- # --hints--
`sedol` should be a function. `sedol` dovrebbe essere una funzione.
```js ```js
assert(typeof sedol === 'function'); assert(typeof sedol === 'function');
``` ```
`sedol('a')` should return null. `sedol('a')` dovrebbe restituire null.
```js ```js
assert(sedol('a') === null); assert(sedol('a') === null);
``` ```
`sedol('710889')` should return '7108899'. `sedol('710889')` dovrebbe restituire '7108899'.
```js ```js
assert(sedol('710889') === '7108899'); assert(sedol('710889') === '7108899');
``` ```
`sedol('BOATER')` should return null. `sedol('BOATER')` dovrebbe restituire null.
```js ```js
assert(sedol('BOATER') === null); assert(sedol('BOATER') === null);
``` ```
`sedol('228276')` should return '2282765'. `sedol('228276')` dovrebbe restituire '2282765'.
```js ```js
assert(sedol('228276') === '2282765'); assert(sedol('228276') === '2282765');

View File

@ -1,6 +1,6 @@
--- ---
id: 5eaf48389ee512d4d103684b id: 5eaf48389ee512d4d103684b
title: Self Describing Numbers title: Numeri autodescrittivi
challengeType: 5 challengeType: 5
forumTopicId: 385289 forumTopicId: 385289
dashedName: self-describing-numbers dashedName: self-describing-numbers
@ -8,52 +8,52 @@ dashedName: self-describing-numbers
# --description-- # --description--
There are several so-called "self describing" or ["self-descriptive"](https://en.wikipedia.org/wiki/Self-descriptive_number) integers. Ci sono diversi cosiddetti interi "auto-descriventi" o ["auto-descrittivi"](https://en.wikipedia.org/wiki/Self-descriptive_number) interi.
An integer is said to be "self-describing" if it has the property that, when digit positions are labeled 0 to N-1, the digit in each position is equal to the number of times that digit appears in the number. Si dice che un intero è "auto-descritto" se ha la proprietà che, quando le posizioni di cifra sono etichettate da 0 a N-1, la cifra in ogni posizione è uguale al numero di volte che la cifra appare nel numero.
For example, **2020** is a four-digit self describing number: Ad esempio, **2020** è un numero auto-descrittivo a quattro cifre:
<ul> <ul>
<li> position 0 has value 2 and there are two 0s in the number; </li> <li> la posizione 0 ha il valore 2 e nel numero ci sono due zeri; </li>
<li> position 1 has value 0 and there are no 1s in the number; </li> <li> la posizione 1 ha valore 0 e non ci sono uno nel numero; </li>
<li> position 2 has value 2 and there are two 2s; </li> <li> la posizione 2 ha valore 2 e ci sono due due; </li>
<li> position 3 has value 0 and there are zero 3s; </li> <li> la posizione 3 ha valore 0 e ci sono zero tre; </li>
</ul> </ul>
Self-describing numbers &lt; 100,000,000 are: 1210, 2020, 21200, 3211000, 42101000. Numeri auto-descriventi &lt; 100.000.000 sono: 1210, 2020, 21200, 3211000, 42101000.
# --instructions-- # --instructions--
Write a function that takes a positive integer as a parameter. If it is self-describing return true. Otherwise, return false. Scrivi una funzione che richiede un intero positivo come parametro. Se è auto-descrittivo restituire vero. Altrimenti, restituisci falso.
# --hints-- # --hints--
`isSelfDescribing` should be a function. `isSelfDescribing` dovrebbe essere una funzione.
```js ```js
assert(typeof isSelfDescribing == 'function'); assert(typeof isSelfDescribing == 'function');
``` ```
`isSelfDescribing()` should return a boolean. `isSelfDescribing()` dovrebbe restituire un booleano.
```js ```js
assert(typeof isSelfDescribing(2020) == 'boolean'); assert(typeof isSelfDescribing(2020) == 'boolean');
``` ```
`isSelfDescribing(2020)` should return `true`. `isSelfDescribing(2020)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSelfDescribing(2020), true); assert.equal(isSelfDescribing(2020), true);
``` ```
`isSelfDescribing(3021)` should return `false`. `isSelfDescribing(3021)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSelfDescribing(3021), false); assert.equal(isSelfDescribing(3021), false);
``` ```
`isSelfDescribing(3211000)` should return `true`. `isSelfDescribing(3211000)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSelfDescribing(3211000), true); assert.equal(isSelfDescribing(3211000), true);

View File

@ -1,6 +1,6 @@
--- ---
id: 5eb3e4a21f462f409d656c73 id: 5eb3e4a21f462f409d656c73
title: Self-referential sequence title: Sequenza autoreferenziale
challengeType: 5 challengeType: 5
forumTopicId: 385317 forumTopicId: 385317
dashedName: self-referential-sequence dashedName: self-referential-sequence
@ -8,41 +8,41 @@ dashedName: self-referential-sequence
# --description-- # --description--
There are several ways to generate a self-referential sequence. One very common one (the [Look-and-say sequence](https://rosettacode.org/wiki/Look-and-say sequence)) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: Ci sono diversi modi per generare una sequenza autoreferenziale. Uno molto comune (la sequenza [Look-and-say](https://rosettacode.org/wiki/Look-and-say sequence)) è iniziare con un numero intero positivo, quindi generare il termine successivo concatenando gruppi enumerati di cifre simili adiacenti:
<pre>0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ...</pre> <pre>0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ...</pre>
The terms generated grow in length geometrically and never converge. I termini generati crescono geometricamente in lunghezza e non convergono mai.
Another way to generate a self-referential sequence is to summarize the previous term. Un altro modo per generare una sequenza auto-referenziale è quello di riassumere il termine precedente.
Count how many of each alike digit there is, then concatenate the sum and digit for each of the sorted enumerated digits. Note that the first five terms are the same as for the previous sequence. Conta quante di ogni cifra simile ci sono, quindi concatena la somma e la cifra per ciascuna delle cifre enumerate ordinate. Nota che i primi cinque termini sono gli stessi della sequenza precedente.
<pre>0, 10, 1110, 3110, 132110, 13123110, 23124110 ...</pre> <pre>0, 10, 1110, 3110, 132110, 13123110, 23124110 ...</pre>
Sort the digits largest to smallest. Do not include counts of digits that do not appear in the previous term. Ordina le cifre da più grandi a più piccole. Non includere i conteggi di cifre che non appaiono nel termine precedente.
Depending on the seed value, series generated this way always either converge to a stable value or to a short cyclical pattern. (For our purposes, converge means that an element matches a previously seen element.) The sequence shown, with a seed value of 0, converges to a stable value of 1433223110 after 11 iterations. The seed value that converges most quickly is 22. It goes stable after the first element. (The next element is 22, which has been seen before.) A seconda del valore del seme, le serie generate in questo modo convergono sempre a un valore stabile o a un breve modello periodico. (Per i nostri scopi, convergere significa che un elemento corrisponde a un elemento visto precedentemente.) La sequenza mostrata, con un valore di seme di 0, converge ad un valore stabile di 1433223110 dopo 11 iterazioni. Il valore del seme che converge più rapidamente è 22. Diventa stabile dopo il primo elemento. (L'elemento successivo è 22, che è stato visto prima.)
# --instructions-- # --instructions--
Write a function that takes the seed value as parameter, generates a self referential sequence until it converges, and returns it as an array. Scrivi una funzione che prende il valore del seme come parametro, genera una sequenza autoreferenziale fino a quando non converge, e la restituisce sotto forma di array.
# --hints-- # --hints--
`selfReferential` should be a function. `selfReferential` dovrebbe essere una funzione.
```js ```js
assert(typeof selfReferential === 'function'); assert(typeof selfReferential === 'function');
``` ```
`selfReferential(40)` should return a array. `selfReferential(40)` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(selfReferential(40))); assert(Array.isArray(selfReferential(40)));
``` ```
`selfReferential(40)` should return `["40", "1410", "142110", "14123110", "1413124110", "2413125110", "151413224110", "152413225110", "251413324110", "152423224110", "152413423110"]`. `selfReferential(40)` dovrebbe restituire `["40", "1410", "142110", "14123110", "1413124110", "2413125110", "151413224110", "152413225110", "251413324110", "152423224110", "152413423110"]`.
```js ```js
assert.deepEqual(selfReferential(40), [ assert.deepEqual(selfReferential(40), [
@ -60,7 +60,7 @@ assert.deepEqual(selfReferential(40), [
]); ]);
``` ```
`selfReferential(132110)` should return `["132110", "13123110", "23124110", "1413223110", "1423224110", "2413323110", "1433223110"]`. `selfReferential(132110)` dovrebbe restituire `["132110", "13123110", "23124110", "1413223110", "1423224110", "2413323110", "1433223110"]`.
```js ```js
assert.deepEqual(selfReferential(132110), [ assert.deepEqual(selfReferential(132110), [
@ -74,7 +74,7 @@ assert.deepEqual(selfReferential(132110), [
]); ]);
``` ```
`selfReferential(132211)` should return `["132211", "132231", "232221", "134211", "14131231", "14231241", "24132231", "14233221"]`. `selfReferential(132211)` dovrebbe restituire `["132211", "132231", "232221", "134211", "14131231", "14231241", "24132231", "14233221"]`.
```js ```js
assert.deepEqual(selfReferential(132211), [ assert.deepEqual(selfReferential(132211), [
@ -89,7 +89,7 @@ assert.deepEqual(selfReferential(132211), [
]); ]);
``` ```
`selfReferential(1413223110)` should return `["1413223110", "1423224110", "2413323110", "1433223110"]`. `selfReferential(1413223110)` dovrebbe restituire `["1413223110", "1423224110", "2413323110", "1433223110"]`.
```js ```js
assert.deepEqual(selfReferential(1413223110), [ assert.deepEqual(selfReferential(1413223110), [
@ -100,7 +100,7 @@ assert.deepEqual(selfReferential(1413223110), [
]); ]);
``` ```
`selfReferential(251413126110)` should return `["251413126110", "16151413225110", "16251413226110", "26151413325110", "16251423225110", "16251413424110", "16153413225110"]`. `selfReferential(251413126110)` dovrebbe restituire `["251413126110", "16151413225110", "16251413226110", "26151413325110", "16251423225110", "16251413424110", "16153413225110"]`.
```js ```js
assert.deepEqual(selfReferential(251413126110), [ assert.deepEqual(selfReferential(251413126110), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5eb3e4aa847216613aa81983 id: 5eb3e4aa847216613aa81983
title: Semiprime title: Semiprimi
challengeType: 5 challengeType: 5
forumTopicId: 385318 forumTopicId: 385318
dashedName: semiprime dashedName: semiprime
@ -8,83 +8,83 @@ dashedName: semiprime
# --description-- # --description--
Semiprime numbers are natural numbers that are products of exactly two (possibly equal) [prime numbers](https://rosettacode.org/wiki/prime_number). I numeri semiprimi sono numeri naturali che sono il prodotto di esattamente due [numeri primi](https://rosettacode.org/wiki/prime_number) (anche uguali).
<pre>1679 = 23 x 73</pre> <pre>1679 = 23 x 73</pre>
# --instructions-- # --instructions--
Write a function that returns true if a number is semiprime, or false if it is not. Scrivi una funzione che restituisce vero se un numero è semiprimo, o falso se non lo è.
# --hints-- # --hints--
`isSemiPrime` should be a function. `isSemiPrime` dovrebbe essere una funzione.
```js ```js
assert(typeof isSemiPrime === 'function'); assert(typeof isSemiPrime === 'function');
``` ```
`isSemiPrime(100)` should return a boolean. `isSemiPrime(100)` dovrebbe restituire un booleano.
```js ```js
assert(typeof isSemiPrime(100) === 'boolean'); assert(typeof isSemiPrime(100) === 'boolean');
``` ```
`isSemiPrime(100)` should return `false`. `isSemiPrime(100)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSemiPrime(100), false); assert.equal(isSemiPrime(100), false);
``` ```
`isSemiPrime(504)` should return `false`. `isSemiPrime(504)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSemiPrime(504), false); assert.equal(isSemiPrime(504), false);
``` ```
`isSemiPrime(4)` should return `true`. `isSemiPrime(4)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSemiPrime(4), true); assert.equal(isSemiPrime(4), true);
``` ```
`isSemiPrime(46)` should return `true`. `isSemiPrime(46)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSemiPrime(46), true); assert.equal(isSemiPrime(46), true);
``` ```
`isSemiPrime(13)` should return `false`. `isSemiPrime(13)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSemiPrime(13), false); assert.equal(isSemiPrime(13), false);
``` ```
`isSemiPrime(74)` should return `true`. `isSemiPrime(74)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSemiPrime(74), true); assert.equal(isSemiPrime(74), true);
``` ```
`isSemiPrime(1679)` should return `true`. `isSemiPrime(1679)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSemiPrime(1679), true); assert.equal(isSemiPrime(1679), true);
``` ```
`isSemiPrime(2)` should return `false`. `isSemiPrime(2)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSemiPrime(2), false); assert.equal(isSemiPrime(2), false);
``` ```
`isSemiPrime(95)` should return `true`. `isSemiPrime(95)` dovrebbe restituire `true`.
```js ```js
assert.equal(isSemiPrime(95), true); assert.equal(isSemiPrime(95), true);
``` ```
`isSemiPrime(124)` should return `false`. `isSemiPrime(124)` dovrebbe restituire `false`.
```js ```js
assert.equal(isSemiPrime(124), false); assert.equal(isSemiPrime(124), false);

View File

@ -1,6 +1,6 @@
--- ---
id: 5eb3e4af7d0e7b760b46cedc id: 5eb3e4af7d0e7b760b46cedc
title: Set consolidation title: Consolidazione di insiemi
challengeType: 5 challengeType: 5
forumTopicId: 385319 forumTopicId: 385319
dashedName: set-consolidation dashedName: set-consolidation
@ -8,58 +8,58 @@ dashedName: set-consolidation
# --description-- # --description--
Given two sets of items then if any item is common to any set then the result of applying *consolidation* to those sets is a set of sets whose contents is: Dati due set di elementi, se un elemento è comune in comune tra almeno due set allora il risultato di applicare la *consolidazione* a questi set è un set di set il cui contenuto è:
<ul> <ul>
<li>The two input sets if no common item exists between the two input sets of items.</li> <li>I due set di input se non c'è alcun elemento in comune tra i due set di elementi di input.</li>
<li>The single set that is the union of the two input sets if they share a common item.</li> <li>Il singolo set che è unione dei due set di input se hanno un elemento in comune.</li>
</ul> </ul>
Given N sets of items where N > 2 then the result is the same as repeatedly replacing all combinations of two sets by their consolidation until no further consolidation between set pairs is possible. If N &lt; 2 then consolidation has no strict meaning and the input can be returned. Dati N set di elementi done N > 2 allora il risultato è lo stesso di sostituire ripetutamente tutte le combinazioni di due set con la loro consolidazione finché non è più possibile alcuna altra consolidazione tra coppie di set. Se N &lt; 2 allora la consolidazione non ha significatio e l'input può essere restituito.
Here are some examples: Ecco alcuni esempi:
**Example 1:** **Esempio 1:**
Given the two sets `{A,B}` and `{C,D}` then there is no common element between the sets and the result is the same as the input. Dati due set `{A,B}` e `{C,D}` allora non c'è alcun elemento in comune tra i set e il risultato è lo stesso dell'input.
**Example 2:** **Esempio 2:**
Given the two sets `{A,B}` and `{B,D}` then there is a common element `B` between the sets and the result is the single set `{B,D,A}`. (Note that order of items in a set is immaterial: `{A,B,D}` is the same as `{B,D,A}` and `{D,A,B}`, etc). Dati due set `{A,B}` e `{B,D}` allora c'è un elemento in comune `B` tra i due set e il risultato è il singolo set `{B,D,A}`. (Nota che l'ordine degli elementi in un set è immateriale: `{A,B,D}` è lo stesso di `{B,D,A}` e di `{D,A,B}`, ecc).
**Example 3:** **Esempio 3:**
Given the three sets `{A,B}` and `{C,D}` and `{D,B}` then there is no common element between the sets `{A,B}` and `{C,D}` but the sets `{A,B}` and `{D,B}` do share a common element that consolidates to produce the result `{B,D,A}`. On examining this result with the remaining set, `{C,D}`, they share a common element and so consolidate to the final output of the single set `{A,B,C,D}` Dati tre set `{A,B}` e `{C,D}` e `{D,B}`, non c'è un elemento in comune tra i set `{A,B}` e `{C,D}` ma i set `{A,B}` e `{D,B}` hanno un elemento in comune che consolida per produrre il risultato `{B,D,A}`. Esamindando questo risultato con il set rimanente, `{C,D}`, hanno un elemento in comune e consolidato a formare l'output finale del singolo set `{A,B,C,D}`
**Example 4:** **Esempio 4:**
The consolidation of the five sets: Il consolidamento dei cinque gruppi:
`{H,I,K}`, `{A,B}`, `{C,D}`, `{D,B}`, and `{F,G,H}` `{H,I,K}`, `{A,B}`, `{C,D}`, `{D,B}`, e `{F,G,H}`
Is the two sets: Risulta nei due set:
`{A, C, B, D}`, and `{G, F, I, H, K}` `{A, C, B, D}`, e `{G, F, I, H, K}`
# --instructions-- # --instructions--
Write a function that takes an array of strings as a parameter. Each string is represents a set with the characters representing the set elements. The function should return a 2D array containing the consolidated sets. Note: Each set should be sorted. Scrivi una funzione che prende un array di stringhe come parametro. Ogni stringa rappresenta un set con i caratteri rappresentando gli elementi del set. La funzione dovrebbe restituire un array 2D contenente i set consolidati. Nota: Ogni set deve essere ordinato.
# --hints-- # --hints--
`setConsolidation` should be a function. `setConsolidation` dovrebbe essere una funzione.
```js ```js
assert(typeof setConsolidation === 'function'); assert(typeof setConsolidation === 'function');
``` ```
`setConsolidation(["AB", "CD"])` should return a array. `setConsolidation(["AB", "CD"])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(setConsolidation(['AB', 'CD']))); assert(Array.isArray(setConsolidation(['AB', 'CD'])));
``` ```
`setConsolidation(["AB", "CD"])` should return `[["C", "D"], ["A", "B"]]`. `setConsolidation(["AB", "CD"])` dovrebbe restituire `[["C", "D"], ["A", "B"]]`.
```js ```js
assert.deepEqual(setConsolidation(['AB', 'CD']), [ assert.deepEqual(setConsolidation(['AB', 'CD']), [
@ -68,19 +68,19 @@ assert.deepEqual(setConsolidation(['AB', 'CD']), [
]); ]);
``` ```
`setConsolidation(["AB", "BD"])` should return `[["A", "B", "D"]]`. `setConsolidation(["AB", "BD"])` dovrebbe restituire `[["A", "B", "D"]]`.
```js ```js
assert.deepEqual(setConsolidation(['AB', 'BD']), [['A', 'B', 'D']]); assert.deepEqual(setConsolidation(['AB', 'BD']), [['A', 'B', 'D']]);
``` ```
`setConsolidation(["AB", "CD", "DB"])` should return `[["A", "B", "C", "D"]]`. `setConsolidation(["AB", "CD", "DB"])` dovrebbe restituire `[["A", "B", "C", "D"]]`.
```js ```js
assert.deepEqual(setConsolidation(['AB', 'CD', 'DB']), [['A', 'B', 'C', 'D']]); assert.deepEqual(setConsolidation(['AB', 'CD', 'DB']), [['A', 'B', 'C', 'D']]);
``` ```
`setConsolidation(["HIK", "AB", "CD", "DB", "FGH"])` should return `[["F", "G", "H", "I", "K"], ["A", "B", "C", "D"]]`. `setConsolidation(["HIK", "AB", "CD", "DB", "FGH"])` dovrebbe restituire `[["F", "G", "H", "I", "K"], ["A", "B", "C", "D"]]`.
```js ```js
assert.deepEqual(setConsolidation(['HIK', 'AB', 'CD', 'DB', 'FGH']), [ assert.deepEqual(setConsolidation(['HIK', 'AB', 'CD', 'DB', 'FGH']), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5eb3e4b20aa93c437f9e9717 id: 5eb3e4b20aa93c437f9e9717
title: Set of real numbers title: Insieme di numeri reali
challengeType: 5 challengeType: 5
forumTopicId: 385322 forumTopicId: 385322
dashedName: set-of-real-numbers dashedName: set-of-real-numbers
@ -8,7 +8,7 @@ dashedName: set-of-real-numbers
# --description-- # --description--
All real numbers form the uncountable set . Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers *a* and *b* where *a**b*. There are actually four cases for the meaning of "between", depending on open or closed boundary: Tutti i numeri reali formano l'insieme non numerabile R. Tra i suoi sottoinsiemi, relativamente semplici sono gli insiemi convessi, ciascuno espresso come intervallo tra due numeri reali *a* e *b* dove *a**b*. Ci sono in realtà quattro casi per il significato di "tra", a seconda che l'intervallo sia aperto o chiuso:
<ul> <ul>
<li>[<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i><i>x</i> and <i>x</i><i>b</i> }</li> <li>[<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i><i>x</i> and <i>x</i><i>b</i> }</li>
@ -17,52 +17,52 @@ All real numbers form the uncountable set . Among its subsets, relatively sim
<li>(<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i> < <i>x</i> and <i>x</i><i>b</i> }</li> <li>(<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i> < <i>x</i> and <i>x</i><i>b</i> }</li>
</ul> </ul>
Note that if *a* = *b*, of the four only \[*a*, *a*] would be non-empty. Nota che se *a* = *b*, dei quattro solo \[*a*, *a*] non sarebbero vuoti.
**Task** **Compito**
<ul> <ul>
<li>Devise a way to represent any set of real numbers, for the definition of "any" in the implementation notes below.</li> <li>Definisci un modo per rappresentare qualsiasi insieme di numeri reali, per la definizione di "any" nelle note di implementazione qui sotto.</li>
<li>Provide methods for these common set operations (<i>x</i> is a real number; <i>A</i> and <i>B</i> are sets):</li> <li>Fornisci dei metodi per queste operazioni comuni sugli insiemi (<i>x</i> è un numero reale; <i>A</i> e <i>B</i> sono insiemi):</li>
<ul> <ul>
<li> <li>
<i>x</i><i>A</i>: determine if <i>x</i> is an element of <i>A</i><br> <i>x</i><i>A</i>: determinare se <i>x</i> è un elemento di <i>A</i><br>
example: 1 is in [1, 2), while 2, 3, ... are not. esempio: 1 è in [1, 2), mentre 2, 3, . . non lo sono.
</li> </li>
<li> <li>
<i>A</i> <i>B</i>: union of <i>A</i> and <i>B</i>, i.e. {<i>x</i> | <i>x</i> <i>A</i> or <i>x</i> <i>B</i>}<br> <i>A</i> <i>B</i>: unione di <i>A</i> e <i>B</i>, cioè {<i>x</i> <unk> <i>x</i> <unk> <i>A</i> oppure <i>x</i> <unk> <i>B</i>}<br>
example: [0, 2) (1, 3) = [0, 3); [0, 1) (2, 3] = well, [0, 1) (2, 3] esempio: [0, 2) (1, 3) = [0, 3; [0, 1) (2, 3] = pozzo, [0, 1) (2, 3]
</li> </li>
<li> <li>
<i>A</i><i>B</i>: intersection of <i>A</i> and <i>B</i>, i.e. {<i>x</i> | <i>x</i><i>A</i> and <i>x</i><i>B</i>}<br> <i>A</i><i>B</i>: intersezione di <i>A</i> e <i>B</i>, cioè {<i>x</i> | <i>x</i><i>A</i> e <i>x</i><i>B</i>}<br>
example: [0, 2) ∩ (1, 3) = (1, 2); [0, 1) ∩ (2, 3] = empty set esempio: [0, 2) ∩ (1, 3) = (1, 2); [0, 1) ∩ (2, 3] = insieme vuoto
</li> </li>
<li> <li>
<i>A</i> - <i>B</i>: difference between <i>A</i> and <i>B</i>, also written as <i>A</i> \ <i>B</i>, i.e. {<i>x</i> | <i>x</i><i>A</i> and <i>x</i><i>B</i>}<br> <i>A</i> - <i>B</i>: differenza tra <i>A</i> e <i>B</i>, anche scritto come <i>A</i> \ <i>B</i>, cioè {<i>x</i> | <i>x</i><i>A</i> e <i>x</i> <unk> <i>B</i>}<br>
example: [0, 2) (1, 3) = [0, 1] esempio: [0, 2) - (1, 3) = [0, 1]
</li> </li>
</ul> </ul>
</ul> </ul>
# --instructions-- # --instructions--
Write a function that takes 2 objects, a string and an array as parameters. The objects represents the set and have attributes: `low`, `high` and `rangeType`. Scrivi una funzione che richiede 2 oggetti, una stringa e un array come parametri. Gli oggetti rappresentano l'insieme e hanno attributi: `low`, `high` e `rangeType`.
The `rangeType` can have values 0, 1, 2 and 3 for `CLOSED`, `BOTH_OPEN`, `LEFT_OPEN` and `RIGHT_OPEN`, respectively. The function should implement a set using this information. Il `rangeType` può avere valori 0, 1, 2 e 3 per `CLOSED`, `BOTH_OPEN`, `LEFT_OPEN` e `RIGHT_OPEN`, rispettivamente. La funzione dovrebbe implementare un insieme utilizzando queste informazioni.
The string represents the operation to be performed on the sets. It can be: `"union"`, `"intersect"` and `"subtract"` (difference). La stringa rappresenta l'operazione da eseguire sugli insiemi. Può essere: `"union"`, `"intersect"` e `"subtract"` (differenza).
After performing the operation, the function should check if the values in the array are present in the resultant set and store a corresponding boolean value to an array. The function should return this array. Dopo aver eseguito l'operazione, la funzione dovrebbe controllare se i valori nell'array sono presenti nell'insieme risultante e memorizzare un valore booleano corrispondente a un array. La funzione dovrebbe restituire questo array.
# --hints-- # --hints--
`realSet` should be a function. `realSet` dovrebbe essere una funzione.
```js ```js
assert(typeof realSet == 'function'); assert(typeof realSet == 'function');
``` ```
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` should return a array. `realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -77,7 +77,7 @@ assert(
); );
``` ```
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` should return `[true, false, false]`. `realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` dovrebbe restituire `[true, false, false]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -91,7 +91,7 @@ assert.deepEqual(
); );
``` ```
`realSet({"low":0, "high":2, "rangeType":3}, {"low":1, "high":2, "rangeType":2}, "intersect", [0, 1, 2])` should return `[false, false, false]`. `realSet({"low":0, "high":2, "rangeType":3}, {"low":1, "high":2, "rangeType":2}, "intersect", [0, 1, 2])` dovrebbe restituire `[false, false, false]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -105,7 +105,7 @@ assert.deepEqual(
); );
``` ```
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":1}, "subtract", [0, 1, 2])` should return `[true, true, true]`. `realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":1}, "subtract", [0, 1, 2])` dovrebbe restituire `[true, true, true]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -119,7 +119,7 @@ assert.deepEqual(
); );
``` ```
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":0}, "subtract", [0, 1, 2])` should return `[false, false, true]`. `realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":0}, "subtract", [0, 1, 2])` dovrebbe restituire `[false, false, true]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -133,7 +133,7 @@ assert.deepEqual(
); );
``` ```
`realSet({"low":0, "high":33, "rangeType":1}, {"low":30, "high":31, "rangeType":0}, "intersect", [30, 31, 32])` should return `[true, true, false]`. `realSet({"low":0, "high":33, "rangeType":1}, {"low":30, "high":31, "rangeType":0}, "intersect", [30, 31, 32])` dovrebbe restituire `[true, true, false]`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -8,59 +8,59 @@ dashedName: sha-1
# --description-- # --description--
**SHA-1** or **SHA1** is a one-way hash function; it computes a 160-bit message digest. **SHA-1** o **SHA1** è una funzione di hash unidirezionale; calcola una sintesi (digest) a 160 bit del messaggio.
SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. SHA-1 compare spesso nei protocolli di sicurezza; per esempio, molti siti Web HTTPS usano RSA con SHA-1 per proteggere le loro connessioni.
BitTorrent uses SHA-1 to verify downloads. BitTorrent utilizza SHA-1 per verificare i download.
Git and Mercurial use SHA-1 digests to identify commits. Git e Mercurial usano i digest SHA-1 per identificare i commit.
A US government standard, [FIPS 180-1](https://rosettacode.org/wiki/SHA-1/FIPS-180-1), defines SHA-1. Uno standard governativo US, [FIPS 180-1](https://rosettacode.org/wiki/SHA-1/FIPS-180-1), definisce SHA-1.
# --instructions-- # --instructions--
Write a function that returns the SHA-1 message digest for a given string. Scrivi una funzione che restituisce il digest SHA-1 per una determinata stringa.
# --hints-- # --hints--
`SHA1` should be a function. `SHA1` dovrebbe essere una funzione.
```js ```js
assert(typeof SHA1 === 'function'); assert(typeof SHA1 === 'function');
``` ```
`SHA1("abc")` should return a string. `SHA1("abc")` dovrebbe restituire una stringa.
```js ```js
assert(typeof SHA1('abc') === 'string'); assert(typeof SHA1('abc') === 'string');
``` ```
`SHA1("abc")` should return `"a9993e364706816aba3e25717850c26c9cd0d89d"`. `SHA1("abc")` dovrebbe restituire `"a9993e364706816aba3e25717850c26c9cd0d89d"`.
```js ```js
assert.equal(SHA1('abc'), 'a9993e364706816aba3e25717850c26c9cd0d89d'); assert.equal(SHA1('abc'), 'a9993e364706816aba3e25717850c26c9cd0d89d');
``` ```
`SHA1("Rosetta Code")` should return `"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"`. `SHA1("Rosetta Code")` dovrebbe restituire `"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"`.
```js ```js
assert.equal(SHA1('Rosetta Code'), '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5'); assert.equal(SHA1('Rosetta Code'), '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5');
``` ```
`SHA1("Hello world")` should return `"7b502c3a1f48c8609ae212cdfb639dee39673f5e"`. `SHA1("Hello world")` dovrebbe restituire `"7b502c3a1f48c8609ae212cdfb639dee39673f5e"`.
```js ```js
assert.equal(SHA1('Hello world'), '7b502c3a1f48c8609ae212cdfb639dee39673f5e'); assert.equal(SHA1('Hello world'), '7b502c3a1f48c8609ae212cdfb639dee39673f5e');
``` ```
`SHA1("Programming")` should return `"d1a946bf8b2f2a7292c250063ee28989d742cd4b"`. `SHA1("Programming")` dovrebbe restituire `"d1a946bf8b2f2a7292c250063ee28989d742cd4b"`.
```js ```js
assert.equal(SHA1('Programming'), 'd1a946bf8b2f2a7292c250063ee28989d742cd4b'); assert.equal(SHA1('Programming'), 'd1a946bf8b2f2a7292c250063ee28989d742cd4b');
``` ```
`SHA1("is Awesome")` should return `"6537205da59c72b57ed3881843c2d24103d683a3"`. `SHA1("is Awesome")` dovrebbe restituire `"6537205da59c72b57ed3881843c2d24103d683a3"`.
```js ```js
assert.equal(SHA1('is Awesome'), '6537205da59c72b57ed3881843c2d24103d683a3'); assert.equal(SHA1('is Awesome'), '6537205da59c72b57ed3881843c2d24103d683a3');

View File

@ -8,27 +8,27 @@ dashedName: sha-256
# --description-- # --description--
The `SHA-2` family is a stronger alternative to `SHA-1`. The main difference between them is the length of the hash. Meaning `SHA-1` provides a shorter code with fewer possibilities for unique combinations. `SHA-2` or `SHA-256` creates a longer and thus more complex hash with more possibilities. La famiglia `SHA-2` è un'alternativa più forte a `SHA-1`. La differenza principale tra loro è la lunghezza dell'hash. Vol dire che `SHA-1` fornisce un codice più breve con meno possibilità di combinazioni uniche. `SHA-2` o `SHA-256` crea un hash più lungo e quindi più complesso con più possibilità.
# --instructions-- # --instructions--
Research implemenation details and write a function that takes a string as the parameter and returns a hash using `SHA-256` Ricerca i dettagli di implementazione e scrivi una funzione che prende una stringa come parametro e restituisce un hash utilizzando `SHA-256`
# --hints-- # --hints--
`SHA256` should be a function. `SHA256` dovrebbe essere una funzione.
```js ```js
assert(typeof SHA256 === 'function'); assert(typeof SHA256 === 'function');
``` ```
`SHA256("Rosetta code")` should return a string. `SHA256("Rosetta code")` dovrebbe restituire una stringa.
```js ```js
assert(typeof SHA256('Rosetta code') === 'string'); assert(typeof SHA256('Rosetta code') === 'string');
``` ```
`SHA256("Rosetta code")` should return `"764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf"`. `SHA256("Rosetta code")` dovrebbe restituire `"764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf"`.
```js ```js
assert.equal( assert.equal(
@ -37,7 +37,7 @@ assert.equal(
); );
``` ```
`SHA256("SHA-256 Hash")` should return `"bee8c0cabdcf8c7835f40217dd35a8b0dba9134520e633f1c57285f35ca7ee3e"`. `SHA256("SHA-256 Hash")` dovrebbe restituire `"bee8c0cabdcf8c7835f40217dd35a8b0dba9134520e633f1c57285f35ca7ee3e"`.
```js ```js
assert.equal( assert.equal(
@ -46,7 +46,7 @@ assert.equal(
); );
``` ```
`SHA256("implementation")` should return `"da31012c40330e7e21538e7dd57503b16e8a0839159e96137090cccc9910b171"`. `SHA256("implementation")` dovrebbe restituire `"da31012c40330e7e21538e7dd57503b16e8a0839159e96137090cccc9910b171"`.
```js ```js
assert.equal( assert.equal(
@ -55,7 +55,7 @@ assert.equal(
); );
``` ```
`SHA256("algorithm")` should return `"b1eb2ec8ac9f31ff7918231e67f96e6deda83a9ff33ed2c67443f1df81e5ed14"`. `SHA256("algorithm")` dovrebbe restituire `"b1eb2ec8ac9f31ff7918231e67f96e6deda83a9ff33ed2c67443f1df81e5ed14"`.
```js ```js
assert.equal( assert.equal(
@ -64,7 +64,7 @@ assert.equal(
); );
``` ```
`SHA256("language")` should return `"a4ef304ba42a200bafd78b046e0869af9183f6eee5524aead5dcb3a5ab5f8f3f"`. `SHA256("language")` dovrebbe restituire `"a4ef304ba42a200bafd78b046e0869af9183f6eee5524aead5dcb3a5ab5f8f3f"`.
```js ```js
assert.equal( assert.equal(

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc7ffe id: 5a23c84252665b21eecc7ffe
title: Sort an array of composite structures title: Ordina un array di strutture composite
challengeType: 5 challengeType: 5
forumTopicId: 302306 forumTopicId: 302306
dashedName: sort-an-array-of-composite-structures dashedName: sort-an-array-of-composite-structures
@ -8,17 +8,17 @@ dashedName: sort-an-array-of-composite-structures
# --description-- # --description--
Write a function that takes an array of objects as a parameter. The function should sort the array according to the 'key' attribute of the objects and return the sorted array. Scrivi una funzione che richiede un array di oggetti come parametro. La funzione dovrebbe ordinare l'array usando l'attributo key degli oggetti e restituire l'array ordinato.
# --hints-- # --hints--
`sortByKey` should be a function. `sortByKey` dovrebbe essere una funzione.
```js ```js
assert(typeof sortByKey == 'function'); assert(typeof sortByKey == 'function');
``` ```
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` should return an array. `sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -34,7 +34,7 @@ assert(
); );
``` ```
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` should return `[{key: 1, value: 42}, {key: 2, value: "bar"}, {key: 3, value: "foo"}, {key: 4, value: "baz"}, {key: 5, value: "another string"}]`. `sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` dovrebbe restituire `[{key: 1, value: 42}, {key: 2, value: "bar"}, {key: 3, value: "foo"}, {key: 4, value: "baz"}, {key: 5, value: "another string"}]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -55,7 +55,7 @@ assert.deepEqual(
); );
``` ```
`sortByKey([{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 20, name: "Alice"}, {key: 5, name: "Harry"}])` should return `[{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 5, name: "Harry"}, {key: 20, name: "Alice"}]`. `sortByKey([{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 20, name: "Alice"}, {key: 5, name: "Harry"}])` dovrebbe restituire `[{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 5, name: "Harry"}, {key: 20, name: "Alice"}]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -74,7 +74,7 @@ assert.deepEqual(
); );
``` ```
`sortByKey([{key: 2341, name: "Adam"}, {key: 122, name: "Bernie"}, {key: 19, name: "David"}, {key: 5531, name: "Joe"}, {key: 1234, name: "Walter"}])` should return `[{key: 19, name: "David"}, {key: 122, name: "Bernie"}, {key: 1234, name: "Walter"}, {key: 2341, name: "Adam"}, {key: 5531, name: "Joe"}]`. `sortByKey([{key: 2341, name: "Adam"}, {key: 122, name: "Bernie"}, {key: 19, name: "David"}, {key: 5531, name: "Joe"}, {key: 1234, name: "Walter"}])` dovrebbe restituire `[{key: 19, name: "David"}, {key: 122, name: "Bernie"}, {key: 1234, name: "Walter"}, {key: 2341, name: "Adam"}, {key: 5531, name: "Joe"}]`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8000 id: 5a23c84252665b21eecc8000
title: Sort disjoint sublist title: Ordina sottoliste disgiunte
challengeType: 5 challengeType: 5
forumTopicId: 302307 forumTopicId: 302307
dashedName: sort-disjoint-sublist dashedName: sort-disjoint-sublist
@ -8,9 +8,9 @@ dashedName: sort-disjoint-sublist
# --description-- # --description--
Given a list of values and a set of integer indices into that value list, the task is to sort the values at the given indices, but preserving the values at indices outside the set of those to be sorted. Dato un elenco di valori e un insieme di indici interi in tale lista di valori, l'attività è quella di ordinare i valori negli indici indicati, ma mantenendo i valori in indici al di fuori dell'insieme di quelli da ordinare.
Make your function work with the following list of values and set of indices: Fai funzionare la tua funzione con il seguente elenco di valori e set di indici:
<code>values: [7, <b>6</b>, 5, 4, 3, 2, <b>1</b>, <b>0</b>]</code> <code>values: [7, <b>6</b>, 5, 4, 3, 2, <b>1</b>, <b>0</b>]</code>
@ -18,25 +18,25 @@ Make your function work with the following list of values and set of indices:
indices(0-based): {6, 1, 7} indices(0-based): {6, 1, 7}
``` ```
Where the correct result would be: Dove il risultato corretto sarà:
<code>[7, <b>0</b>, 5, 4, 3, 2, <b>1</b>, <b>6</b>]</code>. <code>[7, <b>0</b>, 5, 4, 3, 2, <b>1</b>, <b>6</b>]</code>.
# --hints-- # --hints--
`sortDisjoint` should be a function. `sortDisjoint` dovrebbe essere una funzione.
```js ```js
assert(typeof sortDisjoint == 'function'); assert(typeof sortDisjoint == 'function');
``` ```
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` should return an array. `sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]))); assert(Array.isArray(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])));
``` ```
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` should return `[7, 0, 5, 4, 3, 2, 1, 6]`. `sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` dovrebbe restituire `[7, 0, 5, 4, 3, 2, 1, 6]`.
```js ```js
assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]), [ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]), [
@ -51,7 +51,7 @@ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]), [
]); ]);
``` ```
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6])` should return `[7, 1, 2, 4, 3, 5, 6, 0]`. `sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6])` dovrebbe restituire `[7, 1, 2, 4, 3, 5, 6, 0]`.
```js ```js
assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6]), [ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6]), [
@ -66,7 +66,7 @@ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6]), [
]); ]);
``` ```
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7])` should return `[8, 1, 6, 5, 4, 3, 2, 7]`. `sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7])` dovrebbe restituire `[8, 1, 6, 5, 4, 3, 2, 7]`.
```js ```js
assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7]), [ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7]), [
@ -81,7 +81,7 @@ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7]), [
]); ]);
``` ```
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6])` should return `[8, 2, 6, 3, 4, 5, 7, 1]`. `sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6])` dovrebbe restituire `[8, 2, 6, 3, 4, 5, 7, 1]`.
```js ```js
assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6]), [ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6]), [
@ -96,7 +96,7 @@ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6]), [
]); ]);
``` ```
`sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4])` should return `[6, 1, 7, 1, 3, 5, 6]`. `sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4])` dovrebbe restituire `[6, 1, 7, 1, 3, 5, 6]`.
```js ```js
assert.deepEqual(sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4]), [ assert.deepEqual(sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8014 id: 5a23c84252665b21eecc8014
title: Sort stability title: Stabilità dell'ordinamento
challengeType: 5 challengeType: 5
forumTopicId: 302308 forumTopicId: 302308
dashedName: sort-stability dashedName: sort-stability
@ -8,9 +8,9 @@ dashedName: sort-stability
# --description-- # --description--
When sorting records in a table by a particular column or field, a [stable sort](https://en.wikipedia.org/wiki/Stable_sort#Stability) will always retain the relative order of records that have the same key. Quando si ordinano i record in una tabella per una particolare colonna o campo, un [ordinamento stabile](https://en.wikipedia.org/wiki/Stable_sort#Stability) manterrà sempre l'ordine relativo dei record che hanno la stessa chiave.
For example, in this table of countries and cities, a stable sort on the **second** column, the cities, would keep the US Birmingham above the UK Birmingham. (Although an unstable sort *might*, in this case, place the US Birmingham above the UK Birmingham, a stable sort routine would *guarantee* it). Ad esempio, in questa tabella di paesi e città, un ordinamento stabile sulla **seconda** colonna, le città, manterrebbe US Birmingham sopra UK Birmingham. (Anche se un ordinamento instabile *potrebbe*, in questo caso, posizionare US Birmingham sopra UK Birmingham, un ordinamento stabile lo *garantirebbe* esso).
<pre>UK London <pre>UK London
US New York US New York
@ -18,21 +18,21 @@ US Birmingham
UK Birmingham UK Birmingham
</pre> </pre>
Similarly, stable sorting on just the first column would generate "UK London" as the first item and "US Birmingham" as the last item (since the order of the elements having the same first word "UK" or "US" would be maintained). Allo stesso modo, l'ordinamento stabile fatto solo sulla prima colonna genererebbe "UK London" come primo elemento e "US Birmingham" come ultimo elemento (perché l'ordine degli elementi con la stessa prima parola "UK" o "US" sarebbe mantenuto).
# --instructions-- # --instructions--
Write a function that takes a 2D array as a parameter. Each element has 2 elements similar to the above example. The function should sort the array as mentioned previously and return the sorted array. Scrivi una funzione che richiede un array bidimensionale come parametro. Ogni elemento ha 2 elementi simili all'esempio precedente. La funzione dovrebbe ordinare l'array come menzionato precedentemente e restituire l'array ordinato.
# --hints-- # --hints--
`stableSort` should be a function. `stableSort` dovrebbe essere una funzione.
```js ```js
assert(typeof stableSort == 'function'); assert(typeof stableSort == 'function');
``` ```
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` should return an array. `stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -47,7 +47,7 @@ assert(
); );
``` ```
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` should return `[["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]]`. `stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` dovrebbe restituire `[["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -66,7 +66,7 @@ assert.deepEqual(
); );
``` ```
`stableSort([[2, 2], [1, 2], [1, 4], [1, 5]])` should return `[[2, 2], [1, 2], [1, 4], [1, 5]]`. `stableSort([[2, 2], [1, 2], [1, 4], [1, 5]])` dovrebbe restituire `[[2, 2], [1, 2], [1, 4], [1, 5]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -85,7 +85,7 @@ assert.deepEqual(
); );
``` ```
`stableSort([[11, 55], [12, 45], [11, 45], [32, 45]])` should return `[[12, 45], [11, 45], [32, 45], [11, 55]]`. `stableSort([[11, 55], [12, 45], [11, 45], [32, 45]])` dovrebbe restituire `[[12, 45], [11, 45], [32, 45], [11, 55]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -104,7 +104,7 @@ assert.deepEqual(
); );
``` ```
`stableSort([[10, 22], [1, 2], [1, 4], [1, 5], [10, 9]])` should return `[[1, 2], [1, 4], [1, 5], [10, 9], [10, 22]]`. `stableSort([[10, 22], [1, 2], [1, 4], [1, 5], [10, 9]])` dovrebbe restituire `[[1, 2], [1, 4], [1, 5], [10, 9], [10, 22]]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -125,7 +125,7 @@ assert.deepEqual(
); );
``` ```
`stableSort([[55, 54], [12, 22], [31, 43], [31, 54], [10, 49]])` should return `[[12, 22], [31, 43], [10, 49], [55, 54], [31, 54]]`. `stableSort([[55, 54], [12, 22], [31, 43], [31, 54], [10, 49]])` dovrebbe restituire `[[12, 22], [31, 43], [10, 49], [55, 54], [31, 54]]`.
```js ```js
assert.deepEqual( assert.deepEqual(

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8016 id: 5a23c84252665b21eecc8016
title: Sort using a custom comparator title: Ordina usando un comparatore personalizzato
challengeType: 5 challengeType: 5
forumTopicId: 302309 forumTopicId: 302309
dashedName: sort-using-a-custom-comparator dashedName: sort-using-a-custom-comparator
@ -8,17 +8,17 @@ dashedName: sort-using-a-custom-comparator
# --description-- # --description--
Write a function to sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length. Scrivi una funzione per ordinare un array (o una lista) di stringhe in ordine di lunghezza decrescente, e in ordine lessicografico ascendente per stringhe di uguale lunghezza.
# --hints-- # --hints--
`lengthSorter` should be a function. `lengthSorter` dovrebbe essere una funzione.
```js ```js
assert(typeof lengthSorter == 'function'); assert(typeof lengthSorter == 'function');
``` ```
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` should return an array. `lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` dovrebbe restituire un array.
```js ```js
assert( assert(
@ -37,7 +37,7 @@ assert(
); );
``` ```
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` should return `["strings", "sample", "sorted", "Here", "some", "are", "be", "to"]`. `lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` dovrebbe restituire `["strings", "sample", "sorted", "Here", "some", "are", "be", "to"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -55,7 +55,7 @@ assert.deepEqual(
); );
``` ```
`lengthSorter(["I", "hope", "your", "day", "is", "going", "good", "?"])` should return `["going", "good", "hope", "your", "day", "is", "?","I"]`. `lengthSorter(["I", "hope", "your", "day", "is", "going", "good", "?"])` dovrebbe restituire `["going", "good", "hope", "your", "day", "is", "?","I"]`.
```js ```js
assert.deepEqual( assert.deepEqual(
@ -64,7 +64,7 @@ assert.deepEqual(
); );
``` ```
`lengthSorter(["Mine", "is", "going", "great"])` should return `["going", "great", "Mine", "is"]`. `lengthSorter(["Mine", "is", "going", "great"])` dovrebbe restituire `["going", "great", "Mine", "is"]`.
```js ```js
assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [ assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [
@ -75,7 +75,7 @@ assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [
]); ]);
``` ```
`lengthSorter(["Have", "fun", "sorting", "!!"])` should return `["sorting", "Have", "fun", "!!"]`. `lengthSorter(["Have", "fun", "sorting", "!!"])` dovrebbe restituire `["sorting", "Have", "fun", "!!"]`.
```js ```js
assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [ assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [
@ -86,7 +86,7 @@ assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [
]); ]);
``` ```
`lengthSorter(["Everything", "is", "good", "!!"])` should return `["Everything", "good", "!!", "is"]`. `lengthSorter(["Everything", "is", "good", "!!"])` dovrebbe restituire `["Everything", "good", "!!", "is"]`.
```js ```js
assert.deepEqual(lengthSorter(['Everything', 'is', 'good', '!!']), [ assert.deepEqual(lengthSorter(['Everything', 'is', 'good', '!!']), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8001 id: 5a23c84252665b21eecc8001
title: Sorting algorithms/Bead sort title: Algoritmi di ordinamento/Bead sort
challengeType: 5 challengeType: 5
forumTopicId: 302310 forumTopicId: 302310
dashedName: sorting-algorithmsbead-sort dashedName: sorting-algorithmsbead-sort
@ -8,47 +8,47 @@ dashedName: sorting-algorithmsbead-sort
# --description-- # --description--
Sort an array of positive integers using the [Bead Sort Algorithm](https://en.wikipedia.org/wiki/Bead_sort). Ordina un array di interi positivi usando l'[Algoritmo di ordinamento Bead Sort](https://en.wikipedia.org/wiki/Bead_sort).
A *bead sort* is also known as a *gravity sort*. Un *bead sort* è anche conosciuto come un *ordinamento per gravità*.
The algorithm has O(S), where S is the sum of the integers in the input set: Each bead is moved individually. L'algoritmo ha complessità O(S), dove S è la somma degli interi nel set di ingresso: Ogni perla viene spostata singolarmente.
This is the case when bead sort is implemented without a mechanism to assist in finding empty spaces below the beads, such as in software implementations. Questo è il caso in cui Bead Sort è implementato senza un meccanismo per aiutare a trovare spazi vuoti sotto le perle, ad esempio nelle implementazioni software.
# --hints-- # --hints--
`beadSort` should be a function. `beadSort` dovrebbe essere una funzione.
```js ```js
assert(typeof beadSort == 'function'); assert(typeof beadSort == 'function');
``` ```
`beadSort([25, 32, 12, 7, 20])` should return an array. `beadSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(beadSort([25, 32, 12, 7, 20]))); assert(Array.isArray(beadSort([25, 32, 12, 7, 20])));
``` ```
`beadSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `beadSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(beadSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(beadSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`beadSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `beadSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(beadSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(beadSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`beadSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `beadSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(beadSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(beadSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`beadSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `beadSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(beadSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(beadSort([12, 33, 26, 18, 1, 16, 38]), [
@ -62,7 +62,7 @@ assert.deepEqual(beadSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`beadSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `beadSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(beadSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(beadSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8002 id: 5a23c84252665b21eecc8002
title: Sorting algorithms/Bogosort title: Algoritmi di ordinamento/Bogosort
challengeType: 5 challengeType: 5
forumTopicId: 302311 forumTopicId: 302311
dashedName: sorting-algorithmsbogosort dashedName: sorting-algorithmsbogosort
@ -8,17 +8,17 @@ dashedName: sorting-algorithmsbogosort
# --description-- # --description--
[Bogosort](https://en.wikipedia.org/wiki/Bogosort) a list of numbers. [Bogosort](https://en.wikipedia.org/wiki/Bogosort) un elenco di numeri.
Bogosort simply shuffles a collection randomly until it is sorted. Bogosort mescola semplicemente una raccolta in modo casuale fino a quando non viene ordinata.
"Bogosort" is a perversely inefficient algorithm only used as an in-joke. "Bogosort" è un algoritmo perversamente inefficiente usato solo come presa in giro.
Its average run-time is O(n!) because the chance that any given shuffle of a set will end up in sorted order is about one in *n* factorial, and the worst case is infinite since there's no guarantee that a random shuffling will ever produce a sorted sequence. La sua durata media è O(n!) perché la possibilità che qualsiasi mescolamento di un set finisca con un set ordinato è di circa uno su *n* fattoriale, e il caso peggiore è infinito dal momento che non c'è garanzia che un mescolamento casuale mai produrrà una sequenza ordinata.
Its best case is O(n) since a single pass through the elements may suffice to order them. Il suo caso migliore è O(n) poiché un singolo passaggio attraverso gli elementi può essere sufficiente per ordinarli.
Pseudocode: Pseudocodice:
<pre><b>while not</b> InOrder(list) <b>do</b> <pre><b>while not</b> InOrder(list) <b>do</b>
Shuffle(list) Shuffle(list)
@ -27,37 +27,37 @@ Pseudocode:
# --hints-- # --hints--
`bogosort` should be a function. `bogosort` dovrebbe essere una funzione.
```js ```js
assert(typeof bogosort == 'function'); assert(typeof bogosort == 'function');
``` ```
`bogosort([25, 32, 12, 7, 20])` should return an array. `bogosort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(bogosort([25, 32, 12, 7, 20]))); assert(Array.isArray(bogosort([25, 32, 12, 7, 20])));
``` ```
`bogosort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `bogosort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(bogosort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(bogosort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`bogosort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `bogosort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(bogosort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(bogosort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`bogosort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `bogosort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(bogosort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(bogosort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`bogosort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `bogosort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(bogosort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(bogosort([12, 33, 26, 18, 1, 16, 38]), [
@ -71,7 +71,7 @@ assert.deepEqual(bogosort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`bogosort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `bogosort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(bogosort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(bogosort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8004 id: 5a23c84252665b21eecc8004
title: Sorting algorithms/Cocktail sort title: Algoritmi di Ordinamento/Cocktail Sort
challengeType: 5 challengeType: 5
forumTopicId: 302312 forumTopicId: 302312
dashedName: sorting-algorithmscocktail-sort dashedName: sorting-algorithmscocktail-sort
@ -8,7 +8,7 @@ dashedName: sorting-algorithmscocktail-sort
# --description-- # --description--
The cocktail shaker sort is an improvement on the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). The improvement is basically that values "bubble" both directions through the array, because on each iteration the cocktail shaker sort bubble sorts once forwards and once backwards. Pseudocode for the algorithm (from [wikipedia](https://en.wikipedia.org/wiki/Cocktail sort)): L'algoritmo cocktail shaker sort è un miglioramento rispetto a [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). Il miglioramento è fondamentalmente che valuta "bolle" in entrambe le direzioni attraverso l'array, perché ad ogni iterazione il cocktail shaker ordina le bolle una volta avanti e una volta all'indietro. Pseudocodice per l'algoritmo (da [wikipedia](https://en.wikipedia.org/wiki/Cocktail sort)):
<pre><b>function</b> <i>cocktailSort</i>( A : list of sortable items ) <pre><b>function</b> <i>cocktailSort</i>( A : list of sortable items )
<b>do</b> <b>do</b>
@ -34,41 +34,41 @@ The cocktail shaker sort is an improvement on the [Bubble Sort](https://rosettac
# --instructions-- # --instructions--
Write a function that sorts a given array using cocktail sort. Scrivi una funzione che ordina un dato array usando cocktail sort.
# --hints-- # --hints--
`cocktailSort` should be a function. `cocktailSort` dovrebbe essere una funzione.
```js ```js
assert(typeof cocktailSort == 'function'); assert(typeof cocktailSort == 'function');
``` ```
`cocktailSort([25, 32, 12, 7, 20])` should return an array. `cocktailSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(cocktailSort([25, 32, 12, 7, 20]))); assert(Array.isArray(cocktailSort([25, 32, 12, 7, 20])));
``` ```
`cocktailSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `cocktailSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(cocktailSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(cocktailSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`cocktailSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `cocktailSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(cocktailSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(cocktailSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`cocktailSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `cocktailSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(cocktailSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(cocktailSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`cocktailSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `cocktailSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [
@ -82,7 +82,7 @@ assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`cocktailSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `cocktailSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(cocktailSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(cocktailSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8005 id: 5a23c84252665b21eecc8005
title: Sorting algorithms/Comb sort title: Algoritmi di Ordinamento/Comb Sort
challengeType: 5 challengeType: 5
forumTopicId: 302313 forumTopicId: 302313
dashedName: sorting-algorithmscomb-sort dashedName: sorting-algorithmscomb-sort
@ -8,30 +8,30 @@ dashedName: sorting-algorithmscomb-sort
# --description-- # --description--
Implement a *comb sort*. Implementa un *comb sort*.
The **Comb Sort** is a variant of the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). Il **Comb Sort** è una variante del [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
Like the [Shell sort](https://rosettacode.org/wiki/Shell sort), the Comb Sort increases the gap used in comparisons and exchanges. Come lo [Shell sort](https://rosettacode.org/wiki/Shell sort), il Comb Sort aumenta lo spazio utilizzato nei confronti e negli scambi.
Dividing the gap by $(1-e^{-\\varphi})^{-1} \\approx 1.247330950103979$ works best, but 1.3 may be more practical. Dividere il divario per $(1-e^{-\\varphi})^{-1} \\ca. 1.247330950103979$ funziona meglio, ma 1.3 può essere più pratico.
Some implementations use the insertion sort once the gap is less than a certain amount. Alcune implementazioni usano l'insertion sort una volta che il divario è inferiore a una certa quantità.
**Also see** **Vedi anche**
<ul> <ul>
<li>the Wikipedia article: <a href='https://en.wikipedia.org/wiki/Comb sort' target='_blank'>Comb sort</a>.</li> <li>l'articolo Wikipedia: <a href='https://en.wikipedia.org/wiki/Comb sort' target='_blank'>Comb sort</a>.</li>
</ul> </ul>
Variants: Varianti:
<ul> <ul>
<li>Combsort11 makes sure the gap ends in (11, 8, 6, 4, 3, 2, 1), which is significantly faster than the other two possible endings.</li> <li>Combsort11 assicura che il divario finisca in (11, 8, 6, 4, 3, 2, 1), che è significativamente più veloce delle altre due possibili terminazioni.</li>
<li>Combsort with different endings changes to a more efficient sort when the data is almost sorted (when the gap is small). Comb sort with a low gap isn't much better than the Bubble Sort.</li> <li>Combsort con diversi terminali diventa un ordinamento più efficiente quando i dati sono quasi del tutto ordinati (quando il divario è piccolo). Combsort con un gap basso non è molto meglio di Bubble Sort.</li>
</ul> </ul>
Pseudocode: Pseudocodice:
<pre><b>function</b> combsort(<b>array</b> input) <pre><b>function</b> combsort(<b>array</b> input)
gap := input<b>.size</b> <i>//initialize gap size</i> gap := input<b>.size</b> <i>//initialize gap size</i>
@ -59,41 +59,41 @@ Pseudocode:
# --instructions-- # --instructions--
Write a function that sorts a given array using Comb sort. Scrivi una funzione che ordina un determinato array usando Combsort.
# --hints-- # --hints--
`combSort` should be a function. `combSort` dovrebbe essere una funzione.
```js ```js
assert(typeof combSort == 'function'); assert(typeof combSort == 'function');
``` ```
`combSort([25, 32, 12, 7, 20])` should return an array. `combSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(combSort([25, 32, 12, 7, 20]))); assert(Array.isArray(combSort([25, 32, 12, 7, 20])));
``` ```
`combSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `combSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(combSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(combSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`combSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `combSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(combSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(combSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`combSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `combSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(combSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(combSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`combSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `combSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [
@ -107,7 +107,7 @@ assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`combSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `combSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(combSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(combSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8007 id: 5a23c84252665b21eecc8007
title: Sorting algorithms/Gnome sort title: Algoritmi di ordinamento/Gnome sort
challengeType: 5 challengeType: 5
forumTopicId: 302314 forumTopicId: 302314
dashedName: sorting-algorithmsgnome-sort dashedName: sorting-algorithmsgnome-sort
@ -8,9 +8,9 @@ dashedName: sorting-algorithmsgnome-sort
# --description-- # --description--
Gnome sort is a sorting algorithm which is similar to [Insertion sort](https://rosettacode.org/wiki/Insertion sort), except that moving an element to its proper place is accomplished by a series of swaps, as in [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). Gnome Sort è un algoritmo di ordinamento che è simile a [Insertion Sort](https://rosettacode.org/wiki/Insertion sort), tranne che lo spostamento di un elemento al suo posto corretto è realizzato da una serie di scambi, come in [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
The pseudocode for the algorithm is: Lo pseudocodice per l'algoritmo è:
<pre><b>function</b> <i>gnomeSort</i>(a[0..size-1]) <pre><b>function</b> <i>gnomeSort</i>(a[0..size-1])
i := 1 i := 1
@ -33,41 +33,41 @@ The pseudocode for the algorithm is:
# --instructions-- # --instructions--
Write a function to implement the above pseudo code. The function should return the sorted array. Scrivi una funzione che implementi lo pseudocodice di cui sopra. La funzione dovrebbe restituire l'array ordinato.
# --hints-- # --hints--
`gnomeSort` should be a function. `gnomeSort` dovrebbe essere una funzione.
```js ```js
assert(typeof gnomeSort == 'function'); assert(typeof gnomeSort == 'function');
``` ```
`gnomeSort([25, 32, 12, 7, 20])` should return an array. `gnomeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(gnomeSort([25, 32, 12, 7, 20]))); assert(Array.isArray(gnomeSort([25, 32, 12, 7, 20])));
``` ```
`gnomeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `gnomeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(gnomeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(gnomeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`gnomeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `gnomeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(gnomeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(gnomeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`gnomeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `gnomeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(gnomeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(gnomeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`gnomeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `gnomeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [
@ -81,7 +81,7 @@ assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`gnomeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `gnomeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(gnomeSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(gnomeSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc800b id: 5a23c84252665b21eecc800b
title: Sorting algorithms/Pancake sort title: Algoritmi di ordinamento/Pancake sort
challengeType: 5 challengeType: 5
forumTopicId: 302315 forumTopicId: 302315
dashedName: sorting-algorithmspancake-sort dashedName: sorting-algorithmspancake-sort
@ -8,51 +8,51 @@ dashedName: sorting-algorithmspancake-sort
# --description-- # --description--
Write a function to sort an array of integers (of any convenient size) into ascending order using [Pancake sorting](https://en.wikipedia.org/wiki/Pancake sorting). The function should return the sorted array. Scrivi una funzione per ordinare un array di interi (di qualsiasi dimensione conveniente) in ordine crescente usando [Pancake sorting](https://en.wikipedia.org/wiki/Pancake sorting). La funzione dovrebbe restituire l'array ordinato.
In short, instead of individual elements being sorted, the only operation allowed is to "flip" one end of the list, like so: In breve, invece di ordinare singoli elementi, l'unica operazione consentita è quella di "capovolgere" una estremità della lista in questo modo:
<pre>Before: <pre>Prima:
<b>6 7 8 9</b> 2 5 3 4 1<br> <b>6 7 8 9</b> 2 5 3 4 1<br>
After: Dopo:
<b>9 8 7 6</b> 2 5 3 4 1 <b>9 8 7 6</b> 2 5 3 4 1
</pre> </pre>
Only one end of the list can be flipped; this should be the low end, but the high end is okay if it's easier to code or works better, but it **must** be the same end for the entire solution. (The end flipped can't be arbitrarily changed.) Solo una fine della lista può essere capovolta; questa dovrebbe essere l'estremità di valore più basso, ma l'estremità alta va comunque bene se è più facile da codificare o funziona meglio, ma essa **deve** essere la stessa estremità per l'intera soluzione. (L'estremità capovolta non può essere cambiata arbitrariamente.)
# --hints-- # --hints--
`pancakeSort` should be a function. `pancakeSort` dovrebbe essere una funzione.
```js ```js
assert(typeof pancakeSort == 'function'); assert(typeof pancakeSort == 'function');
``` ```
`pancakeSort([25, 32, 12, 7, 20])` should return an array. `pancakeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(pancakeSort([25, 32, 12, 7, 20]))); assert(Array.isArray(pancakeSort([25, 32, 12, 7, 20])));
``` ```
`pancakeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `pancakeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(pancakeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(pancakeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`pancakeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `pancakeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(pancakeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(pancakeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`pancakeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `pancakeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(pancakeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(pancakeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`pancakeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `pancakeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [
@ -66,7 +66,7 @@ assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`pancakeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `pancakeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(pancakeSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(pancakeSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc800c id: 5a23c84252665b21eecc800c
title: Sorting algorithms/Permutation sort title: Algoritmi di ordinamento/Permutation sort
challengeType: 5 challengeType: 5
forumTopicId: 302316 forumTopicId: 302316
dashedName: sorting-algorithmspermutation-sort dashedName: sorting-algorithmspermutation-sort
@ -8,9 +8,9 @@ dashedName: sorting-algorithmspermutation-sort
# --description-- # --description--
Write a function to implement a permutation sort, which proceeds by generating the possible permutations of the input array until discovering the sorted one. The function should return the sorted array. Scrivere una funzione per implementare un ordinamento a permutazione, che procede generando le possibili permutazioni dell'array di input fino a trovare quello ordinato. La funzione dovrebbe restituire l'array ordinato.
Pseudocode: Pseudocodice:
<pre><b>while not</b> InOrder(list) <b>do</b> <pre><b>while not</b> InOrder(list) <b>do</b>
nextPermutation(list) nextPermutation(list)
@ -19,37 +19,37 @@ Pseudocode:
# --hints-- # --hints--
`permutationSort` should be a function. `permutationSort` dovrebbe essere una funzione.
```js ```js
assert(typeof permutationSort == 'function'); assert(typeof permutationSort == 'function');
``` ```
`permutationSort([25, 32, 12, 7, 20])` should return an array. `permutationSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(permutationSort([25, 32, 12, 7, 20]))); assert(Array.isArray(permutationSort([25, 32, 12, 7, 20])));
``` ```
`permutationSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `permutationSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(permutationSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(permutationSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`permutationSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `permutationSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(permutationSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(permutationSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`permutationSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `permutationSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(permutationSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(permutationSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`permutationSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `permutationSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [
@ -63,7 +63,7 @@ assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`permutationSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `permutationSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(permutationSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(permutationSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8010 id: 5a23c84252665b21eecc8010
title: Sorting algorithms/Shell sort title: Algoritmi di ordinamento/Shell Sort
challengeType: 5 challengeType: 5
forumTopicId: 302317 forumTopicId: 302317
dashedName: sorting-algorithmsshell-sort dashedName: sorting-algorithmsshell-sort
@ -8,51 +8,51 @@ dashedName: sorting-algorithmsshell-sort
# --description-- # --description--
Write a function to sort an array of elements using the [Shell sort](https://en.wikipedia.org/wiki/Shell sort) algorithm, a diminishing increment sort. The function should return the sorted array. Scrivi una funzione per ordinare un array di elementi usando l'algoritmo [Shell sort](https://en.wikipedia.org/wiki/Shell sort), un tipo di ordinamento a incremento in diminuzione. La funzione dovrebbe restituire l'array ordinato.
The Shell sort (also known as Shellsort or Shell's method) is named after its inventor, Donald Shell, who published the algorithm in 1959. Shell Short (noto anche come metodo di Shellsort o Shell) prende il nome dal suo inventore, Donald Shell, che ha pubblicato l'algoritmo nel 1959.
Shell sort is a sequence of interleaved insertion sorts based on an increment sequence. The increment size is reduced after each pass until the increment size is 1. Shell Sort è una sequenza di Insertion Sort intercalati basata su una sequenza di incremento. La dimensione dell'incremento viene ridotta dopo ogni passaggio fino a quando la dimensione dell'incremento è 1.
With an increment size of 1, the sort is a basic insertion sort, but by this time the data is guaranteed to be almost sorted, which is insertion sort's "best case". Con un incremento della dimensione di 1, l'ordinamento è un classico Insertion Sort, ma per questo esercizio i dati sono garantiti essere quasi ordinati, che è il "caso migliore" per Insertion Sort.
Any sequence will sort the data as long as it ends in 1, but some work better than others. Qualsiasi sequenza ordinerà i dati finché terminerà in 1, ma alcune funzionano meglio di altre.
Empirical studies have shown a geometric increment sequence with a ratio of about 2.2 work well in practice. Studi empirici hanno mostrato che una sequenza geometrica di incremento con un rapporto di circa 2.2 funziona bene nella pratica.
# --hints-- # --hints--
`shellSort` should be a function. `shellSort` dovrebbe essere una funzione.
```js ```js
assert(typeof shellSort == 'function'); assert(typeof shellSort == 'function');
``` ```
`shellSort([25, 32, 12, 7, 20])` should return an array. `shellSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(shellSort([25, 32, 12, 7, 20]))); assert(Array.isArray(shellSort([25, 32, 12, 7, 20])));
``` ```
`shellSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `shellSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(shellSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(shellSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`shellSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `shellSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(shellSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(shellSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`shellSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `shellSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(shellSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(shellSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`shellSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `shellSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [
@ -66,7 +66,7 @@ assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`shellSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `shellSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(shellSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(shellSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8012 id: 5a23c84252665b21eecc8012
title: Sorting algorithms/Stooge sort title: Algoritmi di Ordinamento/Stooge Sort
challengeType: 5 challengeType: 5
forumTopicId: 302318 forumTopicId: 302318
dashedName: sorting-algorithmsstooge-sort dashedName: sorting-algorithmsstooge-sort
@ -8,9 +8,9 @@ dashedName: sorting-algorithmsstooge-sort
# --description-- # --description--
Write a function to perform [Stooge Sort](https://en.wikipedia.org/wiki/Stooge sort) on an array of integers. The function should return a sorted array. Scrivi una funzione per eseguire lo [Stooge Sort](https://it.wikipedia.org/wiki/Trippel_sort) su un array di interi. La funzione dovrebbe restituire un array ordinato.
The Stooge Sort algorithm is as follows: L'algoritmo Stooge Sort è il seguente:
<pre><b>algorithm</b> stoogesort(<b>array</b> L, i = 0, j = <b>length</b>(L)-1) <pre><b>algorithm</b> stoogesort(<b>array</b> L, i = 0, j = <b>length</b>(L)-1)
<b>if</b> L[j] &#x3C; L[i] <b>then</b> <b>if</b> L[j] &#x3C; L[i] <b>then</b>
@ -25,37 +25,37 @@ The Stooge Sort algorithm is as follows:
# --hints-- # --hints--
`stoogeSort` should be a function. `stoogeSort` dovrebbe essere una funzione.
```js ```js
assert(typeof stoogeSort == 'function'); assert(typeof stoogeSort == 'function');
``` ```
`stoogeSort([25, 32, 12, 7, 20])` should return an array. `stoogeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(stoogeSort([25, 32, 12, 7, 20]))); assert(Array.isArray(stoogeSort([25, 32, 12, 7, 20])));
``` ```
`stoogeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `stoogeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(stoogeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(stoogeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`stoogeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `stoogeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(stoogeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(stoogeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`stoogeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `stoogeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(stoogeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(stoogeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`stoogeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `stoogeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [
@ -69,7 +69,7 @@ assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`stoogeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `stoogeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(stoogeSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(stoogeSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -1,6 +1,6 @@
--- ---
id: 5a23c84252665b21eecc8013 id: 5a23c84252665b21eecc8013
title: Sorting algorithms/Strand sort title: Algoritmi di ordinamento/Strand sort
challengeType: 5 challengeType: 5
forumTopicId: 302319 forumTopicId: 302319
dashedName: sorting-algorithmsstrand-sort dashedName: sorting-algorithmsstrand-sort
@ -8,43 +8,43 @@ dashedName: sorting-algorithmsstrand-sort
# --description-- # --description--
Write a function to sort an array using the [Strand sort](https://en.wikipedia.org/wiki/Strand sort). The function should return the sorted array. Scrivi una funzione per ordinare un array usando l'ordinamento [Strand sort](https://en.wikipedia.org/wiki/Strand sort). La funzione dovrebbe restituire l'array ordinato.
This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list. Questo è un modo di ordinare i numeri estraendo sequenze più brevi di numeri già ordinati da un elenco non ordinato.
# --hints-- # --hints--
`strandSort` should be a function. `strandSort` dovrebbe essere una funzione.
```js ```js
assert(typeof strandSort == 'function'); assert(typeof strandSort == 'function');
``` ```
`strandSort([25, 32, 12, 7, 20])` should return an array. `strandSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
```js ```js
assert(Array.isArray(strandSort([25, 32, 12, 7, 20]))); assert(Array.isArray(strandSort([25, 32, 12, 7, 20])));
``` ```
`strandSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`. `strandSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
```js ```js
assert.deepEqual(strandSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]); assert.deepEqual(strandSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
``` ```
`strandSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`. `strandSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
```js ```js
assert.deepEqual(strandSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]); assert.deepEqual(strandSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
``` ```
`strandSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`. `strandSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
```js ```js
assert.deepEqual(strandSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]); assert.deepEqual(strandSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
``` ```
`strandSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`. `strandSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
```js ```js
assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [ assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [
@ -58,7 +58,7 @@ assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [
]); ]);
``` ```
`strandSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`. `strandSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
```js ```js
assert.deepEqual(strandSort([3, 39, 48, 16, 1, 4, 29]), [ assert.deepEqual(strandSort([3, 39, 48, 16, 1, 4, 29]), [

View File

@ -8,86 +8,86 @@ dashedName: soundex
# --description-- # --description--
Soundex is an algorithm for creating indices for words based on their pronunciation. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling (from [the WP article](https://en.wikipedia.org/wiki/soundex)). There is a major issue in many of the implementations concerning the separation of two consonants that have the same soundex code! According to the [official Rules](https://www.archives.gov/research/census/soundex.html). So check for instance if **Ashcraft** is coded to **A-261**. Soundex è un algoritmo per creare indici per le parole basato sulla loro pronuncia. L'obbiettivo è avere gli omofoni codificati alla stessa rappresentazione così che possano essere combaciati nonostante piccole differenze di ortografia (dall'[articolo di Wikipedia](https://en.wikipedia.org/wiki/soundex)). C'è un problema importante in molte delle implementazioni riguardanti la separazione di due consonanti che hanno lo stesso codice soundex! In accordo con le [regole ufficiali](https://www.archives.gov/research/census/soundex.html). Quindi controlla se per esempio **Ashcraft** è codificato a **A-261**.
<ul> <ul>
<li>If a vowel (A, E, I, O, U) separates two consonants that have the same soundex code, the consonant to the right of the vowel is coded. Tymczak is coded as T-522 (T, 5 for the M, 2 for the C, Z ignored (see "Side-by-Side" rule above), 2 for the K). Since the vowel "A" separates the Z and K, the K is coded.</li> <li>Se una vocale (A, E, I, O, U) separata due consonanti che hanno lo stesso codice soundex, la consonante a destra della vocale è codificata. Tymczak è codificato come T-522 (T, 5 per M, 2 per C, Z ignorata (vedi regola "Fianco-a-fianco" qua sopra), 2 per K). Visto che la "A" separa la Z e la K, la K è codificata.</li>
<li>If "H" or "W" separate two consonants that have the same soundex code, the consonant to the right of the vowel is not coded. Example: Ashcraft is coded A-261 (A, 2 for the S, C ignored, 6 for the R, 1 for the F). It is not coded A-226.</li> <li>Se "H" o "W" separano due consonanti che hanno lo stesso codice soundex, la consonante alla destra della vocale non è codificata. Per esempio: Ashcraft è codificato come A-261 (A, 2 per S, C ignorata, 6 per R, 1 per F). Non è codificata come A-226.</li>
</ul> </ul>
# --instructions-- # --instructions--
Write a function that takes a string as a parameter and returns the encoded string. Scrivi una funzione che prende una stringa come parametro e restituisce la stringa codificata.
# --hints-- # --hints--
`soundex` should be a function. `soundex` dovrebbe essere una funzione.
```js ```js
assert(typeof soundex == 'function'); assert(typeof soundex == 'function');
``` ```
`soundex("Soundex")` should return a string. `soundex("Soundex")` dovrebbe restituire una stringa.
```js ```js
assert(typeof soundex('Soundex') == 'string'); assert(typeof soundex('Soundex') == 'string');
``` ```
`soundex("Soundex")` should return `"S532"`. `soundex("Soundex")` dovrebbe restituire `"S532"`.
```js ```js
assert.equal(soundex('Soundex'), 'S532'); assert.equal(soundex('Soundex'), 'S532');
``` ```
`soundex("Example")` should return `"E251"`. `soundex("Example")` dovrebbe restituire `"E251"`.
```js ```js
assert.equal(soundex('Example'), 'E251'); assert.equal(soundex('Example'), 'E251');
``` ```
`soundex("Sownteks")` should return `"S532"`. `soundex("Sownteks")` dovrebbe restituire `"S532"`.
```js ```js
assert.equal(soundex('Sownteks'), 'S532'); assert.equal(soundex('Sownteks'), 'S532');
``` ```
`soundex("Ekzampul")` should return `"E251"`. `soundex("Ekzampul")` dovrebbe restituire `"E251"`.
```js ```js
assert.equal(soundex('Ekzampul'), 'E251'); assert.equal(soundex('Ekzampul'), 'E251');
``` ```
`soundex("Euler")` should return `"E460"`. `soundex("Euler")` dovrebbe restituire `"E460"`.
```js ```js
assert.equal(soundex('Euler'), 'E460'); assert.equal(soundex('Euler'), 'E460');
``` ```
`soundex("Gauss")` should return `"G200"`. `soundex("Gauss")` dovrebbe restituire `"G200"`.
```js ```js
assert.equal(soundex('Gauss'), 'G200'); assert.equal(soundex('Gauss'), 'G200');
``` ```
`soundex("Hilbert")` should return `"H416"`. `soundex("Hilbert")` dovrebbe restituire `"H416"`.
```js ```js
assert.equal(soundex('Hilbert'), 'H416'); assert.equal(soundex('Hilbert'), 'H416');
``` ```
`soundex("Knuth")` should return `"K530"`. `soundex("Knuth")` dovrebbe restituire `"K530"`.
```js ```js
assert.equal(soundex('Knuth'), 'K530'); assert.equal(soundex('Knuth'), 'K530');
``` ```
`soundex("Lloyd")` should return `"L300"`. `soundex("Lloyd")` dovrebbe restituire `"L300"`.
```js ```js
assert.equal(soundex('Lloyd'), 'L300'); assert.equal(soundex('Lloyd'), 'L300');
``` ```
`soundex("Lukasiewicz")` should return `"L222"`. `soundex("Lukasiewicz")` dovrebbe restituire `"L222"`.
```js ```js
assert.equal(soundex('Lukasiewicz'), 'L222'); assert.equal(soundex('Lukasiewicz'), 'L222');

Some files were not shown because too many files have changed in this diff Show More