chore(i18n,learn): processed translations (#45151)
This commit is contained in:
@ -23,7 +23,7 @@ myTest();
|
||||
console.log(loc);
|
||||
```
|
||||
|
||||
La llamada a la función `myTest()` mostrará la cadena `foo` en la consola. La línea `console.log(loc)` arrojará un error, ya que `loc` no está definida fuera de la función.
|
||||
La llamada a la función `myTest()` mostrará la cadena `foo` en la consola. La línea `console.log(loc)` (fuera de la función `myTest`) lanzará un error, ya que `loc` no está definido fuera de la función.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -60,6 +60,12 @@ assert.isUndefined(addTogether(2, '3'));
|
||||
assert.isUndefined(addTogether(2)([3]));
|
||||
```
|
||||
|
||||
`addTogether("2", 3)` debe devolver `undefined`.
|
||||
|
||||
```js
|
||||
assert.isUndefined(addTogether('2', 3));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
@ -45,6 +45,18 @@ assert.deepEqual(uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`uniteUnique([1, 3, 2], [5, 4], [5, 6])` debe devolver `[1, 3, 2, 5, 4, 6]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(uniteUnique([1, 3, 2], [5, 4], [5, 6]), [1, 3, 2, 5, 4, 6]);
|
||||
```
|
||||
|
||||
`uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1])` debe devolver `[1, 3, 2, 5, 4]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1]), [1, 3, 2, 5, 4]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
@ -62,7 +74,11 @@ uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
|
||||
```js
|
||||
function uniteUnique(arr) {
|
||||
return [].slice.call(arguments).reduce(function(a, b) {
|
||||
return [].concat(a, b.filter(function(e) {return a.indexOf(e) === -1;}));
|
||||
return [].concat(
|
||||
a,
|
||||
b.filter(function(e, currentIndex) {
|
||||
return b.indexOf(e) === currentIndex && a.indexOf(e) === -1;
|
||||
}));
|
||||
}, []);
|
||||
}
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59637c4d89f6786115efd814
|
||||
title: Hofstadter Q sequence
|
||||
title: Successione Q di Hofstadter
|
||||
challengeType: 5
|
||||
forumTopicId: 302287
|
||||
dashedName: hofstadter-q-sequence
|
||||
@ -8,49 +8,49 @@ dashedName: hofstadter-q-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The [Hofstadter Q sequence](https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Q_sequence "wp: Hofstadter_sequence#Hofstadter_Q_sequence") is defined as:
|
||||
La [successione Q di Hofstadter](https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Q_sequence "wp: Hofstadter_sequence#Hofstadter_Q_sequence") è definita come:
|
||||
|
||||
$Q(1)=Q(2)=1, \\\\ Q(n)=Q\\big(n-Q(n-1)\\big)+Q\\big(n-Q(n-2)), \\quad n>2.$
|
||||
|
||||
It is defined like the [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence"), but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
|
||||
È definita come la [successione di Fibonacci](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence"), ma mentre il termine successivo nella successione di Fibonacci è la somma dei due termini precedenti, nella successione Q i due termini precedenti ti dicono fino a che punto tornare nella sequenza Q per trovare i due numeri da sommare per generare il prossimo termine della successione.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement the Hofstadter Q Sequence equation as a function. The function should accept number, `n`, and return an integer.
|
||||
Implementa l'equazione della Sequenza Q di Hofstadter come funzione. La funzione dovrebbe accettare un numero, `n`, e restituire un numero intero.
|
||||
|
||||
# --hints--
|
||||
|
||||
`hofstadterQ` should be a function.
|
||||
`hofstadterQ` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof hofstadterQ === 'function');
|
||||
```
|
||||
|
||||
`hofstadterQ()` should return `integer`
|
||||
`hofstadterQ()` dovrebbe restituire `integer`
|
||||
|
||||
```js
|
||||
assert(Number.isInteger(hofstadterQ(1000)));
|
||||
```
|
||||
|
||||
`hofstadterQ(1000)` should return `502`
|
||||
`hofstadterQ(1000)` dovrebbe restituire `502`
|
||||
|
||||
```js
|
||||
assert.equal(hofstadterQ(testCase[0]), res[0]);
|
||||
```
|
||||
|
||||
`hofstadterQ(1500)` should return `755`
|
||||
`hofstadterQ(1500)` dovrebbe restituire `755`
|
||||
|
||||
```js
|
||||
assert.equal(hofstadterQ(testCase[1]), res[1]);
|
||||
```
|
||||
|
||||
`hofstadterQ(2000)` should return `1005`
|
||||
`hofstadterQ(2000)` dovrebbe restituire `1005`
|
||||
|
||||
```js
|
||||
assert.equal(hofstadterQ(testCase[2]), res[2]);
|
||||
```
|
||||
|
||||
`hofstadterQ(2500)` should return `1261`
|
||||
`hofstadterQ(2500)` dovrebbe restituire `1261`
|
||||
|
||||
```js
|
||||
assert.equal(hofstadterQ(testCase[3]), res[3]);
|
||||
|
@ -47,7 +47,7 @@ assert(typeof IBeforeExceptC('receive') == 'boolean');
|
||||
assert.equal(IBeforeExceptC('receive'), true);
|
||||
```
|
||||
|
||||
`IBeforeExceptC("receive")` dovrebbe restituire `false`.
|
||||
`IBeforeExceptC("science")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(IBeforeExceptC('science'), false);
|
||||
|
@ -8,61 +8,61 @@ dashedName: iban
|
||||
|
||||
# --description--
|
||||
|
||||
The [International Bank Account Number (IBAN)](https://en.wikipedia.org/wiki/International_Bank_Account_Number) is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating [transcription errors](https://en.wikipedia.org/wiki/Transcription_error).
|
||||
Il numero internazione del conto bancario ([International Bank Account Number IBAN)](https://en.wikipedia.org/wiki/International_Bank_Account_Number) è un modo per identificare internazionalmente i conti bancari con un rischio ridotto di propagare [errori di trascrizione](https://en.wikipedia.org/wiki/Transcription_error).
|
||||
|
||||
The IBAN consists of up to 34 alphanumeric characters:
|
||||
L’IBAN è costituito da un massimo di 34 caratteri alfanumerici:
|
||||
|
||||
<ul>
|
||||
<li>first the two-letter ISO 3166-1 alpha-2 country code</li>
|
||||
<li>then two check digits, and</li>
|
||||
<li>finally a country-specific Basic Bank Account Number (BBAN).</li>
|
||||
<li>inizia con il codice paese a due lettere ISO 3166-1 alpha-2</li>
|
||||
<li>poi due cifre di controllo, e</li>
|
||||
<li>infine un numero di conto bancario di base specifico per paese (BBAN).</li>
|
||||
</ul>
|
||||
|
||||
The check digits enable a sanity check of the bank account number to confirm its integrity even before submitting a transaction.
|
||||
Le cifre di controllo consentono un controllo di sanità del numero di conto bancario per confermare la sua integrità anche prima di inviare una transazione.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes IBAN string as parameter. If it is valid return true. Otherwise, return false.
|
||||
Scrivi una funzione che prende come parametro la stringa IBAN. Se è valido restituisci true. Altrimenti, restituisci false.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isValid` should be a function.
|
||||
`isValid` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isValid == 'function');
|
||||
```
|
||||
|
||||
`isValid("GB82 WEST 1234 5698 7654 32")` should return a boolean.
|
||||
`isValid("GB82 WEST 1234 5698 7654 32")` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isValid('GB82 WEST 1234 5698 7654 32') == 'boolean');
|
||||
```
|
||||
|
||||
`isValid("GB82 WEST 1234 5698 7654 32")` should return `true`.
|
||||
`isValid("GB82 WEST 1234 5698 7654 32")` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isValid('GB82 WEST 1234 5698 7654 32'), true);
|
||||
```
|
||||
|
||||
`isValid("GB82 WEST 1.34 5698 7654 32")` should return `false`.
|
||||
`isValid("GB82 WEST 1.34 5698 7654 32")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isValid('GB82 WEST 1.34 5698 7654 32'), false);
|
||||
```
|
||||
|
||||
`isValid("GB82 WEST 1234 5698 7654 325")` should return `false`.
|
||||
`isValid("GB82 WEST 1234 5698 7654 325")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isValid('GB82 WEST 1234 5698 7654 325'), false);
|
||||
```
|
||||
|
||||
`isValid("GB82 TEST 1234 5698 7654 32")` should return `false`.
|
||||
`isValid("GB82 TEST 1234 5698 7654 32")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isValid('GB82 TEST 1234 5698 7654 32'), false);
|
||||
```
|
||||
|
||||
`isValid("SA03 8000 0000 6080 1016 7519")` should return `true`.
|
||||
`isValid("SA03 8000 0000 6080 1016 7519")` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isValid('SA03 8000 0000 6080 1016 7519'), true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7eb1
|
||||
title: Identity matrix
|
||||
title: Matrice identità
|
||||
challengeType: 5
|
||||
forumTopicId: 302290
|
||||
dashedName: identity-matrix
|
||||
@ -8,7 +8,7 @@ dashedName: identity-matrix
|
||||
|
||||
# --description--
|
||||
|
||||
An *identity matrix* is a square matrix of size \\( n \\times n \\), where the diagonal elements are all `1`s (ones), and all the other elements are all `0`s (zeroes).
|
||||
Una *matrice identità* è una matrice quadrata di dimensione \\( n \\times n \\), dove gli elementi sulla diagionale sono tutti `1` (uno), e tutti gli altri elementi sono `0` (zero).
|
||||
|
||||
<ul>
|
||||
<li style='list-style: none;'>\(\displaystyle I_{n}=\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}\)</li>
|
||||
@ -16,41 +16,41 @@ An *identity matrix* is a square matrix of size \\( n \\times n \\), where the d
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a number `n` as a parameter and returns the identity matrix of order \\( n \\times n \\).
|
||||
Scrivi una funzione che prende un numero `n` come paramentro e restituisce la matrice identità di ordine \\( n \\times n \\).
|
||||
|
||||
# --hints--
|
||||
|
||||
`idMatrix` should be a function.
|
||||
`idMatrix` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof idMatrix == 'function');
|
||||
```
|
||||
|
||||
`idMatrix(1)` should return an array.
|
||||
`idMatrix(1)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(idMatrix(1)));
|
||||
```
|
||||
|
||||
`idMatrix(1)` should return `[ [ 1 ] ]`.
|
||||
`idMatrix(1)` dovrebbe restituire `[ [ 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(1), results[0]);
|
||||
```
|
||||
|
||||
`idMatrix(2)` should return `[ [ 1, 0 ], [ 0, 1 ] ]`.
|
||||
`idMatrix(2)` dovrebbe restituire `[ [ 1, 0 ], [ 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(2), results[1]);
|
||||
```
|
||||
|
||||
`idMatrix(3)` should return `[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]`.
|
||||
`idMatrix(3)` dovrebbe restituire `[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(3), results[2]);
|
||||
```
|
||||
|
||||
`idMatrix(4)` should return `[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]`.
|
||||
`idMatrix(4)` dovrebbe restituire `[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(4), results[3]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ec1
|
||||
title: Iterated digits squaring
|
||||
title: Quadratura di cifre iterata
|
||||
challengeType: 5
|
||||
forumTopicId: 302291
|
||||
dashedName: iterated-digits-squaring
|
||||
@ -8,7 +8,7 @@ dashedName: iterated-digits-squaring
|
||||
|
||||
# --description--
|
||||
|
||||
If you add the square of the digits of a Natural number (an integer bigger than zero), you always end with either 1 or 89:
|
||||
Se sommi il quadrato delle cifre di un numero naturale (un numero intero più grande di zero), ottieni sempre o 1 o 89:
|
||||
|
||||
<pre>15 -> 26 -> 40 -> 16 -> 37 -> 58 -> 89
|
||||
7 -> 49 -> 97 -> 130 -> 10 -> 1
|
||||
@ -16,53 +16,53 @@ If you add the square of the digits of a Natural number (an integer bigger than
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a number as a parameter and returns 1 or 89 after performing the mentioned process.
|
||||
Scrivi una funzione che prende un numero come parametro e restituisce 1 o 89 dopo aver eseguito il processo menzionato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`iteratedSquare` should be a function.
|
||||
`iteratedSquare` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof iteratedSquare == 'function');
|
||||
```
|
||||
|
||||
`iteratedSquare(4)` should return a number.
|
||||
`iteratedSquare(4)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof iteratedSquare(4) == 'number');
|
||||
```
|
||||
|
||||
`iteratedSquare(4)` should return `89`.
|
||||
`iteratedSquare(4)` dovrebbe restituire `89`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(4), 89);
|
||||
```
|
||||
|
||||
`iteratedSquare(7)` should return `1`.
|
||||
`iteratedSquare(7)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(7), 1);
|
||||
```
|
||||
|
||||
`iteratedSquare(15)` should return `89`.
|
||||
`iteratedSquare(15)` dovrebbe restituire `89`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(15), 89);
|
||||
```
|
||||
|
||||
`iteratedSquare(20)` should return `89`.
|
||||
`iteratedSquare(20)` dovrebbe restituire `89`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(20), 89);
|
||||
```
|
||||
|
||||
`iteratedSquare(70)` should return `1`.
|
||||
`iteratedSquare(70)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(70), 1);
|
||||
```
|
||||
|
||||
`iteratedSquare(100)` should return `1`.
|
||||
`iteratedSquare(100)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(iteratedSquare(100), 1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ec2
|
||||
title: Jaro distance
|
||||
title: Distanza di Jaro
|
||||
challengeType: 5
|
||||
forumTopicId: 302292
|
||||
dashedName: jaro-distance
|
||||
@ -8,28 +8,28 @@ dashedName: jaro-distance
|
||||
|
||||
# --description--
|
||||
|
||||
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that `0` equates to no similarity and `1` is an exact match.
|
||||
La distanza di Jaro è una misura di similitudine tra due stringhe. Maggiore la distanza di Jaro per due stringhe, più simili sono. Il punteggio è normalizzato affinché `0` inidichi nessuna similarità e `1` che sono identiche.
|
||||
|
||||
**Definition**
|
||||
**Definizione**
|
||||
|
||||
The Jaro distance \\( d_j \\) of two given strings \\(s_1\\) and \\(s_2\\) is
|
||||
La distanza di Jaro \\( d_j \\) di due stringhe date \\(s_1\\) e \\(s_2\\) è
|
||||
|
||||
\\begin{align}d_j = \\begin{cases}0& & \\text{if }m=0 \\\\\\\\{\\frac {1}{3}}\\left({\\frac {m}{|s\_{1}|}}+{\\frac {m}{|s\_{2}|}}+{\\frac {m-t}{m}}\\right)& & \\text{otherwise}\\end{cases}\\end{align}
|
||||
|
||||
Where:
|
||||
Dove:
|
||||
|
||||
<ul>
|
||||
<li>\(m\) is the number of <i>matching characters</i>;</li>
|
||||
<li> \(t\) is half the number of <i>transpositions</i>.</li>
|
||||
<li>\(m\) è il numero di <i>caratteri combacianti</i>;</li>
|
||||
<li> \(t\) è metà del numero di <i>trasposizioni</i>.</li>
|
||||
</ul>
|
||||
|
||||
Two characters from \\(s_1\\) and \\(s_2\\) respectively, are considered *matching* only if they are the same and not farther than \\(\\left\\lfloor\\frac{\\max(|s_1|,|s_2|)}{2}\\right\\rfloor-1\\).
|
||||
Due caratteri da \\(s_1\\) e \\(s_2\\) rispettivamente, sono considerati *combacianti* solo se sono uguali e non più lontani di \\(\\left\\lfloor\\frac{\\max(|s_1|,|s_2|)}{2}\\right\\rfloor-1\\).
|
||||
|
||||
Each character of \\(s_1\\) is compared with all its matching characters in \\(s_2\\) . The number of matching (but different sequence order) characters divided by 2 defines the number of *transpositions*.
|
||||
Ogni carattere di \\(s_1\\) è comparato con tutti i caratteri combacianti in \\(s_2\\) . Il numero di caratteri combacianti (ma in differente ordine di sequenza) diviso 2 definisce il numero di *trasposizioni*.
|
||||
|
||||
**Example**
|
||||
**Esempio**
|
||||
|
||||
Given the strings \\(s_1\\) *DWAYNE* and \\(s_2\\) *DUANE* we find:
|
||||
Date le stringhe \\(s_1\\) *DWAYNE* e \\(s_2\\) *DUANE* troviamo:
|
||||
|
||||
<ul>
|
||||
<li>\(m = 4\)</li>
|
||||
@ -38,51 +38,51 @@ Given the strings \\(s_1\\) *DWAYNE* and \\(s_2\\) *DUANE* we find:
|
||||
<li>\(t = 0\)</li>
|
||||
</ul>
|
||||
|
||||
We find a Jaro score of: \\(d_j = \\frac{1}{3}\\left(\\frac{4}{6} + \\frac{4}{5} + \\frac{4-0}{4}\\right) = 0.822\\).
|
||||
Troviamo un punteggio Jaro di: \\(d_j = \\frac{1}{3}\\left(\\frac{4}{6} + \\frac{4}{5} + \\frac{4-0}{4}\\right) = 0.822\\).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function a that takes two strings as parameters and returns the associated Jaro distance.
|
||||
Scrivi una funzione che prende due stringhe come parametri e restituisce l'associata distanza di Jaro.
|
||||
|
||||
# --hints--
|
||||
|
||||
`jaro` should be a function.
|
||||
`jaro` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof jaro == 'function');
|
||||
```
|
||||
|
||||
`jaro("MARTHA", "MARHTA")` should return a number.
|
||||
`jaro("MARTHA", "MARHTA")` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof jaro('MARTHA', 'MARHTA') == 'number');
|
||||
```
|
||||
|
||||
`jaro("MARTHA", "MARHTA")` should return `0.9444444444444445`.
|
||||
`jaro("MARTHA", "MARHTA")` dovrebbe restituire `0.9444444444444445`.
|
||||
|
||||
```js
|
||||
assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445);
|
||||
```
|
||||
|
||||
`jaro("DIXON", "DICKSONX")` should return `0.7666666666666666`.
|
||||
`jaro("DIXON", "DICKSONX")` dovrebbe restituire `0.7666666666666666`.
|
||||
|
||||
```js
|
||||
assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666);
|
||||
```
|
||||
|
||||
`jaro("JELLYFISH", "SMELLYFISH")` should return `0.8962962962962964`.
|
||||
`jaro("JELLYFISH", "SMELLYFISH")` dovrebbe restituire `0.8962962962962964`.
|
||||
|
||||
```js
|
||||
assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964);
|
||||
```
|
||||
|
||||
`jaro("HELLOS", "CHELLO")` should return `0.888888888888889`.
|
||||
`jaro("HELLOS", "CHELLO")` dovrebbe restituire `0.888888888888889`.
|
||||
|
||||
```js
|
||||
assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889);
|
||||
```
|
||||
|
||||
`jaro("ABCD", "BCDA")` should return `0.8333333333333334`.
|
||||
`jaro("ABCD", "BCDA")` dovrebbe restituire `0.8333333333333334`.
|
||||
|
||||
```js
|
||||
assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334);
|
||||
|
@ -8,55 +8,55 @@ dashedName: jortsort
|
||||
|
||||
# --description--
|
||||
|
||||
jortSort is a sorting toolset that makes the user do the work and guarantees efficiency because you don't have to sort ever again. It was originally presented by Jenn "Moneydollars" Schiffer at the prestigious [JSConf](https://www.youtube.com/watch?v=pj4U_W0OFoE).
|
||||
jortSort è un set di strumenti di ordinamento che permette all'utente di fare il lavoro e garantisce l'efficienza perché non è necessario riordinare nuovamente. È stato originariamente presentato da Jenn "Moneydollars" Schiffer al prestigioso [JSConf](https://www.youtube.com/watch?v=pj4U_W0OFoE).
|
||||
|
||||
jortSort should be a function that takes a single array of comparable objects as its argument. It then sorts the array in ascending order and compares the sorted array to the originally provided array. If the arrays match (i.e. the original array was already sorted), the function returns true. If the arrays do not match (i.e. the original array was not sorted), the function returns false.
|
||||
jortSort dovrebbe essere una funzione che prende un singolo array di oggetti comparabili come argomento. Esso ordina l'array in ordine crescente e confronta l'array ordinato con l'array originariamente fornito. Se gli array corrispondono (cioè l'array originale è già stato ordinato), la funzione restituisce true. Se gli array non corrispondono (cioè l'array originale non è stato ordinato), la funzione restituisce false.
|
||||
|
||||
# --hints--
|
||||
|
||||
`jortsort` should be a function.
|
||||
`jortsort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof jortsort == 'function');
|
||||
```
|
||||
|
||||
`jortsort([1,2,3,4,5])` should return a boolean.
|
||||
`jortsort([1,2,3,4,5])` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof jortsort([1, 2, 3, 4, 5]) == 'boolean');
|
||||
```
|
||||
|
||||
`jortsort([1,2,3,4,5])` should return `true`.
|
||||
`jortsort([1,2,3,4,5])` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([1, 2, 3, 4, 5]), true);
|
||||
```
|
||||
|
||||
`jortsort([1,2,13,4,5])` should return `false`.
|
||||
`jortsort([1,2,13,4,5])` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([1, 2, 13, 4, 5]), false);
|
||||
```
|
||||
|
||||
`jortsort([12,4,51,2,4])` should return `false`.
|
||||
`jortsort([12,4,51,2,4])` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([12, 4, 51, 2, 4]), false);
|
||||
```
|
||||
|
||||
`jortsort([1,2])` should return `true`.
|
||||
`jortsort([1,2])` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([1, 2]), true);
|
||||
```
|
||||
|
||||
`jortsort([5,4,3,2,1])` should return `false`.
|
||||
`jortsort([5,4,3,2,1])` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([5, 4, 3, 2, 1]), false);
|
||||
```
|
||||
|
||||
`jortsort([1,1,1,1,1])` should return `true`.
|
||||
`jortsort([1,1,1,1,1])` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(jortsort([1, 1, 1, 1, 1]), true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ec5
|
||||
title: Josephus problem
|
||||
title: Problema di Josephus
|
||||
challengeType: 5
|
||||
forumTopicId: 302294
|
||||
dashedName: josephus-problem
|
||||
@ -8,65 +8,65 @@ dashedName: josephus-problem
|
||||
|
||||
# --description--
|
||||
|
||||
[Josephus problem](https://en.wikipedia.org/wiki/Josephus problem) is a math puzzle with a grim description: $n$ prisoners are standing on a circle, sequentially numbered from $0$ to $n-1$.
|
||||
[Il problema di Josephus](https://en.wikipedia.org/wiki/Josephus problem) è un puzzle matematico con una descrizione truce: $n$ prigionieri sono in piedi su un cerchio, numerato in sequenza da $0$ a $n-1$.
|
||||
|
||||
An executioner walks along the circle, starting from prisoner $0$, removing every $k$-th prisoner and killing him.
|
||||
Un boia cammina lungo il cerchio, iniziando dal prigioniero $0$, rimuovendo ogni $k$-mo prigioniero e uccidendolo.
|
||||
|
||||
As the process goes on, the circle becomes smaller and smaller, until only one prisoner remains, who is then freed.
|
||||
Mentre il processo continua, il cerchio diventa più piccolo, fino a quando rimane solo un prigioniero, che poi viene liberato.
|
||||
|
||||
For example, if there are $n=5$ prisoners and $k=2$, the order the prisoners are killed in (let's call it the "killing sequence") will be 1, 3, 0, and 4, and the survivor will be #2.
|
||||
Ad esempio, se ci sono $n=5$ prigionieri e $k=2$, l'ordine in cui i prigionieri vengono uccisi (chiamiamolo la "sequenza di uccisione") sarà 1, 3, 0 e 4, e il sopravvissuto sarà il numero 2.
|
||||
|
||||
Given any $n, k > 0$, find out which prisoner will be the final survivor.
|
||||
Dato qualsiasi $n, k > 0$, scopri quale prigioniero sarà il sopravvissuto finale.
|
||||
|
||||
In one such incident, there were 41 prisoners and every 3<sup>rd</sup> prisoner was being killed ($k=3$).
|
||||
In una di queste situazioni, ci furono 41 prigionieri e ogni 3<sup>°</sup> prigioniero fu ucciso ($k= 3 $).
|
||||
|
||||
Among them was a clever chap name Josephus who worked out the problem, stood at the surviving position, and lived on to tell the tale.
|
||||
Tra di loro c'era una persona intelligente di nome Josephus che elaborò il problema, si trovava in posizione di sopravvivenza, e ha vissuto per raccontare la storia.
|
||||
|
||||
Which number was he?
|
||||
A che numero corrisponde lui?
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes the initial number of prisoners and 'k' as parameter and returns the number of the prisoner that survives.
|
||||
Scrvi una funzione che prende il numero iniziale dei prigionieri e 'k' come parametro e ritorna il numero del prigioniero che è sopravvissuto.
|
||||
|
||||
# --hints--
|
||||
|
||||
`josephus` should be a function.
|
||||
`josephus` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof josephus == 'function');
|
||||
```
|
||||
|
||||
`josephus(30,3)` should return a number.
|
||||
`josephus(30,3)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof josephus(30, 3) == 'number');
|
||||
```
|
||||
|
||||
`josephus(30,3)` should return `28`.
|
||||
`josephus(30,3)` dovrebbe restituire `28`.
|
||||
|
||||
```js
|
||||
assert.equal(josephus(30, 3), 28);
|
||||
```
|
||||
|
||||
`josephus(30,5)` should return `2`.
|
||||
`josephus(30,5)` dovrebbe restituire `2`.
|
||||
|
||||
```js
|
||||
assert.equal(josephus(30, 5), 2);
|
||||
```
|
||||
|
||||
`josephus(20,2)` should return `8`.
|
||||
`josephus(20,2)` dovrebbe restituire `8`.
|
||||
|
||||
```js
|
||||
assert.equal(josephus(20, 2), 8);
|
||||
```
|
||||
|
||||
`josephus(17,6)` should return `1`.
|
||||
`josephus(17,6)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(josephus(17, 6), 1);
|
||||
```
|
||||
|
||||
`josephus(29,4)` should return `1`.
|
||||
`josephus(29,4)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(josephus(29, 4), 1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ecb
|
||||
title: K-d tree
|
||||
title: Albero K-d
|
||||
challengeType: 5
|
||||
forumTopicId: 302295
|
||||
dashedName: k-d-tree
|
||||
@ -8,21 +8,21 @@ dashedName: k-d-tree
|
||||
|
||||
# --description--
|
||||
|
||||
A k-d tree (short for *k*-dimensional tree) is a space-partitioning data structure for organizing points in a k-dimensional space. k-d trees are a useful data structure for several applications, such as searches involving a multidimensional search key (e.g. range searches and nearest neighbor searches). k-d trees are a special case of binary space partitioning trees. k-d trees are not suitable, however, for efficiently finding the nearest neighbor in high dimensional spaces. As a general rule, if the dimensionality is *k*, the number of points in the data, *N*, should be *N* ≫ 2<sup><i>k</i></sup>. Otherwise, when k-d trees are used with high-dimensional data, most of the points in the tree will be evaluated and the efficiency is no better than exhaustive search, and other methods such as approximate nearest-neighbor are used instead.
|
||||
Un albero k-d (abbreviazione per *k*-dimensional tree) è una struttura dati di partizionamento spaziale per organizzare i punti in uno spazio k-dimensionale. Gli alberi k-d sono una struttura di dati utile per diverse applicazioni, come le ricerche che comportano una chiave di ricerca multidimensionale (ad esempio ricerche di intervallo e ricerche del vicino più prossimo). Gli alberi k-d sono un caso speciale di alberi binari di partizionamento spaziale. Gli alberi k-d non sono adatti, tuttavia, per trovare in modo efficiente il vicino più prossimo in spazi ad alta dimensione. Come regola generale, se la dimensionalità è *k*, il numero di punti nei dati, *N*, dovrebbe essere *N* ≫ 2<sup><i>k</i></sup>. Altrimenti, quando gli alberi k-d sono utilizzati con dati ad alta dimensione, la maggior parte dei punti dell'albero sarà valutata e l'efficienza non sarà migliore di una ricerca esaustiva, e vengono utilizzati invece altri metodi come quello del vicino più prossimo approssimato.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to perform a nearest neighbour search using k-d tree. The function takes two parameters: an array of k-dimensional points, and a single k-dimensional point whose nearest neighbour should be returned by the function. A k-dimensional point will be given as an array of k elements.
|
||||
Scrivi una funzione per eseguire una ricerca del vicino più prossimo usando un albero k-d. La funzione accetta due parametri: un array di punti k-dimensionali, e un singolo punto k-dimensionale di cui la funzione dovrebbe restituire il punto più vicino. Un punto k-dimensionale sarà dato come un array di k elementi.
|
||||
|
||||
# --hints--
|
||||
|
||||
`kdNN` should be a function.
|
||||
`kdNN` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof kdNN == 'function');
|
||||
```
|
||||
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [9, 2])` should return an array.
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [9, 2])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -42,7 +42,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [9, 2])` should return `[ 8, 1 ]`.
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [9, 2])` dovrebbe restituire `[ 8, 1 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -61,7 +61,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [7, 1])` should return `[ 8, 1 ]`.
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [7, 1])` dovrebbe restituire `[ 8, 1 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -80,7 +80,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [3, 2])` should return `[ 2, 3 ]`.
|
||||
`kdNN([[[2, 3], [5, 4], [9, 6], [4, 7], [8, 1], [7, 2]], [3, 2])` dovrebbe restituire `[ 2, 3 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -99,7 +99,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [1, 2, 3])` should return `[ 1, 2, 5 ]`.
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [1, 2, 3])` dovrebbe restituire `[ 1, 2, 5 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -118,7 +118,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [4, 5, 6])` should return `[ 4, 6, 7 ]`.
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [4, 5, 6])` dovrebbe restituire `[ 4, 6, 7 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -137,7 +137,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [8, 8, 8])` should return `[ 7, 8, 9 ]`.
|
||||
`kdNN([[2, 3, 1], [9, 4, 5], [4, 6, 7], [1, 2, 5], [7, 8, 9], [3, 6, 1]], [8, 8, 8])` dovrebbe restituire `[ 7, 8, 9 ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7eca
|
||||
title: Kaprekar numbers
|
||||
title: Numeri di Kaprekar
|
||||
challengeType: 5
|
||||
forumTopicId: 302296
|
||||
dashedName: kaprekar-numbers
|
||||
@ -8,77 +8,77 @@ dashedName: kaprekar-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A positive integer is a [Kaprekar number](https://en.wikipedia.org/wiki/Kaprekar number) if:
|
||||
Un numero intero positivo è un [numero di Kaprekar](https://en.wikipedia.org/wiki/Kaprekar number) se:
|
||||
|
||||
<ul>
|
||||
<li>It is 1, or,</li>
|
||||
<li>The decimal representation of its square may be split once into two parts consisting of positive integers which sum to the original number. </li>
|
||||
<li>È 1 o,</li>
|
||||
<li>La rappresentazione decimale del suo quadrato può essere suddivisa una volta in due parti costituite da interi positivi che sommano al numero originale. </li>
|
||||
</ul>
|
||||
|
||||
Note that a split resulting in a part consisting purely of 0s is not valid, as 0 is not considered positive.Example
|
||||
Si noti che una scissione risultante in una parte costituita esclusivamente da 0 non è valida, in quanto 0 non è considerato positivo.
|
||||
|
||||
Kaprekar numbers:
|
||||
Esempi di numeri di Kaprekar:
|
||||
|
||||
<ul>
|
||||
<li><code>2223</code> is a Kaprekar number, as <code>2223 * 2223 = 4941729</code>, <code>4941729</code> may be split to <code>494</code> and <code>1729</code>, and <code>494 + 1729 = 2223</code></li>
|
||||
<li>The series of Kaprekar numbers is known as <a href='https://oeis.org/A006886' target='_blank'>A006886</a>, and begins as <code>1, 9, 45, 55, ...</code></li>
|
||||
<li><code>2223</code> è un numero Kaprekar, poiché <code>2223 * 2223 = 4941729</code>, <code>4941729</code> può essere suddiviso in <code>494</code> e <code>1729</code>and <code>494 + 1729 = 2223</code></li>
|
||||
<li>La serie di numeri Kaprekar è conosciuta come <a href='https://oeis.org/A006886' target='_blank'>A006886</a> e inizia con <code>1, 9, 45, 55, ...</code></li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a number $n$, a base $bs$, and returns true if the number is a Kaprekar number for the given base. Otherwise, the function returns false.
|
||||
Scrivi una funzione che prende un numero $n$, una base $bs$, e restituisce vero se il numero è un numero di Kaprekar per la base specificata. Altrimenti, la funzione restituisce falso.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isKaprekar` should be a function.
|
||||
`isKaprekar` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isKaprekar == 'function');
|
||||
```
|
||||
|
||||
`isKaprekar(1, 10)` should return a boolean.
|
||||
`isKaprekar(1, 10)` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isKaprekar(1, 10) == 'boolean');
|
||||
```
|
||||
|
||||
`isKaprekar(1, 10)` should return `true`.
|
||||
`isKaprekar(1, 10)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(1, 10), true);
|
||||
```
|
||||
|
||||
`isKaprekar(9, 10)` should return `true`.
|
||||
`isKaprekar(9, 10)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(9, 10), true);
|
||||
```
|
||||
|
||||
`isKaprekar(2223, 10)` should return `true`.
|
||||
`isKaprekar(2223, 10)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(2223, 10), true);
|
||||
```
|
||||
|
||||
`isKaprekar(22823, 10)` should return `false`.
|
||||
`isKaprekar(22823, 10)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(22823, 10), false);
|
||||
```
|
||||
|
||||
`isKaprekar(9, 17)` should return `false`.
|
||||
`isKaprekar(9, 17)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(9, 17), false);
|
||||
```
|
||||
|
||||
`isKaprekar(225, 17)` should return `true`.
|
||||
`isKaprekar(225, 17)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(225, 17), true);
|
||||
```
|
||||
|
||||
`isKaprekar(999, 17)` should return `false`.
|
||||
`isKaprekar(999, 17)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isKaprekar(999, 17), false);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ed1
|
||||
title: Knapsack problem/0-1
|
||||
title: Problema dello Zaino/0-1
|
||||
challengeType: 5
|
||||
forumTopicId: 323649
|
||||
dashedName: knapsack-problem0-1
|
||||
@ -8,17 +8,17 @@ dashedName: knapsack-problem0-1
|
||||
|
||||
# --description--
|
||||
|
||||
The 0-1 knapsack problem is defined as follows:
|
||||
Il problema dello zaino 0-1 è definito come segue:
|
||||
|
||||
You are given an array of objects representing items to be put in a knapsack. The objects have 3 attributes: name, weight, and value. The items need to be selected so that the total weight does not exceed the maximum weight and the value is maximized.
|
||||
Ti viene data una serie di oggetti che rappresentano cose da mettere in uno zaino. Gli oggetti hanno 3 attributi: nome, peso e valore. Gli articoli devono essere selezionati in modo che il peso totale non superi il peso massimo e il valore è massimizzato.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to solve the knapsack problem. The function is given the array of objects and the maximum weight as parameters. It should return the maximum total value possible.
|
||||
Scrivi una funzione per risolvere il problema dello zaino. Alla funzione viene dato l'array di oggetti e il peso massimo come parametri. Dovrebbe restituire il massimo valore totale possibile.
|
||||
|
||||
# --hints--
|
||||
|
||||
`knapsack([{ name:'map', weight:9, value:150 }, { name:'compass', weight:13, value:35 }, { name:'water', weight:153, value:200 }, { name:'sandwich', weight:50, value:160 }, { name:'glucose', weight:15, value:60 }, { name:'tin', weight:68, value:45 }, { name:'banana', weight:27, value:60 }, { name:'apple', weight:39, value:40 }], 100)` should return `405`.
|
||||
`knapsack([{ name:'map', weight:9, value:150 }, { name:'compass', weight:13, value:35 }, { name:'water', weight:153, value:200 }, { name:'sandwich', weight:50, value:160 }, { name:'glucose', weight:15, value:60 }, { name:'tin', weight:68, value:45 }, { name:'banana', weight:27, value:60 }, { name:'apple', weight:39, value:40 }], 100)` dovrebbe restituire `405`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -39,7 +39,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsack([{ name:'map', weight:9, value:150 }, { name:'compass', weight:13, value:35 }, { name:'water', weight:153, value:200 }, { name:'sandwich', weight:50, value:160 }, { name:'glucose', weight:15, value:60 }, { name:'tin', weight:68, value:45 }, { name:'banana', weight:27, value:60 }, { name:'apple', weight:39, value:40 }], 200)` should return `510`.
|
||||
`knapsack([{ name:'map', weight:9, value:150 }, { name:'compass', weight:13, value:35 }, { name:'water', weight:153, value:200 }, { name:'sandwich', weight:50, value:160 }, { name:'glucose', weight:15, value:60 }, { name:'tin', weight:68, value:45 }, { name:'banana', weight:27, value:60 }, { name:'apple', weight:39, value:40 }], 200)` dovrebbe restituire `510`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -60,7 +60,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsack([{ name:'cheese', weight:23, value:30 }, { name:'beer', weight:52, value:10 }, { name:'suntan cream', weight:11, value:70 }, { name:'camera', weight:32, value:30 }, { name:'T-shirt', weight:24, value:15 }, { name:'trousers', weight:48, value:10 }, { name:'umbrella', weight:73, value:40 }], 100)` should return `145`.
|
||||
`knapsack([{ name:'cheese', weight:23, value:30 }, { name:'beer', weight:52, value:10 }, { name:'suntan cream', weight:11, value:70 }, { name:'camera', weight:32, value:30 }, { name:'T-shirt', weight:24, value:15 }, { name:'trousers', weight:48, value:10 }, { name:'umbrella', weight:73, value:40 }], 100)` dovrebbe restituire `145`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -80,7 +80,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsack([{ name:'cheese', weight:23, value:30 }, { name:'beer', weight:52, value:10 }, { name:'suntan cream', weight:11, value:70 }, { name:'camera', weight:32, value:30 }, { name:'T-shirt', weight:24, value:15 }, { name:'trousers', weight:48, value:10 }, { name:'umbrella', weight:73, value:40 }], 200)` should return `185`.
|
||||
`knapsack([{ name:'cheese', weight:23, value:30 }, { name:'beer', weight:52, value:10 }, { name:'suntan cream', weight:11, value:70 }, { name:'camera', weight:32, value:30 }, { name:'T-shirt', weight:24, value:15 }, { name:'trousers', weight:48, value:10 }, { name:'umbrella', weight:73, value:40 }], 200)` dovrebbe restituire `185`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -100,7 +100,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsack([{ name:'waterproof trousers', weight:42, value:70 }, { name:'waterproof overclothes', weight:43, value:75 }, { name:'note-case', weight:22, value:80 }, { name:'sunglasses', weight:7, value:20 }, { name:'towel', weight:18, value:12 }, { name:'socks', weight:4, value:50 }, { name:'book', weight:30, value:10 }], 100)` should return `237`.
|
||||
`knapsack([{ name:'waterproof trousers', weight:42, value:70 }, { name:'waterproof overclothes', weight:43, value:75 }, { name:'note-case', weight:22, value:80 }, { name:'sunglasses', weight:7, value:20 }, { name:'towel', weight:18, value:12 }, { name:'socks', weight:4, value:50 }, { name:'book', weight:30, value:10 }], 100)` dovrebbe restituire `237`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -120,7 +120,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsack([{ name:'waterproof trousers', weight:42, value:70 }, { name:'waterproof overclothes', weight:43, value:75 }, { name:'note-case', weight:22, value:80 }, { name:'sunglasses', weight:7, value:20 }, { name:'towel', weight:18, value:12 }, { name:'socks', weight:4, value:50 }, { name:'book', weight:30, value:10 }], 200)` should return `317`.'
|
||||
`knapsack([{ name:'waterproof trousers', weight:42, value:70 }, { name:'waterproof overclothes', weight:43, value:75 }, { name:'note-case', weight:22, value:80 }, { name:'sunglasses', weight:7, value:20 }, { name:'towel', weight:18, value:12 }, { name:'socks', weight:4, value:50 }, { name:'book', weight:30, value:10 }], 200)` dovrebbe restituire `317`.'
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ed2
|
||||
title: Knapsack problem/Bounded
|
||||
title: Problema dello Zaino/Limitato
|
||||
challengeType: 5
|
||||
forumTopicId: 323652
|
||||
dashedName: knapsack-problembounded
|
||||
@ -8,17 +8,17 @@ dashedName: knapsack-problembounded
|
||||
|
||||
# --description--
|
||||
|
||||
The bounded knapsack problem is defined as follows:
|
||||
Il problema dello zaino limitato è definito come segue:
|
||||
|
||||
You are given an array of objects representing items to be put in a knapsack. The objects have 4 attributes: name, pieces (the number of the particular item), weight, and value. The items need to be selected so that the total weight does not exceed the maximum weight and the value is maximized. Keep in mind that each item can appear between 0 and `pieces` times.
|
||||
Ti viene data una serie di oggetti che rappresentano cose da mettere in uno zaino. Gli oggetti hanno 4 attributi: nome, pezzi (il numero di pezzi di quel particolare oggetto), peso e valore. Gli articoli devono essere selezionati in modo che il peso totale non superi il peso massimo e il valore è massimizzato. Tieni presente che ogni elemento può apparire un numero di volte tra 0 e `pieces`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to solve the knapsack problem. The function is given the array of objects and the maximum weight as parameters. It should return the maximum total value possible.
|
||||
Scrivi una funzione per risolvere il problema dello zaino. Alla funzione viene dato l'array di oggetti e il peso massimo come parametri. Dovrebbe restituire il massimo valore totale possibile.
|
||||
|
||||
# --hints--
|
||||
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 300)` should return `755`.
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 300)` dovrebbe restituire `755`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -44,7 +44,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 400)` should return `875`.
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 400)` dovrebbe restituire `875`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -70,7 +70,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 500)` should return `1015`.
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 500)` dovrebbe restituire `1015`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -96,7 +96,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 600)` should return `1120`.
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 600)` dovrebbe restituire `1120`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -122,7 +122,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 700)` should return `1225`.
|
||||
`findBestPack([{ name:'map', weight:9, value:150, pieces:1 }, { name:'compass', weight:13, value:35, pieces:1 }, { name:'water', weight:153, value:200, pieces:2 }, { name:'sandwich', weight:50, value:60, pieces:2 }, { name:'glucose', weight:15, value:60, pieces:2 }, { name:'tin', weight:68, value:45, pieces:3 }, { name:'banana', weight:27, value:60, pieces:3 }, { name:'apple', weight:39, value:40, pieces:3 }, { name:'cheese', weight:23, value:30, pieces:1 }, { name:'beer', weight:52, value:10, pieces:3 }, { name:'suntan, cream', weight:11, value:70, pieces:1 }, { name:'camera', weight:32, value:30, pieces:1 }, { name:'T-shirt', weight:24, value:15, pieces:2 }], 700)` dovrebbe restituire `1225`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ed3
|
||||
title: Knapsack problem/Continuous
|
||||
title: Problema di Knapsack/continuo
|
||||
challengeType: 5
|
||||
forumTopicId: 323654
|
||||
dashedName: knapsack-problemcontinuous
|
||||
@ -8,17 +8,17 @@ dashedName: knapsack-problemcontinuous
|
||||
|
||||
# --description--
|
||||
|
||||
A thief burgles a butcher's shop, where he can select from some items.
|
||||
Un ladro deruba il negozio di un macellaio, dove può scegliere tra alcuni prodotti.
|
||||
|
||||
The thief knows the weights and prices of each items. Because he has a knapsack with a limit on the maximum weight that it can carry, he wants to select the items such that he would have his profit maximized. He may cut the items; the item has a reduced price after cutting that is proportional to the original price by the ratio of masses. That means: half of an item has half the price of the original.
|
||||
Il ladro conosce i pesi e i prezzi di ogni articolo. Dato che ha un zaino con un limite di peso massimo che può trasportare, vuole selezionare gli elementi in modo tale da massimizzare il suo profitto. Può tagliare gli oggetti; l'articolo ha un prezzo ridotto dopo il taglio che è proporzionale al prezzo originale per il rapporto tra le masse. Ciò significa: la metà di un articolo ha metà del prezzo dell'originale.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of objects representing the items available in the shop. Each object has 3 attributes: name, weight, and value. The function also takes the maximum weight as a parameter. The function should return the maximum value possible, and the total weight of the selected items should not exceed the maximum weight.
|
||||
Scrivi una funzione che accetta una serie di oggetti che rappresentano i prodotti disponibili nel negozio. Ogni oggetto ha 3 attributi: nome, peso e valore. La funzione prende anche il peso massimo come parametro. La funzione dovrebbe restituire il valore massimo possibile e il peso totale degli elementi selezionati non dovrebbe superare il peso massimo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 10)` should return `257.875`.
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 10)` dovrebbe restituire `257.875`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -40,7 +40,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 12)` should return `295.05405405405406`.
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 12)` dovrebbe restituire `295.05405405405406`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -62,7 +62,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 15)` should return `349.3783783783784`.
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 15)` dovrebbe restituire `349.3783783783784`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -84,7 +84,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 22)` should return `459.5263157894737`.
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 22)` dovrebbe restituire `459.5263157894737`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -106,7 +106,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 24)` should return `478.4736842105263`.
|
||||
`knapContinuous([{ "weight":3.8, "value":36, name:"beef" }, { "weight":5.4, "value":43, name:"pork" }, { "weight":3.6, "value":90, name:"ham" }, { "weight":2.4, "value":45, name:"greaves" }, { "weight":4.0, "value":30, name:"flitch" }, { "weight":2.5, "value":56, name:"brawn" }, { "weight":3.7, "value":67, name:"welt" }, { "weight":3.0, "value":95, name:"salami" }, { "weight":5.9, "value":98, name:"sausage" }], 24)` dovrebbe restituire `478.4736842105263`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ed4
|
||||
title: Knapsack problem/Unbounded
|
||||
title: Problema dello Zaino/Non limitato
|
||||
challengeType: 5
|
||||
forumTopicId: 323655
|
||||
dashedName: knapsack-problemunbounded
|
||||
@ -8,21 +8,21 @@ dashedName: knapsack-problemunbounded
|
||||
|
||||
# --description--
|
||||
|
||||
A traveler gets diverted and has to make an unscheduled stop in what turns out to be Shangri-La. Opting to leave, he is allowed to take as much as he likes of the items available there, so long as it will fit in his knapsack, and he can carry it.
|
||||
Un viaggiatore viene deviato e deve fare una sosta non programmata in quello che risulta essere Shangri-La. Scegliendo di andarsene, gli è permesso prendere tutto ciò che vuole degli oggetti disponibili lì, fintanto che entrino nel suo zaino e riesca a portarlo.
|
||||
|
||||
He knows that he can carry no more than a particular value of maximum weight in total; and that the capacity of his knapsack has a limited volume.
|
||||
Sa che non può portare più di un particolare valore di peso massimo totale; e che la capacità del suo zaino ha un volume limitato.
|
||||
|
||||
Looking just above the bar codes on the items he finds their weights and volumes. He digs out his recent copy of a financial paper and gets the value of each item.
|
||||
Guardando appena sopra i codici a barre sugli articoli trova i loro pesi e volumi. Va a ripescare la sua recente copia di un documento finanziario e ottiene il valore di ogni voce.
|
||||
|
||||
He can only take whole units of any item, but there is much more of any item than he could ever carry.
|
||||
Può solo prendere unità intere di qualsiasi oggetto, ma c'è molto di più di qualsiasi oggetto che potrebbe mai trasportare.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of objects, maximum weight, and maximum volume as parameters. Each object has 4 attributes: name, value, weight, and volume. The function should return the maximum value of items the traveller can take with him.
|
||||
Scrivi una funzione che richiede una serie di oggetti, il peso massimo e il volume massimo come parametri. Ogni oggetto ha 4 attributi: nome, valore, peso e volume. La funzione dovrebbe restituire il valore massimo degli articoli che il viaggiatore può portare con sé.
|
||||
|
||||
# --hints--
|
||||
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 25, 0.25)` should return `54500`.
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 25, 0.25)` dovrebbe restituire `54500`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -39,7 +39,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 55, 0.25)` should return `88400`.
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 55, 0.25)` dovrebbe restituire `88400`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -56,7 +56,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 25, 0.15)` should return `42500`.
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 25, 0.15)` dovrebbe restituire `42500`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -73,7 +73,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 35, 0.35)` should return `75900`.
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 35, 0.35)` dovrebbe restituire `75900`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -90,7 +90,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 15, 0.25)` should return `43200`.
|
||||
`knapsackUnbounded([{ name:"panacea", value:3000, weight:0.3, volume:0.025 }, { name:"ichor", value:1800, weight:0.2, volume:0.015 }, { name:"gold", value:2500, weight:2, volume:0.002 }], 15, 0.25)` dovrebbe restituire `43200`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ed5
|
||||
title: Knight's tour
|
||||
title: Tour del cavallo
|
||||
challengeType: 5
|
||||
forumTopicId: 302297
|
||||
dashedName: knights-tour
|
||||
@ -8,51 +8,51 @@ dashedName: knights-tour
|
||||
|
||||
# --description--
|
||||
|
||||
[Knight's Tour](https://en.wikipedia.org/wiki/Knight%27s_tour) Problem: You have an empty `w` \* `h` chessboard, but for a single knight on some square. The knight must perform a sequence of legal moves that result in the knight visiting every square on the chessboard exactly once. Note that it is *not* a requirement that the tour be "closed"; that is, the knight need not end within a single move of its start position.
|
||||
[Problema del Tour del Cavallo](https://en.wikipedia.org/wiki/Knight%27s_tour): Hai una scacchiera vuota `w` \* `h`, tranne che per un singolo cavallo su una qualche casella. Il cavallo deve eseguire una sequenza di mosse permesse che lo portano a visitare ogni casella sulla scacchiera esattamente una sola volta. Nota che *non è* un requisito che il tour sia "chiuso", cioè il cavallo non deve terminare a distanza di una mossa dalla sua posizione di partenza.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes `w` and `h` as parameters and returns the number of initial positions from where it is possible to achieve the task stated above.
|
||||
Scrivi una funzione che richiede `w` e `h` come parametri e restituisce il numero di posizioni iniziali da dove è possibile completare quanto richiesto sopra.
|
||||
|
||||
# --hints--
|
||||
|
||||
`knightTour` should be a function.
|
||||
`knightTour` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof knightTour == 'function');
|
||||
```
|
||||
|
||||
`knightTour(6, 6)` should return a number.
|
||||
`knightTour(6, 6)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof knightTour(6, 6) == 'number');
|
||||
```
|
||||
|
||||
`knightTour(6, 6)` should return `36`.
|
||||
`knightTour(6, 6)` dovrebbe tornare `36`.
|
||||
|
||||
```js
|
||||
assert.equal(knightTour(6, 6), 36);
|
||||
```
|
||||
|
||||
`knightTour(5, 6)` should return `30`.
|
||||
`knightTour(5, 6)` dovrebbe tornare `30`.
|
||||
|
||||
```js
|
||||
assert.equal(knightTour(5, 6), 30);
|
||||
```
|
||||
|
||||
`knightTour(4, 6)` should return `12`.
|
||||
`knightTour(4, 6)` dovrebbe tornare `12`.
|
||||
|
||||
```js
|
||||
assert.equal(knightTour(4, 6), 12);
|
||||
```
|
||||
|
||||
`knightTour(7, 3)` should return `10`.
|
||||
`knightTour(7, 3)` dovrebbe tornare `10`.
|
||||
|
||||
```js
|
||||
assert.equal(knightTour(7, 3), 10);
|
||||
```
|
||||
|
||||
`knightTour(8, 6)` should return `48`.
|
||||
`knightTour(8, 6)` dovrebbe tornare `48`.
|
||||
|
||||
```js
|
||||
assert.equal(knightTour(8, 6), 48);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7edb
|
||||
title: Largest int from concatenated ints
|
||||
title: Intero più grande da interi concatenati
|
||||
challengeType: 5
|
||||
forumTopicId: 302298
|
||||
dashedName: largest-int-from-concatenated-ints
|
||||
@ -8,47 +8,47 @@ dashedName: largest-int-from-concatenated-ints
|
||||
|
||||
# --description--
|
||||
|
||||
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
|
||||
Dato un insieme di numeri interi positivi, scrivere una funzione per ordinare gli interi in modo che la concatenazione dei numeri formi il più grande numero intero possibile e restituisca questo numero intero.
|
||||
|
||||
# --hints--
|
||||
|
||||
`maxCombine` should be a function.
|
||||
`maxCombine` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof maxCombine == 'function');
|
||||
```
|
||||
|
||||
`maxCombine([1, 3, 3, 4, 55])` should return a number.
|
||||
`maxCombine([1, 3, 3, 4, 55])` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof maxCombine([1, 3, 3, 4, 55]) == 'number');
|
||||
```
|
||||
|
||||
`maxCombine([1, 3, 3, 4, 55])` should return `554331`.
|
||||
`maxCombine([1, 3, 3, 4, 55])` dovrebbe restituire `554331`.
|
||||
|
||||
```js
|
||||
assert.equal(maxCombine([1, 3, 3, 4, 55]), 554331);
|
||||
```
|
||||
|
||||
`maxCombine([71, 45, 23, 4, 5])` should return `71545423`.
|
||||
`maxCombine([71, 45, 23, 4, 5])` dovrebbe restituire `71545423`.
|
||||
|
||||
```js
|
||||
assert.equal(maxCombine([71, 45, 23, 4, 5]), 71545423);
|
||||
```
|
||||
|
||||
`maxCombine([14, 43, 53, 114, 55])` should return `55534314114`.
|
||||
`maxCombine([14, 43, 53, 114, 55])` dovrebbe restituire `55534314114`.
|
||||
|
||||
```js
|
||||
assert.equal(maxCombine([14, 43, 53, 114, 55]), 55534314114);
|
||||
```
|
||||
|
||||
`maxCombine([1, 34, 3, 98, 9, 76, 45, 4])` should return `998764543431`.
|
||||
`maxCombine([1, 34, 3, 98, 9, 76, 45, 4])` dovrebbe restituire `998764543431`.
|
||||
|
||||
```js
|
||||
assert.equal(maxCombine([1, 34, 3, 98, 9, 76, 45, 4]), 998764543431);
|
||||
```
|
||||
|
||||
`maxCombine([54, 546, 548, 60])` should return `6054854654`.
|
||||
`maxCombine([54, 546, 548, 60])` dovrebbe restituire `6054854654`.
|
||||
|
||||
```js
|
||||
assert.equal(maxCombine([54, 546, 548, 60]), 6054854654);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7edc
|
||||
title: Last Friday of each month
|
||||
title: Ultimo venerdì di ogni mese
|
||||
challengeType: 5
|
||||
forumTopicId: 302299
|
||||
dashedName: last-friday-of-each-month
|
||||
@ -8,65 +8,65 @@ dashedName: last-friday-of-each-month
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that returns the date of the last Friday of a given month for a given year.
|
||||
Scrivi una funzione che restituisce la data dell'ultimo venerdì di un dato mese per un dato anno.
|
||||
|
||||
# --hints--
|
||||
|
||||
`lastFriday` should be a function.
|
||||
`lastFriday` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof lastFriday == 'function');
|
||||
```
|
||||
|
||||
`lastFriday(2018, 1)` should return a number.
|
||||
`lastFriday(2018, 1)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof lastFriday(2018, 1) == 'number');
|
||||
```
|
||||
|
||||
`lastFriday(2018, 1)` should return `26`.
|
||||
`lastFriday(2018, 1)` dovrebbe restituire `26`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2018, 1), 26);
|
||||
```
|
||||
|
||||
`lastFriday(2017, 2)` should return `24`.
|
||||
`lastFriday(2017, 2)` dovrebbe restituire `24`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2017, 2), 24);
|
||||
```
|
||||
|
||||
`lastFriday(2012, 3)` should return `30`.
|
||||
`lastFriday(2012, 3)` dovrebbe restituire `30`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2012, 3), 30);
|
||||
```
|
||||
|
||||
`lastFriday(1900, 4)` should return `27`.
|
||||
`lastFriday(1900, 4)` dovrebbe restituire `27`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(1900, 4), 27);
|
||||
```
|
||||
|
||||
`lastFriday(2000, 5)` should return `26`.
|
||||
`lastFriday(2000, 5)` dovrebbe restituire `26`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2000, 5), 26);
|
||||
```
|
||||
|
||||
`lastFriday(2006, 6)` should return `30`.
|
||||
`lastFriday(2006, 6)` dovrebbe restituire `30`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2006, 6), 30);
|
||||
```
|
||||
|
||||
`lastFriday(2010, 7)` should return `30`.
|
||||
`lastFriday(2010, 7)` dovrebbe restituire `30`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2010, 7), 30);
|
||||
```
|
||||
|
||||
`lastFriday(2005, 8)` should return `26`.
|
||||
`lastFriday(2005, 8)` dovrebbe restituire `26`.
|
||||
|
||||
```js
|
||||
assert.equal(lastFriday(2005, 8), 26);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e4ce2b6ac708cc68c1df25e
|
||||
title: Last letter-first letter
|
||||
title: Ultima lettera-prima lettera
|
||||
challengeType: 5
|
||||
forumTopicId: 385256
|
||||
dashedName: last-letter-first-letter
|
||||
@ -8,30 +8,30 @@ dashedName: last-letter-first-letter
|
||||
|
||||
# --description--
|
||||
|
||||
A certain children's game involves starting with a word in a particular category. Each participant in turn says a word, but that word must begin with the final letter of the previous word. Once a word has been given, it cannot be repeated. If an opponent cannot give a word in the category, they fall out of the game.
|
||||
Un certo gioco per bambini comporta l'iniziare con una parola in una categoria particolare. Ogni partecipante a sua volta dice una parola, ma quella parola deve iniziare con la lettera finale della parola precedente. Una volta che una parola è stata data, non può essere ripetuta. Se un avversario non riesce a dare una parola nella categoria è fuori dal gioco.
|
||||
|
||||
For example, with "animals" as the category,
|
||||
Ad esempio, con "animali" come categoria,
|
||||
|
||||
<pre>Child 1: dog
|
||||
Child 2: goldfish
|
||||
Child 1: hippopotamus
|
||||
Child 2: snake
|
||||
<pre>Bambino 1: cane
|
||||
Bambino 2: echidna
|
||||
Bambino 1: alligatore
|
||||
Bambino 2: elefante
|
||||
...
|
||||
</pre>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an input array of words. The function should return an array of words where the first letter of each word is the same as the last letter of the previous word. Only use the words in the input array, and once a word is used it cannot be repeated. The words in the return array should be selected and sequenced so that that its length is maximized.
|
||||
Scrivi una funzione che accetta un array di parole in input. La funzione dovrebbe restituire un array di parole dove la prima lettera di ogni parola è uguale a l'ultima lettera della parola precedente. Usa solo le parole nell'array di input e una volta usata una parola non può essere ripetuta. Le parole nell'array restituito devono essere selezionate e ordinate in modo che la sua lunghezza sia massimizzata.
|
||||
|
||||
# --hints--
|
||||
|
||||
`findLongestChain` should be a function.
|
||||
`findLongestChain` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof findLongestChain == 'function');
|
||||
```
|
||||
|
||||
`findLongestChain(["certain", "each", "game", "involves", "starting", "with", "word"])` should return an array.
|
||||
`findLongestChain(["certain", "each", "game", "involves", "starting", "with", "word"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -49,7 +49,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`findLongestChain(["certain", "each", "game", "involves", "starting", "with", "word"])` should return `["involves", "starting", "game", "each"]`.
|
||||
`findLongestChain(["certain", "each", "game", "involves", "starting", "with", "word"])` dovrebbe restituire `["involves", "starting", "game", "each"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -66,7 +66,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`findLongestChain(["audino", "bagon", "kangaskhan", "banette", "bidoof", "braviary", "exeggcute", "yamask"])` should return `["braviary", "yamask", "kangaskhan"]`
|
||||
`findLongestChain(["audino", "bagon", "kangaskhan", "banette", "bidoof", "braviary", "exeggcute", "yamask"])` dovrebbe restituire `["braviary", "yamask", "kangaskhan"]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -84,7 +84,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`findLongestChain(["harp", "poliwrath", "poochyena", "porygon2", "porygonz", "archana"])` should return `["poliwrath", "harp", "poochyena", "archana"]`.
|
||||
`findLongestChain(["harp", "poliwrath", "poochyena", "porygon2", "porygonz", "archana"])` dovrebbe restituire `["poliwrath", "harp", "poochyena", "archana"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -100,7 +100,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`findLongestChain(["scolipede", "elephant", "zeaking", "sealeo", "silcoon", "tigers"])` should return `["scolipede", "elephant", "tigers", "sealeo"]`.
|
||||
`findLongestChain(["scolipede", "elephant", "zeaking", "sealeo", "silcoon", "tigers"])` dovrebbe restituire `["scolipede", "elephant", "tigers", "sealeo"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -116,7 +116,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`findLongestChain(["loudred", "lumineon", "lunatone", "machamp", "magnezone", "nosepass", "petilil", "pidgeotto", "pikachu"])` should return `["machamp", "petilil", "lumineon", "nosepass"]`.
|
||||
`findLongestChain(["loudred", "lumineon", "lunatone", "machamp", "magnezone", "nosepass", "petilil", "pidgeotto", "pikachu"])` dovrebbe restituire `["machamp", "petilil", "lumineon", "nosepass"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ede
|
||||
title: Leap year
|
||||
title: Anno bisestile
|
||||
challengeType: 5
|
||||
forumTopicId: 302300
|
||||
dashedName: leap-year
|
||||
@ -8,53 +8,53 @@ dashedName: leap-year
|
||||
|
||||
# --description--
|
||||
|
||||
Determine whether a given year is a leap year in the Gregorian calendar.
|
||||
Determina se un dato anno è bisestile nel calendario gregoriano.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isLeapYear` should be a function.
|
||||
`isLeapYear` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isLeapYear == 'function');
|
||||
```
|
||||
|
||||
`isLeapYear()` should return a boolean.
|
||||
`isLeapYear()` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isLeapYear(2018) == 'boolean');
|
||||
```
|
||||
|
||||
`isLeapYear(2018)` should return `false`.
|
||||
`isLeapYear(2018)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(2018), false);
|
||||
```
|
||||
|
||||
`isLeapYear(2016)` should return `true`.
|
||||
`isLeapYear(2016)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(2016), true);
|
||||
```
|
||||
|
||||
`isLeapYear(2000)` should return `true`.
|
||||
`isLeapYear(2000)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(2000), true);
|
||||
```
|
||||
|
||||
`isLeapYear(1900)` should return `false`.
|
||||
`isLeapYear(1900)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(1900), false);
|
||||
```
|
||||
|
||||
`isLeapYear(1996)` should return `true`.
|
||||
`isLeapYear(1996)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(1996), true);
|
||||
```
|
||||
|
||||
`isLeapYear(1800)` should return `false`.
|
||||
`isLeapYear(1800)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLeapYear(1800), false);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7edf
|
||||
title: Least common multiple
|
||||
title: Minimo comune multiplo
|
||||
challengeType: 5
|
||||
forumTopicId: 302301
|
||||
dashedName: least-common-multiple
|
||||
@ -8,51 +8,51 @@ dashedName: least-common-multiple
|
||||
|
||||
# --description--
|
||||
|
||||
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors. As a special case, if either *m* or *n* is zero, then the least common multiple is zero. One way to calculate the least common multiple is to iterate all the multiples of *m*, until you find one that is also a multiple of *n*. If you already have *gcd* for [greatest common divisor](https://rosettacode.org/wiki/greatest common divisor), then this formula calculates *lcm*. ( \\operatorname{lcm}(m, n) = \\frac{|m \\times n|}{\\operatorname{gcd}(m, n)} )
|
||||
Il minimo comune multiplo di 12 e 18 è 36, perché 12 è un fattore (12 × 3 = 36), e 18 è un fattore (18 × 2 = 36), e non c'è un numero intero positivo inferiore a 36 che abbia entrambi i fattori. Come caso speciale, se *m* o *n* è zero, allora il minimo comune multiplo è zero. Un modo per calcolare il minimo comune multiplo è quello di iterare tutti i multipli di *m*, fino a trovarne uno che è anche un multiplo di *n*. Se hai già *MCD* per [il massimo comun divisore](https://rosettacode.org/wiki/greatest common divisor), questa formula calcola *mcm*. ( \\operatorname{mcm}(m, n) = \\frac{| m \\times n|}{\\operatorname{MCD}(m, n)} )
|
||||
|
||||
# --instructions--
|
||||
|
||||
Compute the least common multiple of an array of integers. Given *m* and *n*, the least common multiple is the smallest positive integer that has both *m* and *n* as factors.
|
||||
Calcola il mcm di un array di interi. Dati *m* e *n*, il mcm è il più piccolo intero positivo che ha sia *m* che *n* come fattori.
|
||||
|
||||
# --hints--
|
||||
|
||||
`LCM` should be a function.
|
||||
`LCM` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof LCM == 'function');
|
||||
```
|
||||
|
||||
`LCM([2, 4, 8])` should return a number.
|
||||
`LCM([2, 4, 8])` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof LCM([2, 4, 8]) == 'number');
|
||||
```
|
||||
|
||||
`LCM([2, 4, 8])` should return `8`.
|
||||
`LCM([2, 4, 8])` dovrebbe restituire `8`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([2, 4, 8]), 8);
|
||||
```
|
||||
|
||||
`LCM([4, 8, 12])` should return `24`.
|
||||
`LCM([4, 8, 12])` dovrebbe restituire `24`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([4, 8, 12]), 24);
|
||||
```
|
||||
|
||||
`LCM([3, 4, 5, 12, 40])` should return `120`.
|
||||
`LCM([3, 4, 5, 12, 40])` dovrebbe restituire `120`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([3, 4, 5, 12, 40]), 120);
|
||||
```
|
||||
|
||||
`LCM([11, 33, 90])` should return `990`.
|
||||
`LCM([11, 33, 90])` dovrebbe restituire `990`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([11, 33, 90]), 990);
|
||||
```
|
||||
|
||||
`LCM([-50, 25, -45, -18, 90, 447])` should return `67050`.
|
||||
`LCM([-50, 25, -45, -18, 90, 447])` dovrebbe restituire `67050`.
|
||||
|
||||
```js
|
||||
assert.equal(LCM([-50, 25, -45, -18, 90, 447]), 67050);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ee0
|
||||
title: Left factorials
|
||||
title: Fattoriale sinistro
|
||||
challengeType: 5
|
||||
forumTopicId: 302302
|
||||
dashedName: left-factorials
|
||||
@ -8,7 +8,7 @@ dashedName: left-factorials
|
||||
|
||||
# --description--
|
||||
|
||||
**Left factorials**, $ !n $, may refer to either *subfactorials* or to *factorial sums*. The same notation can be confusingly seen used for the two different definitions. Sometimes, *subfactorials* (also known as *derangements*) may use any of the notations:
|
||||
**Fattoriale sinistro**, $ !n $, può riferisi a *subfattoriali* o a *somme fattoriali*. La stessa notazione confusionalmente può essere vista in uso per le due diverse definizioni. A volte, *subfattoriali* (noti anche come *dismutazioni*) possono usare qualsiasi delle seguenti notazioni:
|
||||
|
||||
<ul>
|
||||
<li>$!n`$</li>
|
||||
@ -16,67 +16,67 @@ dashedName: left-factorials
|
||||
<li>$n¡$</li>
|
||||
</ul>
|
||||
|
||||
(It may not be visually obvious, but the last example uses an upside-down exclamation mark.) This task will be using this formula for **left factorial**:
|
||||
(Potrebbe non essere visivamente ovvio, ma l'ultimo esempio usa un punto esclamativo rovesciato.) Questa sfida userà questa formula per il **fattoriale sinistro**:
|
||||
|
||||
$ !n = \\sum\_{k=0}^{n-1} k! $
|
||||
|
||||
where $!0 = 0$
|
||||
dove $!0 = 0$
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to calculate the left factorial of a given number.
|
||||
Scrivi una funzione per calcolare il fattoriale sinistro di un dato numero.
|
||||
|
||||
# --hints--
|
||||
|
||||
`leftFactorial` should be a function.
|
||||
`leftFactorial` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof leftFactorial == 'function');
|
||||
```
|
||||
|
||||
`leftFactorial(0)` should return a number.
|
||||
`leftFactorial(0)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof leftFactorial(0) == 'number');
|
||||
```
|
||||
|
||||
`leftFactorial(0)` should return `0`.
|
||||
`leftFactorial(0)` dovrebbe restituire `0`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(0), 0);
|
||||
```
|
||||
|
||||
`leftFactorial(1)` should return `1`.
|
||||
`leftFactorial(1)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(1), 1);
|
||||
```
|
||||
|
||||
`leftFactorial(2)` should return `2`.
|
||||
`leftFactorial(2)` dovrebbe restituire `2`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(2), 2);
|
||||
```
|
||||
|
||||
`leftFactorial(3)` should return `4`.
|
||||
`leftFactorial(3)` dovrebbe restituire `4`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(3), 4);
|
||||
```
|
||||
|
||||
`leftFactorial(10)` should return `409114`.
|
||||
`leftFactorial(10)` dovrebbe restituire `409114`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(10), 409114);
|
||||
```
|
||||
|
||||
`leftFactorial(17)` should return `22324392524314`.
|
||||
`leftFactorial(17)` dovrebbe restituire `22324392524314`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(17), 22324392524314);
|
||||
```
|
||||
|
||||
`leftFactorial(19)` should return `6780385526348314`.
|
||||
`leftFactorial(19)` dovrebbe restituire `6780385526348314`.
|
||||
|
||||
```js
|
||||
assert.equal(leftFactorial(19), 6780385526348314);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e4ce2eaac708cc68c1df260
|
||||
title: Levenshtein distance
|
||||
title: Distanza di Levenshtein
|
||||
challengeType: 5
|
||||
forumTopicId: 385264
|
||||
dashedName: levenshtein-distance
|
||||
@ -8,71 +8,71 @@ dashedName: levenshtein-distance
|
||||
|
||||
# --description--
|
||||
|
||||
In information theory and computer science, the **Levenshtein distance** is a [metric](https://en.wikipedia.org/wiki/string metric) for measuring the amount of difference between two sequences (i.e. an [edit distance](https://en.wikipedia.org/wiki/edit distance)). The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
|
||||
Nella teoria dell'informazione e nell'informatica, la **distanza di Levenshtein** è una [metrica](https://en.wikipedia.org/wiki/string metric) per misurare la quantità di differenza tra due sequenze (cioè una [edit distance](https://en.wikipedia.org/wiki/edit distance)). La distanza Levenshtein tra due stringhe è definita come il numero minimo di modifiche necessarie per trasformare una stringa nell'altra, dove le operazioni di modifica consentite sono inserimento, cancellazione o sostituzione di un singolo carattere.
|
||||
|
||||
Example:
|
||||
Esempio:
|
||||
|
||||
The Levenshtein distance between "**kitten**" and "**sitting**" is 3, since the following three edits change one into the other, and there isn't a way to do it with fewer than three edits:
|
||||
La distanza di Levenshtein tra "**kitten**" e "**sitting**" è 3, dal momento che le seguenti tre modifiche cambiano una nell'altra, e non c'è un modo per farlo con meno di tre modifiche:
|
||||
|
||||
<ul>
|
||||
<li><strong>k</strong>itten <strong>s</strong>itten (substitution of 'k' with 's')</li>
|
||||
<li>sitt<strong>e</strong>n sitt<strong>i</strong>n (substitution of 'e' with 'i')</li>
|
||||
<li>sittin sittin<strong>g</strong> (insert 'g' at the end).</li>
|
||||
<li><strong>k</strong>itten <strong>s</strong>itten (sostiruzione di 'k' con 's')</li>
|
||||
<li>sitt<strong>e</strong>n sitt<strong>i</strong>n (sostituzione di 'e' con 'i')</li>
|
||||
<li>sittin sittin<strong>g</strong> (inserisci 'g' alla fine).</li>
|
||||
</ul>
|
||||
|
||||
*The Levenshtein distance between "**rosettacode**", "**raisethysword**" is **8**.*
|
||||
*La distanza Levenshtein tra "**rosettacode**", "**raisethysword**" è **8**.*
|
||||
|
||||
*The distance between two strings is same as that when both strings are reversed.*
|
||||
*La distanza tra due stringhe è uguale a quella tra le due stringhe scritte al contrario.*
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns the Levenshtein distance between two strings given as parameters.
|
||||
Scrivi una funzione che restituisce la distanza di Levenshtein tra due stringhe fornite come parametri.
|
||||
|
||||
# --hints--
|
||||
|
||||
`levenshtein` should be a function.
|
||||
`levenshtein` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof levenshtein == 'function');
|
||||
```
|
||||
|
||||
`levenshtein("mist", "dist")` should return a number.
|
||||
`levenshtein("mist", "dist")` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof levenshtein('mist', 'dist') == 'number');
|
||||
```
|
||||
|
||||
`levenshtein("mist", "dist")` should return `1`.
|
||||
`levenshtein("mist", "dist")` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('mist', 'dist'), 1);
|
||||
```
|
||||
|
||||
`levenshtein("tier", "tor")` should return `2`.
|
||||
`levenshtein("tier", "tor")` dovrebbe restituire `2`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('tier', 'tor'), 2);
|
||||
```
|
||||
|
||||
`levenshtein("kitten", "sitting")` should return `3`.
|
||||
`levenshtein("kitten", "sitting")` dovrebbe restituire `3`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('kitten', 'sitting'), 3);
|
||||
```
|
||||
|
||||
`levenshtein("stop", "tops")` should return `2`.
|
||||
`levenshtein("stop", "tops")` dovrebbe restituire `2`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('stop', 'tops'), 2);
|
||||
```
|
||||
|
||||
`levenshtein("rosettacode", "raisethysword")` should return `8`.
|
||||
`levenshtein("rosettacode", "raisethysword")` dovrebbe restituire `8`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('rosettacode', 'raisethysword'), 8);
|
||||
```
|
||||
|
||||
`levenshtein("mississippi", "swiss miss")` should return `8`.
|
||||
`levenshtein("mississippi", "swiss miss")` dovrebbe restituire `8`.
|
||||
|
||||
```js
|
||||
assert.equal(levenshtein('mississippi', 'swiss miss'), 8);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e4ce2f5ac708cc68c1df261
|
||||
title: Linear congruential generator
|
||||
title: Generatore lineare congruenziale
|
||||
challengeType: 5
|
||||
forumTopicId: 385266
|
||||
dashedName: linear-congruential-generator
|
||||
@ -8,65 +8,65 @@ dashedName: linear-congruential-generator
|
||||
|
||||
# --description--
|
||||
|
||||
The [linear congruential generator](https://en.wikipedia.org/wiki/linear congruential generator) is a very simple example of a [random number generator](http://rosettacode.org/wiki/random number generator). All linear congruential generators use this formula:
|
||||
Il generatore [lineare congruenziale](https://en.wikipedia.org/wiki/linear congruential generator) è un esempio molto semplice di un [generatore di numeri casuali](http://rosettacode.org/wiki/random number generator). Tutti i generatori congruenziali lineari utilizzano questa formula:
|
||||
|
||||
$$r_{n + 1} = (a \times r_n + c) \bmod m$$
|
||||
|
||||
Where:
|
||||
Dove:
|
||||
|
||||
<ul>
|
||||
<li>$ r_0 $ is a seed.</li>
|
||||
<li>$r_1$, $r_2$, $r_3$, ..., are the random numbers.</li>
|
||||
<li>$a$, $c$, $m$ are constants.</li>
|
||||
<li>$ r_0 $ è un seme.</li>
|
||||
<li>$r_1$, $r_2$, $r_3$, ..., sono i numeri casuali.</li>
|
||||
<li>$a$, $c$, $m$ sono costanti.</li>
|
||||
</ul>
|
||||
|
||||
If one chooses the values of $a$, $c$ and $m$ with care, then the generator produces a uniform distribution of integers from $0$ to $m - 1$.
|
||||
Se si scelgono i valori di $a$, $c$ e $m$ con cura, il generatore produce una distribuzione uniforme di interi da $0$ a $m - 1$.
|
||||
|
||||
LCG numbers have poor quality. $r_n$ and $r\_{n + 1}$ are not independent, as true random numbers would be. Anyone who knows $r_n$ can predict $r\_{n + 1}$, therefore LCG is not cryptographically secure. The LCG is still good enough for simple tasks like [Miller-Rabin primality test](http://rosettacode.org/wiki/Miller-Rabin primality test), or [FreeCell deals](http://rosettacode.org/wiki/deal cards for FreeCell). Among the benefits of the LCG, one can easily reproduce a sequence of numbers, from the same $r_0$. One can also reproduce such sequence with a different programming language, because the formula is so simple.
|
||||
I numeri LCG hanno una scarsa qualità. $r_n$ e $r\_{n + 1}$ non sono indipendenti, come i veri numeri casuali. Chiunque sappia $r_n$ può prevedere $r\_{n + 1}$, quindi LCG non è crittograficamente sicuro. L'LCG è ancora abbastanza buono per semplici attività come [test di primalità Miller-Rabin](http://rosettacode.org/wiki/Miller-Rabin primality test), o [mani di FreeCell](http://rosettacode.org/wiki/deal cards for FreeCell). Uno dei benefici del GCL è che si può facilmente riprodurre una sequenza di numeri dallo stesso $r_0$. Si può anche riprodurre tale sequenza con un linguaggio di programmazione diverso, perché la formula è molto semplice.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes $r_0,a,c,m,n$ as parameters and returns $r_n$.
|
||||
Scrivi una funzione che richiede $r_0,a,c,m,n$ come parametri e restituisce $r_n$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`linearCongGenerator` should be a function.
|
||||
`linearCongGenerator` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof linearCongGenerator == 'function');
|
||||
```
|
||||
|
||||
`linearCongGenerator(324, 1145, 177, 2148, 3)` should return a number.
|
||||
`linearCongGenerator(324, 1145, 177, 2148, 3)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof linearCongGenerator(324, 1145, 177, 2148, 3) == 'number');
|
||||
```
|
||||
|
||||
`linearCongGenerator(324, 1145, 177, 2148, 3)` should return `855`.
|
||||
`linearCongGenerator(324, 1145, 177, 2148, 3)` dovrebbe restituire `855`.
|
||||
|
||||
```js
|
||||
assert.equal(linearCongGenerator(324, 1145, 177, 2148, 3), 855);
|
||||
```
|
||||
|
||||
`linearCongGenerator(234, 11245, 145, 83648, 4)` should return `1110`.
|
||||
`linearCongGenerator(234, 11245, 145, 83648, 4)` dovrebbe tornare `1110`.
|
||||
|
||||
```js
|
||||
assert.equal(linearCongGenerator(234, 11245, 145, 83648, 4), 1110);
|
||||
```
|
||||
|
||||
`linearCongGenerator(85, 11, 1234, 214748, 5)` should return `62217`.
|
||||
`linearCongGenerator(85, 11, 1234, 214748, 5)` dovrebbe tornare `62217`.
|
||||
|
||||
```js
|
||||
assert.equal(linearCongGenerator(85, 11, 1234, 214748, 5), 62217);
|
||||
```
|
||||
|
||||
`linearCongGenerator(0, 1103515245, 12345, 2147483648, 1)` should return `12345`.
|
||||
`linearCongGenerator(0, 1103515245, 12345, 2147483648, 1)` dovrebbe restituire `12345`.
|
||||
|
||||
```js
|
||||
assert.equal(linearCongGenerator(0, 1103515245, 12345, 2147483648, 1), 12345);
|
||||
```
|
||||
|
||||
`linearCongGenerator(0, 1103515245, 12345, 2147483648, 2)` should return `1406932606`.
|
||||
`linearCongGenerator(0, 1103515245, 12345, 2147483648, 2)` dovrebbe restituire `1406932606`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e4ce2a1ac708cc68c1df25d
|
||||
title: Long multiplication
|
||||
title: Moltiplicazione lunga
|
||||
challengeType: 5
|
||||
forumTopicId: 385269
|
||||
dashedName: long-multiplication
|
||||
@ -8,31 +8,31 @@ dashedName: long-multiplication
|
||||
|
||||
# --description--
|
||||
|
||||
Explicitly implement [long multiplication](https://en.wikipedia.org/wiki/long multiplication).
|
||||
Implementa esplicitamente [una moltiplicazione lunga](https://en.wikipedia.org/wiki/long multiplication).
|
||||
|
||||
This is one possible approach to arbitrary-precision integer algebra.
|
||||
Questo è un possibile approccio all'algebra intera a precisione arbitraria.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes two strings of large numbers as parameters. Your function should return the product of these two large numbers as a string.
|
||||
Scrivi una funzione che richiede due stringhe di grandi numeri come parametri. La tua funzione dovrebbe restituire il prodotto di questi due grandi numeri come stringa.
|
||||
|
||||
**Note:** In JavaScript, arithmetic operations are inaccurate with large numbers, so you will have to implement precise multiplication yourself.
|
||||
**Nota:** In JavaScript, le operazioni aritmetiche sono inaccurate con grandi numeri, quindi dovrai implementare una moltiplicazione precisa da solo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`mult` should be a function.
|
||||
`mult` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof mult == 'function');
|
||||
```
|
||||
|
||||
`mult("18446744073709551616", "18446744073709551616")` should return a string.
|
||||
`mult("18446744073709551616", "18446744073709551616")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof mult('18446744073709551616', '18446744073709551616') == 'string');
|
||||
```
|
||||
|
||||
`mult("18446744073709551616", "18446744073709551616")` should return `"340282366920938463463374607431768211456"`.
|
||||
`mult("18446744073709551616", "18446744073709551616")` dovrebbe restituire `"340282366920938463463374607431768211456"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -41,7 +41,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`mult("31844674073709551616", "1844674407309551616")` should return `"58743055272886011737990786529368211456"`.
|
||||
`mult("31844674073709551616", "1844674407309551616")` dovrebbe restituire `"58743055272886011737990786529368211456"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -50,7 +50,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`mult("1846744073709551616", "44844644073709551616")` should return `"82816580680737279241781007431768211456"`.
|
||||
`mult("1846744073709551616", "44844644073709551616")` dovrebbe restituire `"82816580680737279241781007431768211456"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -59,7 +59,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`mult("1844674407370951616", "1844674407709551616")` should return `"3402823669833978308014392742590611456"`.
|
||||
`mult("1844674407370951616", "1844674407709551616")` dovrebbe restituire `"3402823669833978308014392742590611456"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -68,7 +68,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`mult("2844674407370951616", "1844674407370955616")` should return `"5247498076580334548376218009219475456"`.
|
||||
`mult("2844674407370951616", "1844674407370955616")` dovrebbe restituire `"5247498076580334548376218009219475456"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -21,7 +21,7 @@ console.log(typeof {});
|
||||
|
||||
コンソールには、文字列 `string`、`number`、`object`、`object` が順番に表示されます。
|
||||
|
||||
JavaScript は 6 つのプリミティブな (イミュータブル) データ型として、`Boolean`、`Null`、`Undefined`、`Number`、`String`、および `Symbol` (ES6 で新登場) を認識します。また、ミュータブルアイテムのための型の 1 つである `Object` も認識します。 JavaScript では、配列は厳密にはオブジェクトの一種であることに注意してください。
|
||||
JavaScript recognizes seven primitive (immutable) data types: `Boolean`, `Null`, `Undefined`, `Number`, `String`, `Symbol` (new with ES6), and `BigInt` (new with ES2020), and one type for mutable items: `Object`. JavaScript では、配列は厳密にはオブジェクトの一種であることに注意してください。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
Reference in New Issue
Block a user