chore(i18n,learn): processed translations (#45165)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e4ce2bbac708cc68c1df25f
|
||||
title: Letter frequency
|
||||
title: Frequenza delle lettere
|
||||
challengeType: 5
|
||||
forumTopicId: 385263
|
||||
dashedName: letter-frequency
|
||||
@ -8,33 +8,33 @@ dashedName: letter-frequency
|
||||
|
||||
# --description--
|
||||
|
||||
Given a string, calculate the frequency of each character.
|
||||
Data una stringa, calcolare la frequenza di ogni carattere.
|
||||
|
||||
All characters should be counted. This includes lower and upper case letters, digits, whitespace, special characters, or any other distinct characters.
|
||||
Tutti i caratteri devono essere contati. Questo include lettere maiuscole e minuscole, cifre, spazi bianchi, caratteri speciali o qualsiasi altro carattere distinto.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to count the occurrences of each character in a given string.
|
||||
Scrivi una funzione per contare le occorrenze di ogni carattere in una determinata stringa.
|
||||
|
||||
The function should return a 2D array with each of the elements in the following form: `['char', freq]`. The character should be a string with a length of 1, and frequency is a number denoting the count.
|
||||
La funzione dovrebbe restituire un array 2D con ciascuno degli elementi nella seguente forma: `['char', freq]`. Il carattere deve essere una stringa con una lunghezza di 1, e la frequenza è un numero che indica il conteggio.
|
||||
|
||||
For example, given the string "ab", your function should return `[['a', 1], ['b', 1]]`.
|
||||
Per esempio, data la stringa "ab", la tua funzione dovrebbe restituire `[['a', 1], ['b', 1]]`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`letterFrequency` should be a function.
|
||||
`letterFrequency` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof letterFrequency == 'function');
|
||||
```
|
||||
|
||||
`letterFrequency("Not all that Mrs. Bennet, however")` should return an array.
|
||||
`letterFrequency("Not all that Mrs. Bennet, however")` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(letterFrequency('Not all that Mrs. Bennet, however')));
|
||||
```
|
||||
|
||||
`letterFrequency("Not all that Mrs. Bennet, however")` should return `[[" ", 5], [",", 1], [".", 1], ["B", 1], ["M", 1], ["N", 1], ["a", 2], ["e", 4], ["h", 2], ["l", 2], ["n", 2], ["o", 2], ["r", 2], ["s", 1], ["t", 4], ["v", 1], ["w", 1]]`.
|
||||
`letterFrequency("Not all that Mrs. Bennet, however")` dovrebbe restituire `[[" ", 5], [",", 1], [".", 1], ["B", 1], ["M", 1], ["N", 1], ["a", 2], ["e", 4], ["h", 2], ["l", 2], ["n", 2], ["o", 2], ["r", 2], ["s", 1], ["t", 4], ["v", 1], ["w", 1]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('Not all that Mrs. Bennet, however'), [
|
||||
@ -58,7 +58,7 @@ assert.deepEqual(letterFrequency('Not all that Mrs. Bennet, however'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`letterFrequency("daughters, could ask on the ")` should return `[[" ", 5],[",", 1],["a", 2],["c", 1],["d", 2],["e", 2],["g", 1],["h", 2],["k", 1],["l", 1],["n", 1],["o", 2],["r", 1],["s", 2],["t", 2],["u", 2]]`.
|
||||
`letterFrequency("daughters, could ask on the ")` dovrebbe restituire `[[" ", 5],[",", 1],["a", 2],["c", 1],["d", 2],["e", 2],["g", 1],["h", 2],["k", 1],["l", 1],["n", 1],["o", 2],["r", 1],["s", 2],["t", 2],["u", 2]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('daughters, could ask on the '), [
|
||||
@ -81,7 +81,7 @@ assert.deepEqual(letterFrequency('daughters, could ask on the '), [
|
||||
]);
|
||||
```
|
||||
|
||||
`letterFrequency("husband any satisfactory description")` should return `[[" ", 3], ["a", 4], ["b", 1], ["c", 2], ["d", 2], ["e", 1], ["f", 1], ["h", 1], ["i", 3], ["n", 3], ["o", 2], ["p", 1], ["r", 2], ["s", 4], ["t", 3], ["u", 1], ["y", 2]]`.
|
||||
`letterFrequency("husband any satisfactory description")` dovrebbe restituire `[[" ", 3], ["a", 4], ["b", 1], ["c", 2], ["d", 2], ["e", 1], ["f", 1], ["h", 1], ["i", 3], ["n", 3], ["o", 2], ["p", 1], ["r", 2], ["s", 4], ["t", 3], ["u", 1], ["y", 2]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('husband any satisfactory description'), [
|
||||
@ -105,7 +105,7 @@ assert.deepEqual(letterFrequency('husband any satisfactory description'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`letterFrequency("in various ways--with barefaced")` should return `[[" ", 3], ["-", 2], ["a", 4], ["b", 1], ["c", 1], ["d", 1], ["e", 2], ["f", 1], ["h", 1], ["i", 3], ["n", 1], ["o", 1], ["r", 2], ["s", 2], ["t", 1], ["u", 1], ["v", 1], ["w", 2], ["y", 1]]`.
|
||||
`letterFrequency("in various ways--with barefaced")` dovrebbe restituire `[[" ", 3], ["-", 2], ["a", 4], ["b", 1], ["c", 1], ["d", 1], ["e", 2], ["f", 1], ["h", 1], ["i", 3], ["n", 1], ["o", 1], ["r", 2], ["s", 2], ["t", 1], ["u", 1], ["v", 1], ["w", 2], ["y", 1]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('in various ways--with barefaced'), [
|
||||
@ -131,7 +131,7 @@ assert.deepEqual(letterFrequency('in various ways--with barefaced'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`letterFrequency("distant surmises; but he eluded")` should return `[[" ", 4], [";", 1], ["a", 1], ["b", 1], ["d", 3], ["e", 4], ["h", 1], ["i", 2], ["l", 1], ["m", 1], ["n", 1], ["r", 1], ["s", 4], ["t", 3], ["u", 3]]`.
|
||||
`letterFrequency("distant surmises; but he eluded")` dovrebbe restituire `[[" ", 4], [";", 1], ["a", 1], ["b", 1], ["d", 3], ["e", 4], ["h", 1], ["i", 2], ["l", 1], ["m", 1], ["n", 1], ["r", 1], ["s", 4], ["t", 3], ["u", 3]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('distant surmises; but he eluded'), [
|
||||
@ -153,7 +153,7 @@ assert.deepEqual(letterFrequency('distant surmises; but he eluded'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`letterFrequency("last obliged to accept the second-hand,")` should return `[[" ", 5], [",", 1], ["-", 1], ["a", 3], ["b", 1], ["c", 3], ["d", 3], ["e", 4], ["g", 1], ["h", 2], ["i", 1], ["l", 2], ["n", 2], ["o", 3], ["p", 1], ["s", 2], ["t", 4]]`.
|
||||
`letterFrequency("last obliged to accept the second-hand,")` dovrebbe restituire `[[" ", 5], [",", 1], ["-", 1], ["a", 3], ["b", 1], ["c", 3], ["d", 3], ["e", 4], ["g", 1], ["h", 2], ["i", 1], ["l", 2], ["n", 2], ["o", 3], ["p", 1], ["s", 2], ["t", 4]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(letterFrequency('last obliged to accept the second-hand,'), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dd1278e6ca105cde40ea9
|
||||
title: Longest common subsequence
|
||||
title: Più lunga successione comune
|
||||
challengeType: 5
|
||||
forumTopicId: 385271
|
||||
dashedName: longest-common-subsequence
|
||||
@ -8,65 +8,65 @@ dashedName: longest-common-subsequence
|
||||
|
||||
# --description--
|
||||
|
||||
The **longest common subsequence** (or [**LCS**](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem)) of groups A and B is the longest group of elements from A and B that are common between the two groups and in the same order in each group. For example, the sequences "1234" and "1224533324" have an LCS of "1234":
|
||||
La **sottosequenza comune più lunga** (o [**LCS**](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem)) dei gruppi A e B è il gruppo più lungo di elementi provenienti da A e B che sono comuni tra i due gruppi e nello stesso ordine in ogni gruppo. Per esempio, le sequenze "1234" e "1224533324" hanno un LCS di "1234":
|
||||
|
||||
***1234***
|
||||
|
||||
***12***245***3***332***4***
|
||||
|
||||
For a string example, consider the sequences "thisisatest" and "testing123testing". An LCS would be "tsitest":
|
||||
Per un esempio di stringa, considera le sequenze "thisisatest" e "testing123testing". Un LCS sarebbe "tsitest":
|
||||
|
||||
***t***hi***si***sa***test***
|
||||
|
||||
***t***e***s***t***i***ng123***test***ing.
|
||||
|
||||
Your code only needs to deal with strings.
|
||||
Il tuo codice deve riguardare solo le stringhe.
|
||||
|
||||
For more information on this problem please see [Wikipedia](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem).
|
||||
Per ulteriori informazioni su questo problema consulta [Wikipedia](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a case-sensitive function that returns the LCS of two strings. You don't need to show multiple LCS's.
|
||||
Scrivi una funzione sensibile alle maiuscole/minuscole che restituisce l'LCS di due stringhe. Non è necessario mostrare più LCS.
|
||||
|
||||
# --hints--
|
||||
|
||||
`lcs` should be a function.
|
||||
`lcs` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof lcs == 'function');
|
||||
```
|
||||
|
||||
`lcs("thisisatest", "testing123testing")` should return a string.
|
||||
`lcs("thisisatest", "testing123testing")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof lcs('thisisatest', 'testing123testing') == 'string');
|
||||
```
|
||||
|
||||
`lcs("thisisatest", "testing123testing")` should return `"tsitest"`.
|
||||
`lcs("thisisatest", "testing123testing")` dovrebbe restituire `"tsitest"`.
|
||||
|
||||
```js
|
||||
assert.equal(lcs('thisisatest', 'testing123testing'), 'tsitest');
|
||||
```
|
||||
|
||||
`lcs("ABCDGH", "AEDFHR")` should return `"ADH"`.
|
||||
`lcs("ABCDGH", "AEDFHR")` dovrebbe restituire `"ADH"`.
|
||||
|
||||
```js
|
||||
assert.equal(lcs('ABCDGH', 'AEDFHR'), 'ADH');
|
||||
```
|
||||
|
||||
`lcs("AGGTAB", "GXTXAYB")` should return `"GTAB"`.
|
||||
`lcs("AGGTAB", "GXTXAYB")` dovrebbe restituire `"GTAB"`.
|
||||
|
||||
```js
|
||||
assert.equal(lcs('AGGTAB', 'GXTXAYB'), 'GTAB');
|
||||
```
|
||||
|
||||
`lcs("BDACDB", "BDCB")` should return `"BDCB"`.
|
||||
`lcs("BDACDB", "BDCB")` dovrebbe restituire `"BDCB"`.
|
||||
|
||||
```js
|
||||
assert.equal(lcs('BDACDB', 'BDCB'), 'BDCB');
|
||||
```
|
||||
|
||||
`lcs("ABAZDC", "BACBAD")` should return `"ABAD"`.
|
||||
`lcs("ABAZDC", "BACBAD")` dovrebbe restituire `"ABAD"`.
|
||||
|
||||
```js
|
||||
assert.equal(lcs('ABAZDC', 'BACBAD'), 'ABAD');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dd139859c290b6ab80292
|
||||
title: Longest increasing subsequence
|
||||
title: Più lunga sottosequenza crescente
|
||||
challengeType: 5
|
||||
forumTopicId: 385272
|
||||
dashedName: longest-increasing-subsequence
|
||||
@ -8,57 +8,57 @@ dashedName: longest-increasing-subsequence
|
||||
|
||||
# --description--
|
||||
|
||||
The longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as possible. An example:
|
||||
Il problema di della più lunga sottosequenza crescente è quello di trovare una sottosequenza di una data sequenza in cui gli elementi successivi sono in ordine, dal più basso al più alto, e in cui la sottosequenza è la più lunga possibile. Un esempio:
|
||||
|
||||
For the following array:
|
||||
Per il seguente array:
|
||||
|
||||
$\\{3, 10, 2, 1, 20\\}$
|
||||
|
||||
Longest increasing sequence is:
|
||||
La sequenza crescente più lunga è:
|
||||
|
||||
$\\{3, 10, 20\\}$
|
||||
|
||||
For more information on this problem please see [Wikipedia](https://en.wikipedia.org/wiki/Longest increasing subsequence).
|
||||
Per ulteriori informazioni su questo problema consulta [Wikipedia](https://en.wikipedia.org/wiki/Longest increasing subsequence).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of numbers as a parameter and returns the longest increasing subsequence.
|
||||
Scrivere una funzione che prende un array di numeri come parametro e restituisce la più lunga sottosequenza crescente.
|
||||
|
||||
It is guaranteed that every array will have a longest increasing subsequence.
|
||||
È garantito che ogni array avrà una sottosequenza crescente più lunga.
|
||||
|
||||
# --hints--
|
||||
|
||||
`findSequence` should be a function.
|
||||
`findSequence` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof findSequence == 'function');
|
||||
```
|
||||
|
||||
`findSequence([3, 10, 2, 1, 20])` should return a array.
|
||||
`findSequence([3, 10, 2, 1, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(findSequence([3, 10, 2, 1, 20])));
|
||||
```
|
||||
|
||||
`findSequence([3, 10, 2, 1, 20])` should return `[3, 10, 20]`.
|
||||
`findSequence([3, 10, 2, 1, 20])` dovrebbe restituire `[3, 10, 20]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(findSequence([3, 10, 2, 1, 20]), [3, 10, 20]);
|
||||
```
|
||||
|
||||
`findSequence([2, 7, 3, 5, 8])` should return `[2, 3, 5, 8]`.
|
||||
`findSequence([2, 7, 3, 5, 8])` dovrebbe restituire `[2, 3, 5, 8]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(findSequence([2, 7, 3, 5, 8]), [2, 3, 5, 8]);
|
||||
```
|
||||
|
||||
`findSequence([2, 6, 4, 5, 1])` should return `[2, 4, 5]`.
|
||||
`findSequence([2, 6, 4, 5, 1])` dovrebbe restituire `[2, 4, 5]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(findSequence([2, 6, 4, 5, 1]), [2, 4, 5]);
|
||||
```
|
||||
|
||||
`findSequence([10, 22, 9, 33, 21, 50, 60, 80])` should return `[10, 22, 33, 50, 60, 80]`.
|
||||
`findSequence([10, 22, 9, 33, 21, 50, 60, 80])` dovrebbe restituire `[10, 22, 33, 50, 60, 80]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(findSequence([10, 22, 9, 33, 21, 50, 60, 80]), [
|
||||
@ -71,7 +71,7 @@ assert.deepEqual(findSequence([10, 22, 9, 33, 21, 50, 60, 80]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`findSequence([0, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])` should return `[0, 2, 6, 9, 11, 15`.
|
||||
`findSequence([0, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15])` dovrebbe restituire `[0, 2, 6, 9, 11, 15`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dd14192286d95fc43046e
|
||||
title: Longest string challenge
|
||||
title: Sfida della stringa più lunga
|
||||
challengeType: 5
|
||||
forumTopicId: 385275
|
||||
dashedName: longest-string-challenge
|
||||
@ -8,27 +8,27 @@ dashedName: longest-string-challenge
|
||||
|
||||
# --description--
|
||||
|
||||
In this challenge, you have to find the strings that are the longest among the given strings.
|
||||
In questa sfida, devi trovare le stringhe che sono le più lunghe tra le stringhe date.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of strings and returns the strings that have a length equal to the longest length.
|
||||
Scrivi una funzione che richiede un array di stringhe e restituisce le stringhe che hanno una lunghezza uguale alla lunghezza più lunga.
|
||||
|
||||
# --hints--
|
||||
|
||||
`longestString` should be a function.
|
||||
`longestString` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof longestString == 'function');
|
||||
```
|
||||
|
||||
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` should return a array.
|
||||
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg'])));
|
||||
```
|
||||
|
||||
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` should return `["ccc", "ggg"]'`.
|
||||
`longestString(["a", "bb", "ccc", "ee", "f", "ggg"])` dovrebbe restituire `["ccc", "ggg"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [
|
||||
@ -37,7 +37,7 @@ assert.deepEqual(longestString(['a', 'bb', 'ccc', 'ee', 'f', 'ggg']), [
|
||||
]);
|
||||
```
|
||||
|
||||
`longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"])` should return `["afedg", "sdccc", "efdee", "geegg"]`.
|
||||
`longestString(["afedg", "bb", "sdccc", "efdee", "f", "geegg"])` dovrebbe restituire `["afedg", "sdccc", "efdee", "geegg"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -46,7 +46,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"])` should return `["bhghgb", "fssdrr"]`.
|
||||
`longestString(["a", "bhghgb", "ccc", "efde", "fssdrr", "ggg"])` dovrebbe restituire `["bhghgb", "fssdrr"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -55,7 +55,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"])` should return `["ahgfhg", "bdsfsb", "ggdsfg"]`.
|
||||
`longestString(["ahgfhg", "bdsfsb", "ccc", "ee", "f", "ggdsfg"])` dovrebbe restituire `["ahgfhg", "bdsfsb", "ggdsfg"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -64,7 +64,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"])` should return `["gzzzgg"]`.
|
||||
`longestString(["a", "bbdsf", "ccc", "edfe", "gzzzgg"])` dovrebbe restituire `["gzzzgg"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(longestString(['a', 'bbdsf', 'ccc', 'edfe', 'gzzzgg']), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dd14797f5ce267c2f19d0
|
||||
title: Look-and-say sequence
|
||||
title: Successione Look-and-say
|
||||
challengeType: 5
|
||||
forumTopicId: 385277
|
||||
dashedName: look-and-say-sequence
|
||||
@ -8,64 +8,64 @@ dashedName: look-and-say-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The [Look and say sequence](https://en.wikipedia.org/wiki/Look and say sequence) is a recursively defined sequence of numbers.
|
||||
La successione [Look and say](https://en.wikipedia.org/wiki/Look and say sequence) è una sequenza di numeri definita ricorsivamente.
|
||||
|
||||
Sequence Definition
|
||||
Definizione della successione
|
||||
|
||||
<ul><li>Take a decimal number</li>
|
||||
<li><span>Look</span> at the number, visually grouping consecutive runs of the same digit.</li>
|
||||
<li><span>Say</span> the number, from left to right, group by group; as how many of that digit there are - followed by the digit grouped.</li></ul><span> This becomes the next number of the sequence.</span>
|
||||
<ul><li>Prendi un numero decimale</li>
|
||||
<li><span>Guarda</span> (look) il numero, raggruppando visivamente le successioni consecutive della stessa cifra.</li>
|
||||
<li><span>Leggi</span> (say) il numero, da sinistra a destra, gruppo per gruppo; quante ripetizioni di quella cifra ci sono - seguita dalla cifra raggruppata.</li></ul><span> Questo diventa il numero successivo della successione.</span>
|
||||
|
||||
An example:
|
||||
Un esempio:
|
||||
|
||||
<ul><li>Starting with the number 1, you have <span>one</span> 1 which produces 11</li>
|
||||
<li>Starting with 11, you have <span>two</span> 1's. I.E.: 21</li>
|
||||
<li>Starting with 21, you have <span>one</span> 2, then <span>one</span> 1. I.E.: (12)(11) which becomes 1211</li>
|
||||
<li>Starting with 1211, you have <span>one</span> 1, <span>one</span> 2, then <span>two</span> 1's. I.E.: (11)(12)(21) which becomes 111221</li></ul>
|
||||
<ul><li>A partire dal numero 1, hai <span>un</span> 1 che produce 11</li>
|
||||
<li>A partire da 11, hai <span>due</span> 1. Cioè: 21</li>
|
||||
<li>A partire da 21, hai <span>un</span> 2, poi <span>un</span> 1. Cioè: (12)(11) che diventa 1211</li>
|
||||
<li>A partire da 1211, hai <span>un</span> 1, <span>un</span> 2, poi <span>due</span> 1. Cioè: (11)(12)(21) che diventa 111221</li></ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that accepts a string as a parameter, processes it, and returns the resultant string.
|
||||
Scrivi una funzione che accetta una stringa come parametro, la elabora e restituisce la stringa risultante.
|
||||
|
||||
# --hints--
|
||||
|
||||
`lookAndSay` should be a function.
|
||||
`lookAndSay` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof lookAndSay == 'function');
|
||||
```
|
||||
|
||||
`lookAndSay("1")` should return a string.
|
||||
`lookAndSay("1")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof lookAndSay('1') == 'string');
|
||||
```
|
||||
|
||||
`lookAndSay("1")` should return `"11"`.
|
||||
`lookAndSay("1")` dovrebbe restituire `"11"`.
|
||||
|
||||
```js
|
||||
assert.equal(lookAndSay('1'), '11');
|
||||
```
|
||||
|
||||
`lookAndSay("11")` should return `"21"`.
|
||||
`lookAndSay("11")` dovrebbe restituire `"21"`.
|
||||
|
||||
```js
|
||||
assert.equal(lookAndSay('11'), '21');
|
||||
```
|
||||
|
||||
`lookAndSay("21")` should return `"1211"`.
|
||||
`lookAndSay("21")` dovrebbe restituire `"1211"`.
|
||||
|
||||
```js
|
||||
assert.equal(lookAndSay('21'), '1211');
|
||||
```
|
||||
|
||||
`lookAndSay("1211")` should return `"111221"`.
|
||||
`lookAndSay("1211")` dovrebbe restituire `"111221"`.
|
||||
|
||||
```js
|
||||
assert.equal(lookAndSay('1211'), '111221');
|
||||
```
|
||||
|
||||
`lookAndSay("3542")` should return `"13151412"`.
|
||||
`lookAndSay("3542")` dovrebbe restituire `"13151412"`.
|
||||
|
||||
```js
|
||||
assert.equal(lookAndSay('3542'), '13151412');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dd15004c88cf00d2a78b3
|
||||
title: Loop over multiple arrays simultaneously
|
||||
title: Iterare su più matrici simultaneamente
|
||||
challengeType: 5
|
||||
forumTopicId: 385279
|
||||
dashedName: loop-over-multiple-arrays-simultaneously
|
||||
@ -8,15 +8,15 @@ dashedName: loop-over-multiple-arrays-simultaneously
|
||||
|
||||
# --description--
|
||||
|
||||
Loop over multiple arrays and create a new array whose $i^{th}$ element is the concatenation of $i^{th}$ element of each of the given.
|
||||
Itera su più array e crea un nuovo array il cui elemento $i^{mo}$ è la concatenazione dell'$i^{mo}$ elemento di ciascuno dei dati forniti.
|
||||
|
||||
For this example, if you are given this array of arrays:
|
||||
Per questo esempio, se le viene dato questo array di array:
|
||||
|
||||
```js
|
||||
[ ["a", "b", "c"], ["A", "B", "C"], [1, 2, 3] ]
|
||||
```
|
||||
|
||||
the output should be:
|
||||
l'output dovrebbe essere:
|
||||
|
||||
```js
|
||||
["aA1","bB2","cC3"]
|
||||
@ -24,17 +24,17 @@ the output should be:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of arrays as a parameter and returns an array of strings satisfying the given description.
|
||||
Scrivi una funzione che prende un array di array come parametro e restituisce un array di stringhe che soddisfano la descrizione data.
|
||||
|
||||
# --hints--
|
||||
|
||||
`loopSimult` should be a function.
|
||||
`loopSimult` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof loopSimult == 'function');
|
||||
```
|
||||
|
||||
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` should return a array.
|
||||
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -48,7 +48,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` should return `["aA1", "bB2", "cC3"]`.
|
||||
`loopSimult([["a", "b", "c"], ["A", "B", "C"], [1, 2, 3]])` dovrebbe restituire `["aA1", "bB2", "cC3"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -61,7 +61,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`loopSimult([["c", "b", "c"], ["4", "5", "C"], [7, 7, 3]])` should return `["c47", "b57", "cC3"]`.
|
||||
`loopSimult([["c", "b", "c"], ["4", "5", "C"], [7, 7, 3]])` dovrebbe restituire `["c47", "b57", "cC3"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -74,7 +74,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`loopSimult([["a", "b", "c", "d"], ["A", "B", "C", "d"], [1, 2, 3, 4]])` should return `["aA1", "bB2", "cC3", "dd4"]`.
|
||||
`loopSimult([["a", "b", "c", "d"], ["A", "B", "C", "d"], [1, 2, 3, 4]])` dovrebbe restituire `["aA1", "bB2", "cC3", "dd4"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -87,7 +87,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`loopSimult([["a", "b"], ["A", "B"], [1, 2]])` should return `["aA1", "bB2"]`.
|
||||
`loopSimult([["a", "b"], ["A", "B"], [1, 2]])` dovrebbe restituire `["aA1", "bB2"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -100,7 +100,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`loopSimult([["b", "c"], ["B", "C"], [2, 3]])` should return `["bB2", "cC3"]`.
|
||||
`loopSimult([["b", "c"], ["B", "C"], [2, 3]])` dovrebbe restituire `["bB2", "cC3"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6decd8ec8d7db960950d1c
|
||||
title: LU decomposition
|
||||
title: Scomposizione LU
|
||||
challengeType: 5
|
||||
forumTopicId: 385280
|
||||
dashedName: lu-decomposition
|
||||
@ -8,21 +8,21 @@ dashedName: lu-decomposition
|
||||
|
||||
# --description--
|
||||
|
||||
Every square matrix $A$ can be decomposed into a product of a lower triangular matrix $L$ and a upper triangular matrix $U$, as described in [LU decomposition](https://en.wikipedia.org/wiki/LU decomposition).
|
||||
Ogni matrice quadrata $A$ può essere scomposta in un prodotto di una matrice triangolare inferiore $L$ e una matrice triangolare superiore $U$, come descritto in [decomposizione LU](https://it.wikipedia.org/wiki/Decomposizione_LU).
|
||||
|
||||
$A = LU$
|
||||
|
||||
It is a modified form of Gaussian elimination.
|
||||
È una forma modificata di eliminazione gaussiana.
|
||||
|
||||
While the [Cholesky decomposition](http://rosettacode.org/wiki/Cholesky decomposition) only works for symmetric, positive definite matrices, the more general LU decomposition works for any square matrix.
|
||||
Mentre la decomposizione [Cholesky](http://rosettacode.org/wiki/Cholesky decomposition) funziona solo per matrici definite simmetriche e positive, la decomposizione LU più generale funziona per qualsiasi matrice quadrata.
|
||||
|
||||
There are several algorithms for calculating $L$ and $U$.
|
||||
Ci sono diversi algoritmi per calcolare $L$ e $U$.
|
||||
|
||||
To derive *Crout's algorithm* for a 3x3 example, we have to solve the following system:
|
||||
Per ricavare l'algoritmo *di Crout* per un esempio 3x3, dobbiamo risolvere il seguente sistema:
|
||||
|
||||
\\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix}= \\begin{pmatrix} l\_{11} & 0 & 0 \\\\ l\_{21} & l\_{22} & 0 \\\\ l\_{31} & l\_{32} & l\_{33}\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = LU\\end{align}
|
||||
|
||||
We now would have to solve 9 equations with 12 unknowns. To make the system uniquely solvable, usually the diagonal elements of $L$ are set to 1
|
||||
Ora dovremmo risolvere 9 equazioni con 12 incognite. Per rendere il sistema unicamente risolvibile, di solito gli elementi diagonali di $L$ sono impostati a 1
|
||||
|
||||
$l\_{11}=1$
|
||||
|
||||
@ -30,11 +30,11 @@ $l\_{22}=1$
|
||||
|
||||
$l\_{33}=1$
|
||||
|
||||
so we get a solvable system of 9 unknowns and 9 equations.
|
||||
così otteniamo un sistema risolvibile con 9 equazioni e 9 incognite.
|
||||
|
||||
\\begin{align}A = \\begin{pmatrix} a\_{11} & a\_{12} & a\_{13}\\\\ a\_{21} & a\_{22} & a\_{23}\\\\ a\_{31} & a\_{32} & a\_{33}\\\\ \\end{pmatrix} = \\begin{pmatrix} 1 & 0 & 0 \\\\ l\_{21} & 1 & 0 \\\\ l\_{31} & l\_{32} & 1\\\\ \\end{pmatrix} \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ 0 & u\_{22} & u\_{23} \\\\ 0 & 0 & u\_{33} \\end{pmatrix} = \\begin{pmatrix} u\_{11} & u\_{12} & u\_{13} \\\\ u\_{11}l\_{21} & u\_{12}l\_{21}+u\_{22} & u\_{13}l\_{21}+u\_{23} \\\\ u\_{11}l\_{31} & u\_{12}l\_{31}+u\_{22}l\_{32} & u\_{13}l\_{31} + u\_{23}l\_{32}+u\_{33} \\end{pmatrix} = LU\\end{align}
|
||||
|
||||
Solving for the other $l$ and $u$, we get the following equations:
|
||||
Risolvendo gli altri $l$ e $u$, otteniamo le seguenti equazioni:
|
||||
|
||||
$u\_{11}=a\_{11}$
|
||||
|
||||
@ -48,7 +48,7 @@ $u\_{23}=a\_{23} - u\_{13}l\_{21}$
|
||||
|
||||
$u\_{33}=a\_{33} - (u\_{13}l\_{31} + u\_{23}l\_{32})$
|
||||
|
||||
and for $l$:
|
||||
e per $l$:
|
||||
|
||||
$l\_{21}=\\frac{1}{u\_{11}} a\_{21}$
|
||||
|
||||
@ -56,41 +56,41 @@ $l\_{31}=\\frac{1}{u\_{11}} a\_{31}$
|
||||
|
||||
$l\_{32}=\\frac{1}{u\_{22}} (a\_{32} - u\_{12}l\_{31})$
|
||||
|
||||
We see that there is a calculation pattern, which can be expressed as the following formulas, first for $U$
|
||||
Vediamo che esiste un modello di calcolo, che può essere espresso come le seguenti formule, prima per $U$
|
||||
|
||||
$u\_{ij} = a\_{ij} - \\sum\_{k=1}^{i-1} u\_{kj}l\_{ik}$
|
||||
|
||||
and then for $L$
|
||||
e poi per $L$
|
||||
|
||||
$l\_{ij} = \\frac{1}{u\_{jj}} (a\_{ij} - \\sum\_{k=1}^{j-1} u\_{kj}l\_{ik})$
|
||||
|
||||
We see in the second formula that to get the $l\_{ij}$ below the diagonal, we have to divide by the diagonal element (pivot) $u\_{jj}$, so we get problems when $u\_{jj}$ is either 0 or very small, which leads to numerical instability.
|
||||
Vediamo nella seconda formula che per ottenere $l\_{ij}$ sotto la diagonale, dobbiamo dividere per l'elemento diagonale (pivot) $u\_{jj}$, così abbiamo problemi quando $u\_{jj}$ è 0 o molto piccolo, il che porta all'instabilità numerica.
|
||||
|
||||
The solution to this problem is *pivoting* $A$, which means rearranging the rows of $A$, prior to the $LU$ decomposition, in a way that the largest element of each column gets onto the diagonal of $A$. Rearranging the rows means to multiply $A$ by a permutation matrix $P$:
|
||||
La soluzione a questo problema è il *pivoting* $A$, il che significa riordinare le righe di $A$, prima della scomposizione di $LU$, in un modo che l’elemento più grande di ogni colonna entri nella diagonale di $A$. Riorganizzare le righe significa moltiplicare $A$ per una matrice di permutazione $P$:
|
||||
|
||||
$PA \\Rightarrow A'$
|
||||
|
||||
Example:
|
||||
Esempio:
|
||||
|
||||
\\begin{align} \\begin{pmatrix} 0 & 1 \\\\ 1 & 0 \\end{pmatrix} \\begin{pmatrix} 1 & 4 \\\\ 2 & 3 \\end{pmatrix} \\Rightarrow \\begin{pmatrix} 2 & 3 \\\\ 1 & 4 \\end{pmatrix} \\end{align}
|
||||
|
||||
The decomposition algorithm is then applied on the rearranged matrix so that
|
||||
L'algoritmo di scomposizione viene quindi applicato sulla matrice riarrangiata in modo che
|
||||
|
||||
$PA = LU$
|
||||
|
||||
# --instructions--
|
||||
|
||||
The task is to implement a routine which will take a square nxn matrix $A$ and return a lower triangular matrix $L$, a upper triangular matrix $U$ and a permutation matrix $P$, so that the above equation is fullfilled. The returned value should be in the form `[L, U, P]`.
|
||||
Il compito è quello di implementare una routine che richiederà una matrice quadrata nxn $A$ e restituirà una matrice triangolare inferiore $L$, una matrice triangolare superiore $U$ e una matrice di permutazione $P$, in modo che l'equazione di cui sopra sia soddisfatta. Il valore restituito dovrebbe essere nella forma `[L, U, P]`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`luDecomposition` should be a function.
|
||||
`luDecomposition` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof luDecomposition == 'function');
|
||||
```
|
||||
|
||||
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` should return a array.
|
||||
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -104,7 +104,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` should return `[[[1, 0, 0], [0.5, 1, 0], [0.5, -1, 1]], [[2, 4, 7], [0, 1, 1.5], [0, 0, -2]], [[0, 1, 0], [1, 0, 0], [0, 0, 1]]]`.
|
||||
`luDecomposition([[1, 3, 5], [2, 4, 7], [1, 1, 0]])` dovrebbe restituire `[[[1, 0, 0], [0.5, 1, 0], [0.5, -1, 1]], [[2, 4, 7], [0, 1, 1.5], [0, 0, -2]], [[0, 1, 0], [1, 0, 0], [0, 0, 1]]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -133,7 +133,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`luDecomposition([[11, 9, 24, 2], [1, 5, 2, 6], [3, 17, 18, 1], [2, 5, 7, 1]])` should return `[[[1, 0, 0, 0], [0.2727272727272727, 1, 0, 0], [0.09090909090909091, 0.2875, 1, 0], [0.18181818181818182, 0.23124999999999996, 0.0035971223021580693, 1]], [[11, 9, 24, 2], [0, 14.545454545454547, 11.454545454545455, 0.4545454545454546], [0, 0, -3.4749999999999996, 5.6875], [0, 0, 0, 0.510791366906476]], [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]]`.
|
||||
`luDecomposition([[11, 9, 24, 2], [1, 5, 2, 6], [3, 17, 18, 1], [2, 5, 7, 1]])` dovrebbe restituire `[[1, 0, 0, 0], [0. 7272727272727, 1, 0, 0], [0.0909090909091, 0.2875, 1, 0], [0.1818181818181818182, 0.231249999999996, 0. 035971223021580693, 1]], [[11, 9, 24, 2], [0, 14.5454545454545447, 11.45454545454545455, 0.45454545454546], [0, 0, -3. 74999999996, 5.6875], [0, 0, 0, 0.510791366906476]], [[1, 0, 0, 0], [0, 1, 0], [0, 1, 0], [0, 0, 0, 1]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -166,7 +166,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`luDecomposition([[1, 1, 1], [4, 3, -1], [3, 5, 3]])` should return `[[[1, 0, 0], [0.75, 1, 0], [0.25, 0.09090909090909091, 1]], [[4, 3, -1], [0, 2.75, 3.75], [0, 0, 0.9090909090909091]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
|
||||
`luDecomposition([[1, 1, 1], [4, 3, -1], [3, 5, 3]])` dovrebbe restituire `[[[1, 0, 0], [0.75, 1, 0], [0.25, 0.09090909090909091, 1]], [[4, 3, -1], [0, 2.75, 3.75], [0, 0, 0.9090909090909091]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -195,7 +195,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`luDecomposition([[1, -2, 3], [2, -5, 12], [0, 2, -10]])` should return `[[[1, 0, 0], [0, 1, 0], [0.5, 0.25, 1]], [[2, -5, 12], [0, 2, -10], [0, 0, -0.5]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
|
||||
`luDecomposition([[1, -2, 3], [2, -5, 12], [0, 2, -10]])` dovrebbe restituire `[[[1, 0, 0], [0, 1, 0], [0.5, 0.25, 1]], [[2, -5, 12], [0, 2, -10], [0, 0, -0.5]], [[0, 1, 0], [0, 0, 1], [1, 0, 0]]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e6dee7749a0b85a3f1fc7d5
|
||||
title: Lucas-Lehmer test
|
||||
title: Test di Lucas-Lehmer
|
||||
challengeType: 5
|
||||
forumTopicId: 385281
|
||||
dashedName: lucas-lehmer-test
|
||||
@ -8,57 +8,57 @@ dashedName: lucas-lehmer-test
|
||||
|
||||
# --description--
|
||||
|
||||
Lucas-Lehmer Test: for $p$ an odd prime, the Mersenne number $2^p-1$ is prime if and only if $2^p-1$ divides $S(p-1)$ where $S(n+1)=(S(n))^2-2$, and $S(1)=4$.
|
||||
Test di Lucas-Lehmer: dato $p$ numero primo dispari, il numero di Mersenne $2^p-1$ è primo se e solo se $2^p-1$ divide $S(p-1)$ dove $S(n+1)=(S(n))^2-2$, e $S(1)=4$.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns whether the given Mersenne number is prime or not.
|
||||
Scrivi una funzione che restituisce se il numero Mersenne dato è primo o no.
|
||||
|
||||
# --hints--
|
||||
|
||||
`lucasLehmer` should be a function.
|
||||
`lucasLehmer` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof lucasLehmer == 'function');
|
||||
```
|
||||
|
||||
`lucasLehmer(11)` should return a boolean.
|
||||
`lucasLehmer(11)` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof lucasLehmer(11) == 'boolean');
|
||||
```
|
||||
|
||||
`lucasLehmer(11)` should return `false`.
|
||||
`lucasLehmer(11)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(11), false);
|
||||
```
|
||||
|
||||
`lucasLehmer(15)` should return `false`.
|
||||
`lucasLehmer(15)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(15), false);
|
||||
```
|
||||
|
||||
`lucasLehmer(13)` should return `true`.
|
||||
`lucasLehmer(13)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(13), true);
|
||||
```
|
||||
|
||||
`lucasLehmer(17)` should return `true`.
|
||||
`lucasLehmer(17)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(17), true);
|
||||
```
|
||||
|
||||
`lucasLehmer(19)` should return `true`.
|
||||
`lucasLehmer(19)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(19), true);
|
||||
```
|
||||
|
||||
`lucasLehmer(21)` should return `false`.
|
||||
`lucasLehmer(21)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(lucasLehmer(21), false);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea281203167d2b0bdefca00
|
||||
title: Ludic numbers
|
||||
title: Numeri ludici
|
||||
challengeType: 5
|
||||
forumTopicId: 385282
|
||||
dashedName: ludic-numbers
|
||||
@ -8,91 +8,91 @@ dashedName: ludic-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
[Ludic numbers](https://oeis.org/wiki/Ludic_numbers) are related to prime numbers as they are generated by a sieve quite like the [Sieve of Eratosthenes](https://rosettacode.org/wiki/Sieve_of_Eratosthenes) is used to generate prime numbers.
|
||||
[I numeri ludici](https://oeis.org/wiki/Ludic_numbers) sono legati ai numeri primi perché sono generati da un setaccio come il [Crivello di Eratosthenes](https://rosettacode.org/wiki/Sieve_of_Eratosthenes) è usato per generare numeri primi.
|
||||
|
||||
The first ludic number is 1.
|
||||
Il primo numero ludico è 1.
|
||||
|
||||
To generate succeeding ludic numbers create an array of increasing integers starting from 2.
|
||||
Per generare numeri ludici funzionanti creare un array di numeri interi crescenti a partire da 2.
|
||||
|
||||
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'>2</span> 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...</code>
|
||||
|
||||
(Loop)
|
||||
(Ciclo)
|
||||
|
||||
<ul>
|
||||
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>2</span>.</li>
|
||||
<li>Remove every <strong>2<sup>nd</sup></strong> indexed item from the array (including the first).</li>
|
||||
<li>Prendi il primo membro dell'array risultante come prossimo numero ludico <span style='color:blue;font-weight:bold'>2</span>.</li>
|
||||
<li>Rimuovi ogni <strong>secondo</strong> elemento indicizzato dall'array (incluso il primo).</li>
|
||||
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold;'><s>2</s></span> 3 <s>4</s> 5 <s>6</s> 7 <s>8</s> 9 <s>10</s> 11 <s>12</s> 13 <s>14</s> 15 <s>16</s> 17 <s>18</s> 19 <s>20</s> 21 <s>22</s> 23 <s>24</s> 25 <s>26</s> ...</code>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>(Unrolling a few loops...)</li>
|
||||
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>3</span>.</li>
|
||||
<li>Remove every <strong>3<sup>rd</sup></strong> indexed item from the array (including the first).</li>
|
||||
<li>(Srotolando alcuni cicli...)</li>
|
||||
<li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>3</span>.</li>
|
||||
<li>Rimuovi ogni <strong>terzo</strong> elemento indicizzato dall'array (incluso il primo).</li>
|
||||
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>3</s></span> 5 7 <s>9</s> 11 13 <s>15</s> 17 19 <s>21</s> 23 25 <s>27</s> 29 31 <s>33</s> 35 37 <s>39</s> 41 43 <s>45</s> 47 49 <s>51</s> ...</code>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>5</span>.</li>
|
||||
<li>Remove every <strong>5<sup>th</sup></strong> indexed item from the array (including the first).</li>
|
||||
<li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>5</span>.</li>
|
||||
<li>Rimuovi ogni <strong>quinto</strong> elemento indicizzato dall'array (incluso il primo).</li>
|
||||
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>5</s></span> 7 11 13 17 <s>19</s> 23 25 29 31 <s>35</s> 37 41 43 47 <s>49</s> 53 55 59 61 <s>65</s> 67 71 73 77 ...</code>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>Take the first member of the resultant array as the next ludic number <span style='color:blue;font-weight:bold'>7</span>.</li>
|
||||
<li>Remove every <strong>7<sup>th</sup></strong> indexed item from the array (including the first).</li>
|
||||
<li>Prendi il primo membro dell'array risultante come il prossimo numero ludico <span style='color:blue;font-weight:bold'>7</span>.</li>
|
||||
<li>Rimuovi ogni <strong>settimo</strong> elemento indicizzato dall'array (incluso il primo).</li>
|
||||
<code style='margin-left: 2em;'><span style='color:blue;font-weight:bold'><s>7</s></span> 11 13 17 23 25 29 <s>31</s> 37 41 43 47 53 55 <s>59</s> 61 67 71 73 77 83 <s>85</s> 89 91 97 ...</code>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li><big><b> ... </b></big></li>
|
||||
<li>Take the first member of the current array as the next ludic number <span style='color:blue;font-weight:bold'>L</span>.</li>
|
||||
<li>Remove every <strong>L<sup>th</sup></strong> indexed item from the array (including the first).</li>
|
||||
<li>Prendi il primo membro dell'array corrente come prossimo numero ludico <span style='color:blue;font-weight:bold'>L</span>.</li>
|
||||
<li>Rimuovi ogni elemento indicizzato <strong>L<sup>mo</sup></strong> dall'array (incluso il primo).</li>
|
||||
<li><big><b> ... </b></big></li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns all the ludic numbers less than or equal to the given number.
|
||||
Scrivi una funzione che restituisce tutti i numeri ludici minori o uguali al numero indicato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`ludic` should be a function.
|
||||
`ludic` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof ludic === 'function', '<code>ludic</code> should be a function.');
|
||||
```
|
||||
|
||||
`ludic(2)` should return a array.
|
||||
`ludic(2)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(ludic(2)));
|
||||
```
|
||||
|
||||
`ludic(2)` should return `[1, 2]`.
|
||||
`ludic(2)` dovrebbe restituire `[1, 2]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ludic(2), [1, 2]);
|
||||
```
|
||||
|
||||
`ludic(3)` should return `[1, 2, 3]`.
|
||||
`ludic(3)` dovrebbe restituire `[1, 2, 3]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ludic(3), [1, 2, 3]);
|
||||
```
|
||||
|
||||
`ludic(5)` should return `[1, 2, 3, 5]`.
|
||||
`ludic(5)` dovrebbe restituire `[1, 2, 3, 5]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ludic(5), [1, 2, 3, 5]);
|
||||
```
|
||||
|
||||
`ludic(20)` should return `[1, 2, 3, 5, 7, 11, 13, 17]`.
|
||||
`ludic(20)` dovrebbe restituire `[1, 2, 3, 5, 7, 11, 13, 17]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ludic(20), [1, 2, 3, 5, 7, 11, 13, 17]);
|
||||
```
|
||||
|
||||
`ludic(26)` should return `[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]`.
|
||||
`ludic(26)` dovrebbe restituire `[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ludic(26), [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea28156e79528a9ab248f27
|
||||
title: Luhn test of credit card numbers
|
||||
title: Test di Luhn dei numeri delle carte di credito
|
||||
challengeType: 5
|
||||
forumTopicId: 385284
|
||||
dashedName: luhn-test-of-credit-card-numbers
|
||||
@ -8,22 +8,22 @@ dashedName: luhn-test-of-credit-card-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
The [Luhn test](https://en.wikipedia.org/wiki/Luhn algorithm) is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
|
||||
Il test di [Luhn](https://en.wikipedia.org/wiki/Luhn algorithm) è utilizzato da alcune aziende di carte di credito per distinguere i numeri di carta di credito validi da quella che potrebbe essere una selezione casuale di cifre.
|
||||
|
||||
Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
|
||||
Le società che utilizzano numeri di carta di credito che possono essere convalidati dal test di Luhn hanno numeri che superano il seguente test:
|
||||
|
||||
<ol>
|
||||
<li> Reverse the order of the digits in the number.</li>
|
||||
<li> Take the first, third, ... and every other odd digit in the reversed digits and sum them to form the partial sum s1</li>
|
||||
<li> Taking the second, fourth ... and every other even digit in the reversed digits:</li>
|
||||
<li> Inverte l'ordine delle cifre nel numero.</li>
|
||||
<li> Prende la prima, la terza, ... e ogni altra cifra dispari nelle cifre invertite e le somma per formare la somma parziale s1</li>
|
||||
<li> Prende la seconda, la quarta... e ogni altra cifra pari nelle cifre invertite:</li>
|
||||
<ol>
|
||||
<li>Multiply each digit by two and sum the digits if the answer is greater than nine to form partial sums for the even digits.</li>
|
||||
<li>Sum the partial sums of the even digits to form s2.</li>
|
||||
<li>Moltiplica ogni cifra per due e somma le cifre se la risposta è maggiore di nove per formare somme parziali per le cifre pari.</li>
|
||||
<li>Somma le somme parziali delle cifre pari per formare s2.</li>
|
||||
</ol>
|
||||
<li>If s1 + s2 ends in zero then the original number is in the form of a valid credit card number as verified by the Luhn test.</li>
|
||||
<li>Se s1 + s2 termina in zero allora il numero originale ha la forma di un numero di carta di credito valido, stando alla verifica del test di Luhn.</li>
|
||||
</ol>
|
||||
|
||||
For example, if the trial number is 49927398716:
|
||||
Ad esempio, se il numero da testare è 49927398716:
|
||||
|
||||
```bash
|
||||
Reverse the digits:
|
||||
@ -44,53 +44,53 @@ s1 + s2 = 70 which ends in zero which means that 49927398716 passes the Luhn tes
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that will validate a number with the Luhn test. Return true if it's a valid number. Otherwise, return false.
|
||||
Scrivi una funzione che convaliderà un numero con il test Luhn. Restituisce vero se è un numero valido. Altrimenti, restituisci falso.
|
||||
|
||||
# --hints--
|
||||
|
||||
`luhnTest` should be a function.
|
||||
`luhnTest` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof luhnTest === 'function');
|
||||
```
|
||||
|
||||
`luhnTest("4111111111111111")` should return a boolean.
|
||||
`luhnTest("4111111111111111")` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof luhnTest('4111111111111111') === 'boolean');
|
||||
```
|
||||
|
||||
`luhnTest("4111111111111111")` should return `true`.
|
||||
`luhnTest("4111111111111111")` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('4111111111111111'), true);
|
||||
```
|
||||
|
||||
`luhnTest("4111111111111112")` should return `false`.
|
||||
`luhnTest("4111111111111112")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('4111111111111112'), false);
|
||||
```
|
||||
|
||||
`luhnTest("49927398716")` should return `true`.
|
||||
`luhnTest("49927398716")` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('49927398716'), true);
|
||||
```
|
||||
|
||||
`luhnTest("49927398717")` should return `false`.
|
||||
`luhnTest("49927398717")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('49927398717'), false);
|
||||
```
|
||||
|
||||
`luhnTest("1234567812345678")` should return `false`.
|
||||
`luhnTest("1234567812345678")` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('1234567812345678'), false);
|
||||
```
|
||||
|
||||
`luhnTest("1234567812345670")` should return `true`.
|
||||
`luhnTest("1234567812345670")` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(luhnTest('1234567812345670'), true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea2815a8640bcc6cb7dab3c
|
||||
title: Lychrel numbers
|
||||
title: Numeri di Lychrel
|
||||
challengeType: 5
|
||||
forumTopicId: 385287
|
||||
dashedName: lychrel-numbers
|
||||
@ -9,21 +9,21 @@ dashedName: lychrel-numbers
|
||||
# --description--
|
||||
|
||||
<ol>
|
||||
<li>Take an integer <code>n₀</code>, greater than zero.</li>
|
||||
<li>Form the next number <code>n</code> of the series by reversing <code>n₀</code> and adding it to <code>n₀</code></li>
|
||||
<li>Stop when <code>n</code> becomes palindromic - i.e. the digits of <code>n</code> in reverse order == <code>n</code>.</li>
|
||||
<li>Prendi un numero intero <code>n₀</code> maggiore di zero.</li>
|
||||
<li>Forma il prossimo numero <code>n</code> della serie invertendo <code>n₀</code> e aggiungendolo a <code>n₀</code></li>
|
||||
<li>Termina quando <code>n</code> diventa palindromo - cioè le cifre di <code>n</code> in ordine inverso == <code>n</code>.</li>
|
||||
</ol>
|
||||
|
||||
The above recurrence relation when applied to most starting numbers `n` = 1, 2, ... terminates in a palindrome quite quickly.
|
||||
La relazione di ricorrenza sopra riportata quando applicata alla maggior parte dei numeri iniziali `n` = 1, 2, ... termina in un palindromo abbastanza rapidamente.
|
||||
|
||||
For example if `n₀` = 12 we get:
|
||||
Per esempio se `n₀` = 12 otteniamo:
|
||||
|
||||
```bash
|
||||
12
|
||||
12 + 21 = 33, a palindrome!
|
||||
```
|
||||
|
||||
And if `n₀` = 55 we get:
|
||||
E se `n₀` = 55 otteniamo:
|
||||
|
||||
```bash
|
||||
55
|
||||
@ -31,17 +31,17 @@ And if `n₀` = 55 we get:
|
||||
110 + 011 = 121, a palindrome!
|
||||
```
|
||||
|
||||
Notice that the check for a palindrome happens *after* an addition.
|
||||
Nota che il controllo per un palindromo viene fatto *dopo* una somma.
|
||||
|
||||
Some starting numbers seem to go on forever; the recurrence relation for 196 has been calculated for millions of repetitions forming numbers with millions of digits, without forming a palindrome. These numbers that do not end in a palindrome are called **Lychrel numbers**.
|
||||
Alcuni numeri iniziali sembrano andare avanti per sempre; la relazione di ricorrenza per 196 è stata calcolata per milioni di ripetizioni formando numeri con milioni di cifre, senza formare un palindromo. Questi numeri che non terminano in un palindromo sono chiamati **numeri di Lychrel**.
|
||||
|
||||
For the purposes of this task a Lychrel number is any starting number that does not form a palindrome within 500 (or more) iterations.
|
||||
Ai fini di questo compito un numero di Lychrel è qualsiasi numero iniziale che non forma un palindromo entro 500 (o più) iterazioni.
|
||||
|
||||
**Seed and related Lychrel numbers:**
|
||||
**Seme e numeri di Lychrel correlati:**
|
||||
|
||||
Any integer produced in the sequence of a Lychrel number is also a Lychrel number.
|
||||
Qualsiasi numero intero prodotto nella sequenza di un numero di Lychrel è anche un numero di Lychrel.
|
||||
|
||||
In general, any sequence from one Lychrel number *might* converge to join the sequence from a prior Lychrel number candidate; for example the sequences for the numbers 196 and then 689 begin:
|
||||
In generale, qualsiasi sequenza da un numero di Lychrel *potrebbe* convergere alla sequenza formata da un precedente numero di Lychrel; per esempio le sequenze per i numeri 196 e poi 689 iniziano:
|
||||
|
||||
```bash
|
||||
196
|
||||
@ -58,59 +58,59 @@ In general, any sequence from one Lychrel number *might* converge to join the se
|
||||
...
|
||||
```
|
||||
|
||||
So we see that the sequence starting with 689 converges to, and continues with the same numbers as that for 196.
|
||||
Quindi vediamo che la sequenza a partire da 689 converge e continua con gli stessi numeri di quella del 196.
|
||||
|
||||
Because of this we can further split the Lychrel numbers into true **Seed** Lychrel number candidates, and **Related** numbers that produce no palindromes but have integers in their sequence seen as part of the sequence generated from a lower Lychrel number.
|
||||
A causa di questo possiamo ulteriormente dividere i numeri di Lychrel in veri **Seed** di numeri di Lychrel, e numeri **Correlati** che non producono palindromi ma hanno interi nella loro sequenza visti come parte della sequenza generata da un numero di Lychrel inferiore.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a number as a parameter. Return true if the number is a Lynchrel number. Otherwise, return false. Remember that the iteration limit is 500.
|
||||
Scrivi una funzione che prende un numero come parametro. Restituisce vero se il numero è un numero di Lychrel. Altrimenti, restituisci falso. Ricorda che il limite di iterazioni è 500.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isLychrel` should be a function.
|
||||
`isLychrel` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isLychrel === 'function');
|
||||
```
|
||||
|
||||
`isLychrel(12)` should return a boolean.
|
||||
`isLychrel(12)` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isLychrel(12) === 'boolean');
|
||||
```
|
||||
|
||||
`isLychrel(12)` should return `false`.
|
||||
`isLychrel(12)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(12), false);
|
||||
```
|
||||
|
||||
`isLychrel(55)` should return `false`.
|
||||
`isLychrel(55)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(55), false);
|
||||
```
|
||||
|
||||
`isLychrel(196)` should return `true`.
|
||||
`isLychrel(196)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(196), true);
|
||||
```
|
||||
|
||||
`isLychrel(879)` should return `true`.
|
||||
`isLychrel(879)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(879), true);
|
||||
```
|
||||
|
||||
`isLychrel(44987)` should return `false`.
|
||||
`isLychrel(44987)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(44987), false);
|
||||
```
|
||||
|
||||
`isLychrel(7059)` should return `true`.
|
||||
`isLychrel(7059)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isLychrel(7059), true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5ea2815e364d9a2222ea55f8
|
||||
title: LZW compression
|
||||
title: Compressione LZW
|
||||
challengeType: 5
|
||||
forumTopicId: 385288
|
||||
dashedName: lzw-compression
|
||||
@ -8,29 +8,29 @@ dashedName: lzw-compression
|
||||
|
||||
# --description--
|
||||
|
||||
The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression.
|
||||
L'algoritmo Lempel-Ziv-Welch (LZW) fornisce compressione di dati senza perdite.
|
||||
|
||||
You can read a complete description of it in the [Wikipedia article](https://en.wikipedia.org/wiki/Lempel-Ziv-Welch) on the subject.
|
||||
Puoi leggerne una descrizione completa nell'articolo [Wikipedia](https://en.wikipedia.org/wiki/Lempel-Ziv-Welch) sull'argomento.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes two parameters. The first parameter is a boolean where `true` indicates compress and `false` indicates decompress. The second parameter is either a string or an array to be processed. If it is a string to be compressed, return an array of numbers. If it's an array of numbers to be decompressed, return a string.
|
||||
Scrivi una funzione che prende due parametri. Il primo parametro è un booleano dove `true` indica compressione e `false` indica decompressione. Il secondo parametro è una stringa o un array da elaborare. Se si tratta di una stringa da comprimere, restituisce un array di numeri. Se si tratta di un array di numeri da decomprimere restituisce una stringa.
|
||||
|
||||
# --hints--
|
||||
|
||||
`LZW` should be a function.
|
||||
`LZW` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof LZW === 'function');
|
||||
```
|
||||
|
||||
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` should return a array.
|
||||
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT')));
|
||||
```
|
||||
|
||||
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` should return a string.
|
||||
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -55,7 +55,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` should return `[84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263]`.
|
||||
`LZW(true, "TOBEORNOTTOBEORTOBEORNOT")` dovrebbe restituire `[84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'), [
|
||||
@ -78,7 +78,7 @@ assert.deepEqual(LZW(true, 'TOBEORNOTTOBEORTOBEORNOT'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` should return `"TOBEORNOTTOBEORTOBEORNOT"`.
|
||||
`LZW(false, [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 259, 261, 263])` dovrebbe restituire `"TOBEORNOTTOBEORTOBEORNOT"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -104,7 +104,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`LZW(true, "0123456789")` should return `[48, 49, 50, 51, 52, 53, 54, 55, 56, 57]`.
|
||||
`LZW(true, "0123456789")` dovrebbe restituire `[48, 49, 50, 51, 52, 53, 54, 55, 56, 57]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(LZW(true, '0123456789'), [
|
||||
@ -121,7 +121,7 @@ assert.deepEqual(LZW(true, '0123456789'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`LZW(false, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57])` should return `"0123456789"`.
|
||||
`LZW(false, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57])` dovrebbe restituire `"0123456789"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -130,13 +130,13 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`LZW(true, "BABAABAAA")` should return `[66, 65, 256, 257, 65, 260]`.
|
||||
`LZW(true, "BABAABAAA")` dovrebbe restituire `[66, 65, 256, 257, 65, 260]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(LZW(true, 'BABAABAAA'), [66, 65, 256, 257, 65, 260]);
|
||||
```
|
||||
|
||||
`LZW(false, [66, 65, 256, 257, 65, 260])` should return `"BABAABAAA"`.
|
||||
`LZW(false, [66, 65, 256, 257, 65, 260])` dovrebbe restituire `"BABAABAAA"`.
|
||||
|
||||
```js
|
||||
assert.equal(LZW(false, [66, 65, 256, 257, 65, 260]), 'BABAABAAA');
|
||||
|
@ -8,47 +8,47 @@ dashedName: s-expressions
|
||||
|
||||
# --description--
|
||||
|
||||
[S-Expressions](https://en.wikipedia.org/wiki/S-Expression "wp: S-Expression") are one convenient way to parse and store data.
|
||||
Le [S-Expressions](https://en.wikipedia.org/wiki/S-Expression "wp: S-Expression") sono un modo comodo per analizzare e memorizzare i dati.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats.
|
||||
Scrivi un semplice lettore/analizzatore di S-Expressions che gestisce stringhe, interi e float.
|
||||
|
||||
The function should read a single but nested S-Expression from a string and return it as a (nested) array.
|
||||
La funzione dovrebbe leggere una singola ma annidata S-Espressione da una stringa e restituire un array annidato.
|
||||
|
||||
Newlines and other whitespace may be ignored unless contained within a quoted string.
|
||||
I caratteri di nuova linea e gli altri spazi bianchi possono essere ignorati a meno che non siano contenuti in una stringa tra virgolette.
|
||||
|
||||
"`()`" inside quoted strings are not interpreted, but treated as part of the string.
|
||||
"`()`" all'interno delle stringhe quotate non vengono interpretate, ma trattate come parte della stringa.
|
||||
|
||||
Handling escaped quotes inside a string is optional; thus "`(foo"bar)`" may be treated as a string "`foo"bar`", or as an error.
|
||||
La gestione delle virgolette con escape all'interno di una stringa è facoltativa; quindi "`(foo"bar)`" può essere trattato come una stringa "`foo"bar`", o come un errore.
|
||||
|
||||
For this, the reader need not recognize `\` for escaping, but should, in addition, recognize numbers if the language has appropriate data types.
|
||||
Per questo, il lettore non deve riconoscere `\` per l'escape, ma dovrebbe inoltre riconoscere i numeri se il linguaggio ha tipi di dati appropriati.
|
||||
|
||||
Note that with the exception of `()"` (`\` if escaping is supported) and whitespace, there are no special characters. Anything else is allowed without quotes.
|
||||
Si noti che ad eccezione di `()"` (`\` se è supportato l'escaping) e spazi bianchi, non ci sono caratteri speciali. Qualsiasi altra cosa è consentita senza virgolette.
|
||||
|
||||
The reader should be able to read the following input
|
||||
Il lettore dovrebbe essere in grado di leggere il seguente input
|
||||
|
||||
<pre>((data "quoted data" 123 4.5)
|
||||
(data (!@# (4.5) "(more" "data)")))
|
||||
</pre>
|
||||
|
||||
and turn it into a native data structure. (See the [Pike](https://rosettacode.org/wiki/S-Expressions#Pike "\#Pike"), [Python](https://rosettacode.org/wiki/S-Expressions#Python "\#Python") and [Ruby](https://rosettacode.org/wiki/S-Expressions#Ruby "\#Ruby") implementations for examples of native data structures.)
|
||||
e trasformarlo in una struttura di dati nativa. (Vedi le implementazioni in [Pike](https://rosettacode.org/wiki/S-Expressions#Pike "\#Pike"), [Python](https://rosettacode.org/wiki/S-Expressions#Python "\#Python") e [Ruby](https://rosettacode.org/wiki/S-Expressions#Ruby "\#Ruby") per esempi di strutture di dati native.)
|
||||
|
||||
# --hints--
|
||||
|
||||
`parseSexpr` should be a function.
|
||||
`parseSexpr` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof parseSexpr === 'function');
|
||||
```
|
||||
|
||||
`parseSexpr('(data1 data2 data3)')` should return `['data1', 'data2', 'data3']`
|
||||
`parseSexpr('(data1 data2 data3)')` dovrebbe restituire `['data1', 'data2', 'data3']`
|
||||
|
||||
```js
|
||||
assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
|
||||
```
|
||||
|
||||
`parseSexpr('((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))')` should return `[['data', '"quoted data"', 123, 4.5], ['data', ['!@#', [4.5], '"(more"', '"data)"']]]`.
|
||||
`parseSexpr('((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))')` dovrebbe restituire `[['data', '"quoted data"', 123, 4.5], ['data', ['!@#', [4.5], '"(more"', '"data)"']]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(parseSexpr(basicSExpr), basicSolution);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59da22823d04c95919d46269
|
||||
title: 'Sailors, coconuts and a monkey problem'
|
||||
title: 'Problema dei marinai, scimmie e noci di cocco'
|
||||
challengeType: 5
|
||||
forumTopicId: 302304
|
||||
dashedName: sailors-coconuts-and-a-monkey-problem
|
||||
@ -8,38 +8,38 @@ dashedName: sailors-coconuts-and-a-monkey-problem
|
||||
|
||||
# --description--
|
||||
|
||||
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and then hides "his" one of the five equally sized piles of coconuts and pushes the other four piles together to form a single visible pile of coconuts again and goes to bed. To cut a long story short, each of the sailors in turn gets up once during the night and performs the same actions of dividing the coconut pile into five, finding that one coconut is left over and giving that single remainder coconut to the monkey. In the morning (after the surreptitious and separate action of each of the five sailors during the night), the remaining coconuts are divided into five equal piles for each of the sailors, whereupon it is found that the pile of coconuts divides equally amongst the sailors with no remainder. (Nothing for the monkey in the morning.)
|
||||
Cinque marinai sono naufragati su un'isola e raccolgono un grande mucchio di noci di cocco durante il giorno. Quella notte il primo marinaio si sveglia e decide di prendere la sua prima parte presto, così cerca di dividere il mucchio di noci di cocco ugualmente in cinque pile, ma scopre che c'è un cocco rimasto, così lo lancia ad una scimmia e poi nasconde la "sua" pila di cocco, di pari dimensione, e spinge le altre quattro insieme per formare nuovamente un unico mucchio visibile di noci di cocco e va a letto. Per farla breve, ciascuno dei marinai a sua volta si alza una volta durante la notte ed esegue le stesse azioni di divisione del mucchio di cocco in cinque, scopre che un cocco è rimasto e da quel singolo cocco alla scimmia. Al mattino (dopo l'azione surrettizia e separata di ciascuno dei cinque marinai durante la notte), le noci di cocco restanti sono suddivise in cinque pile uguali per ciascuno dei marinai, dopodiché si scopre che il mucchio di noci di cocco si divide ugualmente tra i marinai senza resto. (Niente per la scimmia al mattino.)
|
||||
|
||||
# --instructions--
|
||||
|
||||
Create a function that returns the minimum possible size of the initial pile of coconuts collected during the day for `N` sailors. **Note:** Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc. can occur in time fitting the story line, so as not to affect the mathematics. **C.f:**
|
||||
Crea una funzione che restituisca la dimensione minima possibile del mucchio iniziale di noci di cocco raccolto durante il giorno per `N` marinai. **Nota:** Naturalmente la storia è raccontata in un mondo in cui la raccolta di qualsiasi quantità di noci di cocco in un giorno e divisioni multiple del mucchio, ecc. possono verificarsi nel tempo della storia, in modo da non influenzare la matematica. **Confronta:**
|
||||
|
||||
<ul>
|
||||
<li><a href="https://www.youtube.com/watch?v=U9qU20VmvaU" target="_blank"> Monkeys and Coconuts - Numberphile</a> (Video) Analytical solution.</li>
|
||||
<li><a href="https://oeis.org/A002021" target="_blank">A002021 Pile of coconuts problem</a> The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).</li>
|
||||
<li><a href="https://oeis.org/A002021" target="_blank">A002021 Problema del mucchio di noci di cocco</a> L'Enciclopedia online delle sequenze di numeri interi. (Anche se alcuni dei suoi riferimenti possono utilizzare la forma alternativa del racconto).</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`splitCoconuts` should be a function.
|
||||
`splitCoconuts` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof splitCoconuts === 'function');
|
||||
```
|
||||
|
||||
`splitCoconuts(5)` should return 3121.
|
||||
`splitCoconuts(5)` dovrebbe restituire 3121.
|
||||
|
||||
```js
|
||||
assert(splitCoconuts(5) === 3121);
|
||||
```
|
||||
|
||||
`splitCoconuts(6)` should return 233275.
|
||||
`splitCoconuts(6)` dovrebbe restituire 233275.
|
||||
|
||||
```js
|
||||
assert(splitCoconuts(6) === 233275);
|
||||
```
|
||||
|
||||
`splitCoconuts(7)` should return 823537.
|
||||
`splitCoconuts(7)` dovrebbe restituire 823537.
|
||||
|
||||
```js
|
||||
assert(splitCoconuts(7) === 823537);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eb3e497b8d6d7f63c5517ea
|
||||
title: Search a list of records
|
||||
title: Cerca in una lista di record
|
||||
challengeType: 5
|
||||
forumTopicId: 385315
|
||||
dashedName: search-a-list-of-records
|
||||
@ -8,51 +8,51 @@ dashedName: search-a-list-of-records
|
||||
|
||||
# --description--
|
||||
|
||||
A record consists of attributes that describe an entity. Each attribute has a name and a value. For example, a person can have an attribute `age` with a value of 25. An important operation on a list of records is to find a record with a particular attribute value.
|
||||
Un record è costituito da attributi che descrivono un'entità. Ogni attributo ha un nome e un valore. Ad esempio, una persona può avere un attributo `age` con un valore di 25. Un'operazione importante su un elenco di record è quella di trovare un record con un particolare valore di attributo.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a string as a parameter. The function should return the index of the item in `list` for which the value of the `name` attribute matches the given string.
|
||||
Scrivi una funzione che prende una stringa come parametro. La funzione dovrebbe restituire l'indice dell'elemento nella `list` per cui il valore dell'attributo `name` combacia con la stringa data.
|
||||
|
||||
# --hints--
|
||||
|
||||
`searchCity` should be a function.
|
||||
`searchCity` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof searchCity === 'function');
|
||||
```
|
||||
|
||||
`searchCity("Dar Es Salaam")` should return a number.
|
||||
`searchCity("Dar Es Salaam")` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof searchCity('Dar Es Salaam') === 'number');
|
||||
```
|
||||
|
||||
`searchCity("Dar Es Salaam")` should return `6`.
|
||||
`searchCity("Dar Es Salaam")` dovrebbe restituire `6`.
|
||||
|
||||
```js
|
||||
assert.equal(searchCity('Dar Es Salaam'), 6);
|
||||
```
|
||||
|
||||
`searchCity("Casablanca")` should return `9`.
|
||||
`searchCity("Casablanca")` dovrebbe restituire `9`.
|
||||
|
||||
```js
|
||||
assert.equal(searchCity('Casablanca'), 9);
|
||||
```
|
||||
|
||||
`searchCity("Cairo")` should return `1`.
|
||||
`searchCity("Cairo")` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(searchCity('Cairo'), 1);
|
||||
```
|
||||
|
||||
`searchCity("Mogadishu")` should return `4`.
|
||||
`searchCity("Mogadishu")` dovrebbe restituire `4`.
|
||||
|
||||
```js
|
||||
assert.equal(searchCity('Mogadishu'), 4);
|
||||
```
|
||||
|
||||
`searchCity("Lagos")` should return `0`.
|
||||
`searchCity("Lagos")` dovrebbe restituire `0`.
|
||||
|
||||
```js
|
||||
assert.equal(searchCity('Lagos'), 0);
|
||||
|
@ -8,7 +8,7 @@ dashedName: sedols
|
||||
|
||||
# --description--
|
||||
|
||||
For each number list of 6-digit [SEDOL](https://en.wikipedia.org/wiki/SEDOL "wp: SEDOL")s, calculate and append the checksum digit. That is, given the input string on the left, your function should return the corresponding string on the right:
|
||||
Per ogni elenco di numeri di 6 cifre [SEDOL](https://en.wikipedia.org/wiki/SEDOL "wp: SEDOL"), calcolare e aggiungere la cifra di checksum. Cioè, data la stringa di input a sinistra, la funzione dovrebbe restituire la stringa corrispondente a destra:
|
||||
|
||||
<pre>
|
||||
710889 => 7108899
|
||||
@ -24,35 +24,35 @@ B0YBKT => B0YBKT7
|
||||
B00030 => B000300
|
||||
</pre>
|
||||
|
||||
Check that each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string. Your function should return `null` on an invalid input.
|
||||
Controllare che ogni input sia formato correttamente, soprattutto per quanto riguarda i caratteri validi consentiti in una stringa SEDOL. La tua funzione dovrebbe restituire `null` per un input non valido.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sedol` should be a function.
|
||||
`sedol` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sedol === 'function');
|
||||
```
|
||||
|
||||
`sedol('a')` should return null.
|
||||
`sedol('a')` dovrebbe restituire null.
|
||||
|
||||
```js
|
||||
assert(sedol('a') === null);
|
||||
```
|
||||
|
||||
`sedol('710889')` should return '7108899'.
|
||||
`sedol('710889')` dovrebbe restituire '7108899'.
|
||||
|
||||
```js
|
||||
assert(sedol('710889') === '7108899');
|
||||
```
|
||||
|
||||
`sedol('BOATER')` should return null.
|
||||
`sedol('BOATER')` dovrebbe restituire null.
|
||||
|
||||
```js
|
||||
assert(sedol('BOATER') === null);
|
||||
```
|
||||
|
||||
`sedol('228276')` should return '2282765'.
|
||||
`sedol('228276')` dovrebbe restituire '2282765'.
|
||||
|
||||
```js
|
||||
assert(sedol('228276') === '2282765');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eaf48389ee512d4d103684b
|
||||
title: Self Describing Numbers
|
||||
title: Numeri autodescrittivi
|
||||
challengeType: 5
|
||||
forumTopicId: 385289
|
||||
dashedName: self-describing-numbers
|
||||
@ -8,52 +8,52 @@ dashedName: self-describing-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
There are several so-called "self describing" or ["self-descriptive"](https://en.wikipedia.org/wiki/Self-descriptive_number) integers.
|
||||
Ci sono diversi cosiddetti interi "auto-descriventi" o ["auto-descrittivi"](https://en.wikipedia.org/wiki/Self-descriptive_number) interi.
|
||||
|
||||
An integer is said to be "self-describing" if it has the property that, when digit positions are labeled 0 to N-1, the digit in each position is equal to the number of times that digit appears in the number.
|
||||
Si dice che un intero è "auto-descritto" se ha la proprietà che, quando le posizioni di cifra sono etichettate da 0 a N-1, la cifra in ogni posizione è uguale al numero di volte che la cifra appare nel numero.
|
||||
|
||||
For example, **2020** is a four-digit self describing number:
|
||||
Ad esempio, **2020** è un numero auto-descrittivo a quattro cifre:
|
||||
|
||||
<ul>
|
||||
<li> position 0 has value 2 and there are two 0s in the number; </li>
|
||||
<li> position 1 has value 0 and there are no 1s in the number; </li>
|
||||
<li> position 2 has value 2 and there are two 2s; </li>
|
||||
<li> position 3 has value 0 and there are zero 3s; </li>
|
||||
<li> la posizione 0 ha il valore 2 e nel numero ci sono due zeri; </li>
|
||||
<li> la posizione 1 ha valore 0 e non ci sono uno nel numero; </li>
|
||||
<li> la posizione 2 ha valore 2 e ci sono due due; </li>
|
||||
<li> la posizione 3 ha valore 0 e ci sono zero tre; </li>
|
||||
</ul>
|
||||
|
||||
Self-describing numbers < 100,000,000 are: 1210, 2020, 21200, 3211000, 42101000.
|
||||
Numeri auto-descriventi < 100.000.000 sono: 1210, 2020, 21200, 3211000, 42101000.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a positive integer as a parameter. If it is self-describing return true. Otherwise, return false.
|
||||
Scrivi una funzione che richiede un intero positivo come parametro. Se è auto-descrittivo restituire vero. Altrimenti, restituisci falso.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isSelfDescribing` should be a function.
|
||||
`isSelfDescribing` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isSelfDescribing == 'function');
|
||||
```
|
||||
|
||||
`isSelfDescribing()` should return a boolean.
|
||||
`isSelfDescribing()` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isSelfDescribing(2020) == 'boolean');
|
||||
```
|
||||
|
||||
`isSelfDescribing(2020)` should return `true`.
|
||||
`isSelfDescribing(2020)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSelfDescribing(2020), true);
|
||||
```
|
||||
|
||||
`isSelfDescribing(3021)` should return `false`.
|
||||
`isSelfDescribing(3021)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSelfDescribing(3021), false);
|
||||
```
|
||||
|
||||
`isSelfDescribing(3211000)` should return `true`.
|
||||
`isSelfDescribing(3211000)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSelfDescribing(3211000), true);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eb3e4a21f462f409d656c73
|
||||
title: Self-referential sequence
|
||||
title: Sequenza autoreferenziale
|
||||
challengeType: 5
|
||||
forumTopicId: 385317
|
||||
dashedName: self-referential-sequence
|
||||
@ -8,41 +8,41 @@ dashedName: self-referential-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
There are several ways to generate a self-referential sequence. One very common one (the [Look-and-say sequence](https://rosettacode.org/wiki/Look-and-say sequence)) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits:
|
||||
Ci sono diversi modi per generare una sequenza autoreferenziale. Uno molto comune (la sequenza [Look-and-say](https://rosettacode.org/wiki/Look-and-say sequence)) è iniziare con un numero intero positivo, quindi generare il termine successivo concatenando gruppi enumerati di cifre simili adiacenti:
|
||||
|
||||
<pre>0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ...</pre>
|
||||
|
||||
The terms generated grow in length geometrically and never converge.
|
||||
I termini generati crescono geometricamente in lunghezza e non convergono mai.
|
||||
|
||||
Another way to generate a self-referential sequence is to summarize the previous term.
|
||||
Un altro modo per generare una sequenza auto-referenziale è quello di riassumere il termine precedente.
|
||||
|
||||
Count how many of each alike digit there is, then concatenate the sum and digit for each of the sorted enumerated digits. Note that the first five terms are the same as for the previous sequence.
|
||||
Conta quante di ogni cifra simile ci sono, quindi concatena la somma e la cifra per ciascuna delle cifre enumerate ordinate. Nota che i primi cinque termini sono gli stessi della sequenza precedente.
|
||||
|
||||
<pre>0, 10, 1110, 3110, 132110, 13123110, 23124110 ...</pre>
|
||||
|
||||
Sort the digits largest to smallest. Do not include counts of digits that do not appear in the previous term.
|
||||
Ordina le cifre da più grandi a più piccole. Non includere i conteggi di cifre che non appaiono nel termine precedente.
|
||||
|
||||
Depending on the seed value, series generated this way always either converge to a stable value or to a short cyclical pattern. (For our purposes, converge means that an element matches a previously seen element.) The sequence shown, with a seed value of 0, converges to a stable value of 1433223110 after 11 iterations. The seed value that converges most quickly is 22. It goes stable after the first element. (The next element is 22, which has been seen before.)
|
||||
A seconda del valore del seme, le serie generate in questo modo convergono sempre a un valore stabile o a un breve modello periodico. (Per i nostri scopi, convergere significa che un elemento corrisponde a un elemento visto precedentemente.) La sequenza mostrata, con un valore di seme di 0, converge ad un valore stabile di 1433223110 dopo 11 iterazioni. Il valore del seme che converge più rapidamente è 22. Diventa stabile dopo il primo elemento. (L'elemento successivo è 22, che è stato visto prima.)
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes the seed value as parameter, generates a self referential sequence until it converges, and returns it as an array.
|
||||
Scrivi una funzione che prende il valore del seme come parametro, genera una sequenza autoreferenziale fino a quando non converge, e la restituisce sotto forma di array.
|
||||
|
||||
# --hints--
|
||||
|
||||
`selfReferential` should be a function.
|
||||
`selfReferential` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof selfReferential === 'function');
|
||||
```
|
||||
|
||||
`selfReferential(40)` should return a array.
|
||||
`selfReferential(40)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(selfReferential(40)));
|
||||
```
|
||||
|
||||
`selfReferential(40)` should return `["40", "1410", "142110", "14123110", "1413124110", "2413125110", "151413224110", "152413225110", "251413324110", "152423224110", "152413423110"]`.
|
||||
`selfReferential(40)` dovrebbe restituire `["40", "1410", "142110", "14123110", "1413124110", "2413125110", "151413224110", "152413225110", "251413324110", "152423224110", "152413423110"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(selfReferential(40), [
|
||||
@ -60,7 +60,7 @@ assert.deepEqual(selfReferential(40), [
|
||||
]);
|
||||
```
|
||||
|
||||
`selfReferential(132110)` should return `["132110", "13123110", "23124110", "1413223110", "1423224110", "2413323110", "1433223110"]`.
|
||||
`selfReferential(132110)` dovrebbe restituire `["132110", "13123110", "23124110", "1413223110", "1423224110", "2413323110", "1433223110"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(selfReferential(132110), [
|
||||
@ -74,7 +74,7 @@ assert.deepEqual(selfReferential(132110), [
|
||||
]);
|
||||
```
|
||||
|
||||
`selfReferential(132211)` should return `["132211", "132231", "232221", "134211", "14131231", "14231241", "24132231", "14233221"]`.
|
||||
`selfReferential(132211)` dovrebbe restituire `["132211", "132231", "232221", "134211", "14131231", "14231241", "24132231", "14233221"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(selfReferential(132211), [
|
||||
@ -89,7 +89,7 @@ assert.deepEqual(selfReferential(132211), [
|
||||
]);
|
||||
```
|
||||
|
||||
`selfReferential(1413223110)` should return `["1413223110", "1423224110", "2413323110", "1433223110"]`.
|
||||
`selfReferential(1413223110)` dovrebbe restituire `["1413223110", "1423224110", "2413323110", "1433223110"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(selfReferential(1413223110), [
|
||||
@ -100,7 +100,7 @@ assert.deepEqual(selfReferential(1413223110), [
|
||||
]);
|
||||
```
|
||||
|
||||
`selfReferential(251413126110)` should return `["251413126110", "16151413225110", "16251413226110", "26151413325110", "16251423225110", "16251413424110", "16153413225110"]`.
|
||||
`selfReferential(251413126110)` dovrebbe restituire `["251413126110", "16151413225110", "16251413226110", "26151413325110", "16251423225110", "16251413424110", "16153413225110"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(selfReferential(251413126110), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eb3e4aa847216613aa81983
|
||||
title: Semiprime
|
||||
title: Semiprimi
|
||||
challengeType: 5
|
||||
forumTopicId: 385318
|
||||
dashedName: semiprime
|
||||
@ -8,83 +8,83 @@ dashedName: semiprime
|
||||
|
||||
# --description--
|
||||
|
||||
Semiprime numbers are natural numbers that are products of exactly two (possibly equal) [prime numbers](https://rosettacode.org/wiki/prime_number).
|
||||
I numeri semiprimi sono numeri naturali che sono il prodotto di esattamente due [numeri primi](https://rosettacode.org/wiki/prime_number) (anche uguali).
|
||||
|
||||
<pre>1679 = 23 x 73</pre>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns true if a number is semiprime, or false if it is not.
|
||||
Scrivi una funzione che restituisce vero se un numero è semiprimo, o falso se non lo è.
|
||||
|
||||
# --hints--
|
||||
|
||||
`isSemiPrime` should be a function.
|
||||
`isSemiPrime` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof isSemiPrime === 'function');
|
||||
```
|
||||
|
||||
`isSemiPrime(100)` should return a boolean.
|
||||
`isSemiPrime(100)` dovrebbe restituire un booleano.
|
||||
|
||||
```js
|
||||
assert(typeof isSemiPrime(100) === 'boolean');
|
||||
```
|
||||
|
||||
`isSemiPrime(100)` should return `false`.
|
||||
`isSemiPrime(100)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(100), false);
|
||||
```
|
||||
|
||||
`isSemiPrime(504)` should return `false`.
|
||||
`isSemiPrime(504)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(504), false);
|
||||
```
|
||||
|
||||
`isSemiPrime(4)` should return `true`.
|
||||
`isSemiPrime(4)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(4), true);
|
||||
```
|
||||
|
||||
`isSemiPrime(46)` should return `true`.
|
||||
`isSemiPrime(46)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(46), true);
|
||||
```
|
||||
|
||||
`isSemiPrime(13)` should return `false`.
|
||||
`isSemiPrime(13)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(13), false);
|
||||
```
|
||||
|
||||
`isSemiPrime(74)` should return `true`.
|
||||
`isSemiPrime(74)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(74), true);
|
||||
```
|
||||
|
||||
`isSemiPrime(1679)` should return `true`.
|
||||
`isSemiPrime(1679)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(1679), true);
|
||||
```
|
||||
|
||||
`isSemiPrime(2)` should return `false`.
|
||||
`isSemiPrime(2)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(2), false);
|
||||
```
|
||||
|
||||
`isSemiPrime(95)` should return `true`.
|
||||
`isSemiPrime(95)` dovrebbe restituire `true`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(95), true);
|
||||
```
|
||||
|
||||
`isSemiPrime(124)` should return `false`.
|
||||
`isSemiPrime(124)` dovrebbe restituire `false`.
|
||||
|
||||
```js
|
||||
assert.equal(isSemiPrime(124), false);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eb3e4af7d0e7b760b46cedc
|
||||
title: Set consolidation
|
||||
title: Consolidazione di insiemi
|
||||
challengeType: 5
|
||||
forumTopicId: 385319
|
||||
dashedName: set-consolidation
|
||||
@ -8,58 +8,58 @@ dashedName: set-consolidation
|
||||
|
||||
# --description--
|
||||
|
||||
Given two sets of items then if any item is common to any set then the result of applying *consolidation* to those sets is a set of sets whose contents is:
|
||||
Dati due set di elementi, se un elemento è comune in comune tra almeno due set allora il risultato di applicare la *consolidazione* a questi set è un set di set il cui contenuto è:
|
||||
|
||||
<ul>
|
||||
<li>The two input sets if no common item exists between the two input sets of items.</li>
|
||||
<li>The single set that is the union of the two input sets if they share a common item.</li>
|
||||
<li>I due set di input se non c'è alcun elemento in comune tra i due set di elementi di input.</li>
|
||||
<li>Il singolo set che è unione dei due set di input se hanno un elemento in comune.</li>
|
||||
</ul>
|
||||
|
||||
Given N sets of items where N > 2 then the result is the same as repeatedly replacing all combinations of two sets by their consolidation until no further consolidation between set pairs is possible. If N < 2 then consolidation has no strict meaning and the input can be returned.
|
||||
Dati N set di elementi done N > 2 allora il risultato è lo stesso di sostituire ripetutamente tutte le combinazioni di due set con la loro consolidazione finché non è più possibile alcuna altra consolidazione tra coppie di set. Se N < 2 allora la consolidazione non ha significatio e l'input può essere restituito.
|
||||
|
||||
Here are some examples:
|
||||
Ecco alcuni esempi:
|
||||
|
||||
**Example 1:**
|
||||
**Esempio 1:**
|
||||
|
||||
Given the two sets `{A,B}` and `{C,D}` then there is no common element between the sets and the result is the same as the input.
|
||||
Dati due set `{A,B}` e `{C,D}` allora non c'è alcun elemento in comune tra i set e il risultato è lo stesso dell'input.
|
||||
|
||||
**Example 2:**
|
||||
**Esempio 2:**
|
||||
|
||||
Given the two sets `{A,B}` and `{B,D}` then there is a common element `B` between the sets and the result is the single set `{B,D,A}`. (Note that order of items in a set is immaterial: `{A,B,D}` is the same as `{B,D,A}` and `{D,A,B}`, etc).
|
||||
Dati due set `{A,B}` e `{B,D}` allora c'è un elemento in comune `B` tra i due set e il risultato è il singolo set `{B,D,A}`. (Nota che l'ordine degli elementi in un set è immateriale: `{A,B,D}` è lo stesso di `{B,D,A}` e di `{D,A,B}`, ecc).
|
||||
|
||||
**Example 3:**
|
||||
**Esempio 3:**
|
||||
|
||||
Given the three sets `{A,B}` and `{C,D}` and `{D,B}` then there is no common element between the sets `{A,B}` and `{C,D}` but the sets `{A,B}` and `{D,B}` do share a common element that consolidates to produce the result `{B,D,A}`. On examining this result with the remaining set, `{C,D}`, they share a common element and so consolidate to the final output of the single set `{A,B,C,D}`
|
||||
Dati tre set `{A,B}` e `{C,D}` e `{D,B}`, non c'è un elemento in comune tra i set `{A,B}` e `{C,D}` ma i set `{A,B}` e `{D,B}` hanno un elemento in comune che consolida per produrre il risultato `{B,D,A}`. Esamindando questo risultato con il set rimanente, `{C,D}`, hanno un elemento in comune e consolidato a formare l'output finale del singolo set `{A,B,C,D}`
|
||||
|
||||
**Example 4:**
|
||||
**Esempio 4:**
|
||||
|
||||
The consolidation of the five sets:
|
||||
Il consolidamento dei cinque gruppi:
|
||||
|
||||
`{H,I,K}`, `{A,B}`, `{C,D}`, `{D,B}`, and `{F,G,H}`
|
||||
`{H,I,K}`, `{A,B}`, `{C,D}`, `{D,B}`, e `{F,G,H}`
|
||||
|
||||
Is the two sets:
|
||||
Risulta nei due set:
|
||||
|
||||
`{A, C, B, D}`, and `{G, F, I, H, K}`
|
||||
`{A, C, B, D}`, e `{G, F, I, H, K}`
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of strings as a parameter. Each string is represents a set with the characters representing the set elements. The function should return a 2D array containing the consolidated sets. Note: Each set should be sorted.
|
||||
Scrivi una funzione che prende un array di stringhe come parametro. Ogni stringa rappresenta un set con i caratteri rappresentando gli elementi del set. La funzione dovrebbe restituire un array 2D contenente i set consolidati. Nota: Ogni set deve essere ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`setConsolidation` should be a function.
|
||||
`setConsolidation` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof setConsolidation === 'function');
|
||||
```
|
||||
|
||||
`setConsolidation(["AB", "CD"])` should return a array.
|
||||
`setConsolidation(["AB", "CD"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(setConsolidation(['AB', 'CD'])));
|
||||
```
|
||||
|
||||
`setConsolidation(["AB", "CD"])` should return `[["C", "D"], ["A", "B"]]`.
|
||||
`setConsolidation(["AB", "CD"])` dovrebbe restituire `[["C", "D"], ["A", "B"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(setConsolidation(['AB', 'CD']), [
|
||||
@ -68,19 +68,19 @@ assert.deepEqual(setConsolidation(['AB', 'CD']), [
|
||||
]);
|
||||
```
|
||||
|
||||
`setConsolidation(["AB", "BD"])` should return `[["A", "B", "D"]]`.
|
||||
`setConsolidation(["AB", "BD"])` dovrebbe restituire `[["A", "B", "D"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(setConsolidation(['AB', 'BD']), [['A', 'B', 'D']]);
|
||||
```
|
||||
|
||||
`setConsolidation(["AB", "CD", "DB"])` should return `[["A", "B", "C", "D"]]`.
|
||||
`setConsolidation(["AB", "CD", "DB"])` dovrebbe restituire `[["A", "B", "C", "D"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(setConsolidation(['AB', 'CD', 'DB']), [['A', 'B', 'C', 'D']]);
|
||||
```
|
||||
|
||||
`setConsolidation(["HIK", "AB", "CD", "DB", "FGH"])` should return `[["F", "G", "H", "I", "K"], ["A", "B", "C", "D"]]`.
|
||||
`setConsolidation(["HIK", "AB", "CD", "DB", "FGH"])` dovrebbe restituire `[["F", "G", "H", "I", "K"], ["A", "B", "C", "D"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(setConsolidation(['HIK', 'AB', 'CD', 'DB', 'FGH']), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5eb3e4b20aa93c437f9e9717
|
||||
title: Set of real numbers
|
||||
title: Insieme di numeri reali
|
||||
challengeType: 5
|
||||
forumTopicId: 385322
|
||||
dashedName: set-of-real-numbers
|
||||
@ -8,7 +8,7 @@ dashedName: set-of-real-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers *a* and *b* where *a* ≤ *b*. There are actually four cases for the meaning of "between", depending on open or closed boundary:
|
||||
Tutti i numeri reali formano l'insieme non numerabile R. Tra i suoi sottoinsiemi, relativamente semplici sono gli insiemi convessi, ciascuno espresso come intervallo tra due numeri reali *a* e *b* dove *a* ≤ *b*. Ci sono in realtà quattro casi per il significato di "tra", a seconda che l'intervallo sia aperto o chiuso:
|
||||
|
||||
<ul>
|
||||
<li>[<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i> ≤ <i>x</i> and <i>x</i> ≤ <i>b</i> }</li>
|
||||
@ -17,52 +17,52 @@ All real numbers form the uncountable set ℝ. Among its subsets, relatively sim
|
||||
<li>(<i>a</i>, <i>b</i>]: {<i>x</i> | <i>a</i> < <i>x</i> and <i>x</i> ≤ <i>b</i> }</li>
|
||||
</ul>
|
||||
|
||||
Note that if *a* = *b*, of the four only \[*a*, *a*] would be non-empty.
|
||||
Nota che se *a* = *b*, dei quattro solo \[*a*, *a*] non sarebbero vuoti.
|
||||
|
||||
**Task**
|
||||
**Compito**
|
||||
|
||||
<ul>
|
||||
<li>Devise a way to represent any set of real numbers, for the definition of "any" in the implementation notes below.</li>
|
||||
<li>Provide methods for these common set operations (<i>x</i> is a real number; <i>A</i> and <i>B</i> are sets):</li>
|
||||
<li>Definisci un modo per rappresentare qualsiasi insieme di numeri reali, per la definizione di "any" nelle note di implementazione qui sotto.</li>
|
||||
<li>Fornisci dei metodi per queste operazioni comuni sugli insiemi (<i>x</i> è un numero reale; <i>A</i> e <i>B</i> sono insiemi):</li>
|
||||
<ul>
|
||||
<li>
|
||||
<i>x</i> ∈ <i>A</i>: determine if <i>x</i> is an element of <i>A</i><br>
|
||||
example: 1 is in [1, 2), while 2, 3, ... are not.
|
||||
<i>x</i> ∈ <i>A</i>: determinare se <i>x</i> è un elemento di <i>A</i><br>
|
||||
esempio: 1 è in [1, 2), mentre 2, 3, . . – non lo sono.
|
||||
</li>
|
||||
<li>
|
||||
<i>A</i> ∪ <i>B</i>: union of <i>A</i> and <i>B</i>, i.e. {<i>x</i> | <i>x</i> ∈ <i>A</i> or <i>x</i> ∈ <i>B</i>}<br>
|
||||
example: [0, 2) ∪ (1, 3) = [0, 3); [0, 1) ∪ (2, 3] = well, [0, 1) ∪ (2, 3]
|
||||
<i>A</i> ∪ <i>B</i>: unione di <i>A</i> e <i>B</i>, cioè {<i>x</i> <unk> <i>x</i> <unk> <i>A</i> oppure <i>x</i> <unk> <i>B</i>}<br>
|
||||
esempio: [0, 2) ∪ (1, 3) = [0, 3; [0, 1) ∪ (2, 3] = pozzo, [0, 1) ∪ (2, 3]
|
||||
</li>
|
||||
<li>
|
||||
<i>A</i> ∩ <i>B</i>: intersection of <i>A</i> and <i>B</i>, i.e. {<i>x</i> | <i>x</i> ∈ <i>A</i> and <i>x</i> ∈ <i>B</i>}<br>
|
||||
example: [0, 2) ∩ (1, 3) = (1, 2); [0, 1) ∩ (2, 3] = empty set
|
||||
<i>A</i> ∩ <i>B</i>: intersezione di <i>A</i> e <i>B</i>, cioè {<i>x</i> | <i>x</i> ∈ <i>A</i> e <i>x</i> ∈ <i>B</i>}<br>
|
||||
esempio: [0, 2) ∩ (1, 3) = (1, 2); [0, 1) ∩ (2, 3] = insieme vuoto
|
||||
</li>
|
||||
<li>
|
||||
<i>A</i> - <i>B</i>: difference between <i>A</i> and <i>B</i>, also written as <i>A</i> \ <i>B</i>, i.e. {<i>x</i> | <i>x</i> ∈ <i>A</i> and <i>x</i> ∉ <i>B</i>}<br>
|
||||
example: [0, 2) − (1, 3) = [0, 1]
|
||||
<i>A</i> - <i>B</i>: differenza tra <i>A</i> e <i>B</i>, anche scritto come <i>A</i> \ <i>B</i>, cioè {<i>x</i> | <i>x</i> ∈ <i>A</i> e <i>x</i> ∉ <unk> <i>B</i>}<br>
|
||||
esempio: [0, 2) - (1, 3) = [0, 1]
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes 2 objects, a string and an array as parameters. The objects represents the set and have attributes: `low`, `high` and `rangeType`.
|
||||
Scrivi una funzione che richiede 2 oggetti, una stringa e un array come parametri. Gli oggetti rappresentano l'insieme e hanno attributi: `low`, `high` e `rangeType`.
|
||||
|
||||
The `rangeType` can have values 0, 1, 2 and 3 for `CLOSED`, `BOTH_OPEN`, `LEFT_OPEN` and `RIGHT_OPEN`, respectively. The function should implement a set using this information.
|
||||
Il `rangeType` può avere valori 0, 1, 2 e 3 per `CLOSED`, `BOTH_OPEN`, `LEFT_OPEN` e `RIGHT_OPEN`, rispettivamente. La funzione dovrebbe implementare un insieme utilizzando queste informazioni.
|
||||
|
||||
The string represents the operation to be performed on the sets. It can be: `"union"`, `"intersect"` and `"subtract"` (difference).
|
||||
La stringa rappresenta l'operazione da eseguire sugli insiemi. Può essere: `"union"`, `"intersect"` e `"subtract"` (differenza).
|
||||
|
||||
After performing the operation, the function should check if the values in the array are present in the resultant set and store a corresponding boolean value to an array. The function should return this array.
|
||||
Dopo aver eseguito l'operazione, la funzione dovrebbe controllare se i valori nell'array sono presenti nell'insieme risultante e memorizzare un valore booleano corrispondente a un array. La funzione dovrebbe restituire questo array.
|
||||
|
||||
# --hints--
|
||||
|
||||
`realSet` should be a function.
|
||||
`realSet` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof realSet == 'function');
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` should return a array.
|
||||
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -77,7 +77,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` should return `[true, false, false]`.
|
||||
`realSet({"low":0, "high":1, "rangeType":2}, {"low":0, "high":2, "rangeType":3}, "union", [1, 2, 3])` dovrebbe restituire `[true, false, false]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -91,7 +91,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":2, "rangeType":3}, {"low":1, "high":2, "rangeType":2}, "intersect", [0, 1, 2])` should return `[false, false, false]`.
|
||||
`realSet({"low":0, "high":2, "rangeType":3}, {"low":1, "high":2, "rangeType":2}, "intersect", [0, 1, 2])` dovrebbe restituire `[false, false, false]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -105,7 +105,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":1}, "subtract", [0, 1, 2])` should return `[true, true, true]`.
|
||||
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":1}, "subtract", [0, 1, 2])` dovrebbe restituire `[true, true, true]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -119,7 +119,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":0}, "subtract", [0, 1, 2])` should return `[false, false, true]`.
|
||||
`realSet({"low":0, "high":3, "rangeType":3}, {"low":0, "high":1, "rangeType":0}, "subtract", [0, 1, 2])` dovrebbe restituire `[false, false, true]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -133,7 +133,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`realSet({"low":0, "high":33, "rangeType":1}, {"low":30, "high":31, "rangeType":0}, "intersect", [30, 31, 32])` should return `[true, true, false]`.
|
||||
`realSet({"low":0, "high":33, "rangeType":1}, {"low":30, "high":31, "rangeType":0}, "intersect", [30, 31, 32])` dovrebbe restituire `[true, true, false]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -8,59 +8,59 @@ dashedName: sha-1
|
||||
|
||||
# --description--
|
||||
|
||||
**SHA-1** or **SHA1** is a one-way hash function; it computes a 160-bit message digest.
|
||||
**SHA-1** o **SHA1** è una funzione di hash unidirezionale; calcola una sintesi (digest) a 160 bit del messaggio.
|
||||
|
||||
SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections.
|
||||
SHA-1 compare spesso nei protocolli di sicurezza; per esempio, molti siti Web HTTPS usano RSA con SHA-1 per proteggere le loro connessioni.
|
||||
|
||||
BitTorrent uses SHA-1 to verify downloads.
|
||||
BitTorrent utilizza SHA-1 per verificare i download.
|
||||
|
||||
Git and Mercurial use SHA-1 digests to identify commits.
|
||||
Git e Mercurial usano i digest SHA-1 per identificare i commit.
|
||||
|
||||
A US government standard, [FIPS 180-1](https://rosettacode.org/wiki/SHA-1/FIPS-180-1), defines SHA-1.
|
||||
Uno standard governativo US, [FIPS 180-1](https://rosettacode.org/wiki/SHA-1/FIPS-180-1), definisce SHA-1.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns the SHA-1 message digest for a given string.
|
||||
Scrivi una funzione che restituisce il digest SHA-1 per una determinata stringa.
|
||||
|
||||
# --hints--
|
||||
|
||||
`SHA1` should be a function.
|
||||
`SHA1` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof SHA1 === 'function');
|
||||
```
|
||||
|
||||
`SHA1("abc")` should return a string.
|
||||
`SHA1("abc")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof SHA1('abc') === 'string');
|
||||
```
|
||||
|
||||
`SHA1("abc")` should return `"a9993e364706816aba3e25717850c26c9cd0d89d"`.
|
||||
`SHA1("abc")` dovrebbe restituire `"a9993e364706816aba3e25717850c26c9cd0d89d"`.
|
||||
|
||||
```js
|
||||
assert.equal(SHA1('abc'), 'a9993e364706816aba3e25717850c26c9cd0d89d');
|
||||
```
|
||||
|
||||
`SHA1("Rosetta Code")` should return `"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"`.
|
||||
`SHA1("Rosetta Code")` dovrebbe restituire `"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"`.
|
||||
|
||||
```js
|
||||
assert.equal(SHA1('Rosetta Code'), '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5');
|
||||
```
|
||||
|
||||
`SHA1("Hello world")` should return `"7b502c3a1f48c8609ae212cdfb639dee39673f5e"`.
|
||||
`SHA1("Hello world")` dovrebbe restituire `"7b502c3a1f48c8609ae212cdfb639dee39673f5e"`.
|
||||
|
||||
```js
|
||||
assert.equal(SHA1('Hello world'), '7b502c3a1f48c8609ae212cdfb639dee39673f5e');
|
||||
```
|
||||
|
||||
`SHA1("Programming")` should return `"d1a946bf8b2f2a7292c250063ee28989d742cd4b"`.
|
||||
`SHA1("Programming")` dovrebbe restituire `"d1a946bf8b2f2a7292c250063ee28989d742cd4b"`.
|
||||
|
||||
```js
|
||||
assert.equal(SHA1('Programming'), 'd1a946bf8b2f2a7292c250063ee28989d742cd4b');
|
||||
```
|
||||
|
||||
`SHA1("is Awesome")` should return `"6537205da59c72b57ed3881843c2d24103d683a3"`.
|
||||
`SHA1("is Awesome")` dovrebbe restituire `"6537205da59c72b57ed3881843c2d24103d683a3"`.
|
||||
|
||||
```js
|
||||
assert.equal(SHA1('is Awesome'), '6537205da59c72b57ed3881843c2d24103d683a3');
|
||||
|
@ -8,27 +8,27 @@ dashedName: sha-256
|
||||
|
||||
# --description--
|
||||
|
||||
The `SHA-2` family is a stronger alternative to `SHA-1`. The main difference between them is the length of the hash. Meaning `SHA-1` provides a shorter code with fewer possibilities for unique combinations. `SHA-2` or `SHA-256` creates a longer and thus more complex hash with more possibilities.
|
||||
La famiglia `SHA-2` è un'alternativa più forte a `SHA-1`. La differenza principale tra loro è la lunghezza dell'hash. Vol dire che `SHA-1` fornisce un codice più breve con meno possibilità di combinazioni uniche. `SHA-2` o `SHA-256` crea un hash più lungo e quindi più complesso con più possibilità.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Research implemenation details and write a function that takes a string as the parameter and returns a hash using `SHA-256`
|
||||
Ricerca i dettagli di implementazione e scrivi una funzione che prende una stringa come parametro e restituisce un hash utilizzando `SHA-256`
|
||||
|
||||
# --hints--
|
||||
|
||||
`SHA256` should be a function.
|
||||
`SHA256` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof SHA256 === 'function');
|
||||
```
|
||||
|
||||
`SHA256("Rosetta code")` should return a string.
|
||||
`SHA256("Rosetta code")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof SHA256('Rosetta code') === 'string');
|
||||
```
|
||||
|
||||
`SHA256("Rosetta code")` should return `"764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf"`.
|
||||
`SHA256("Rosetta code")` dovrebbe restituire `"764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -37,7 +37,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`SHA256("SHA-256 Hash")` should return `"bee8c0cabdcf8c7835f40217dd35a8b0dba9134520e633f1c57285f35ca7ee3e"`.
|
||||
`SHA256("SHA-256 Hash")` dovrebbe restituire `"bee8c0cabdcf8c7835f40217dd35a8b0dba9134520e633f1c57285f35ca7ee3e"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -46,7 +46,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`SHA256("implementation")` should return `"da31012c40330e7e21538e7dd57503b16e8a0839159e96137090cccc9910b171"`.
|
||||
`SHA256("implementation")` dovrebbe restituire `"da31012c40330e7e21538e7dd57503b16e8a0839159e96137090cccc9910b171"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -55,7 +55,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`SHA256("algorithm")` should return `"b1eb2ec8ac9f31ff7918231e67f96e6deda83a9ff33ed2c67443f1df81e5ed14"`.
|
||||
`SHA256("algorithm")` dovrebbe restituire `"b1eb2ec8ac9f31ff7918231e67f96e6deda83a9ff33ed2c67443f1df81e5ed14"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -64,7 +64,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`SHA256("language")` should return `"a4ef304ba42a200bafd78b046e0869af9183f6eee5524aead5dcb3a5ab5f8f3f"`.
|
||||
`SHA256("language")` dovrebbe restituire `"a4ef304ba42a200bafd78b046e0869af9183f6eee5524aead5dcb3a5ab5f8f3f"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7ffe
|
||||
title: Sort an array of composite structures
|
||||
title: Ordina un array di strutture composite
|
||||
challengeType: 5
|
||||
forumTopicId: 302306
|
||||
dashedName: sort-an-array-of-composite-structures
|
||||
@ -8,17 +8,17 @@ dashedName: sort-an-array-of-composite-structures
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that takes an array of objects as a parameter. The function should sort the array according to the 'key' attribute of the objects and return the sorted array.
|
||||
Scrivi una funzione che richiede un array di oggetti come parametro. La funzione dovrebbe ordinare l'array usando l'attributo key degli oggetti e restituire l'array ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sortByKey` should be a function.
|
||||
`sortByKey` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sortByKey == 'function');
|
||||
```
|
||||
|
||||
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` should return an array.
|
||||
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -34,7 +34,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` should return `[{key: 1, value: 42}, {key: 2, value: "bar"}, {key: 3, value: "foo"}, {key: 4, value: "baz"}, {key: 5, value: "another string"}]`.
|
||||
`sortByKey([{key: 3, value: "foo"}, {key: 2, value: "bar"}, {key: 4, value: "baz"}, {key: 1, value: 42}, {key: 5, value: "another string"}])` dovrebbe restituire `[{key: 1, value: 42}, {key: 2, value: "bar"}, {key: 3, value: "foo"}, {key: 4, value: "baz"}, {key: 5, value: "another string"}]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -55,7 +55,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`sortByKey([{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 20, name: "Alice"}, {key: 5, name: "Harry"}])` should return `[{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 5, name: "Harry"}, {key: 20, name: "Alice"}]`.
|
||||
`sortByKey([{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 20, name: "Alice"}, {key: 5, name: "Harry"}])` dovrebbe restituire `[{key: 3, name: "Joe"}, {key: 4, name: "Bill"}, {key: 5, name: "Harry"}, {key: 20, name: "Alice"}]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -74,7 +74,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`sortByKey([{key: 2341, name: "Adam"}, {key: 122, name: "Bernie"}, {key: 19, name: "David"}, {key: 5531, name: "Joe"}, {key: 1234, name: "Walter"}])` should return `[{key: 19, name: "David"}, {key: 122, name: "Bernie"}, {key: 1234, name: "Walter"}, {key: 2341, name: "Adam"}, {key: 5531, name: "Joe"}]`.
|
||||
`sortByKey([{key: 2341, name: "Adam"}, {key: 122, name: "Bernie"}, {key: 19, name: "David"}, {key: 5531, name: "Joe"}, {key: 1234, name: "Walter"}])` dovrebbe restituire `[{key: 19, name: "David"}, {key: 122, name: "Bernie"}, {key: 1234, name: "Walter"}, {key: 2341, name: "Adam"}, {key: 5531, name: "Joe"}]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8000
|
||||
title: Sort disjoint sublist
|
||||
title: Ordina sottoliste disgiunte
|
||||
challengeType: 5
|
||||
forumTopicId: 302307
|
||||
dashedName: sort-disjoint-sublist
|
||||
@ -8,9 +8,9 @@ dashedName: sort-disjoint-sublist
|
||||
|
||||
# --description--
|
||||
|
||||
Given a list of values and a set of integer indices into that value list, the task is to sort the values at the given indices, but preserving the values at indices outside the set of those to be sorted.
|
||||
Dato un elenco di valori e un insieme di indici interi in tale lista di valori, l'attività è quella di ordinare i valori negli indici indicati, ma mantenendo i valori in indici al di fuori dell'insieme di quelli da ordinare.
|
||||
|
||||
Make your function work with the following list of values and set of indices:
|
||||
Fai funzionare la tua funzione con il seguente elenco di valori e set di indici:
|
||||
|
||||
<code>values: [7, <b>6</b>, 5, 4, 3, 2, <b>1</b>, <b>0</b>]</code>
|
||||
|
||||
@ -18,25 +18,25 @@ Make your function work with the following list of values and set of indices:
|
||||
indices(0-based): {6, 1, 7}
|
||||
```
|
||||
|
||||
Where the correct result would be:
|
||||
Dove il risultato corretto sarà:
|
||||
|
||||
<code>[7, <b>0</b>, 5, 4, 3, 2, <b>1</b>, <b>6</b>]</code>.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sortDisjoint` should be a function.
|
||||
`sortDisjoint` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sortDisjoint == 'function');
|
||||
```
|
||||
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` should return an array.
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])));
|
||||
```
|
||||
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` should return `[7, 0, 5, 4, 3, 2, 1, 6]`.
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7])` dovrebbe restituire `[7, 0, 5, 4, 3, 2, 1, 6]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]), [
|
||||
@ -51,7 +51,7 @@ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [6, 1, 7]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6])` should return `[7, 1, 2, 4, 3, 5, 6, 0]`.
|
||||
`sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6])` dovrebbe restituire `[7, 1, 2, 4, 3, 5, 6, 0]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6]), [
|
||||
@ -66,7 +66,7 @@ assert.deepEqual(sortDisjoint([7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 5, 6]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7])` should return `[8, 1, 6, 5, 4, 3, 2, 7]`.
|
||||
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7])` dovrebbe restituire `[8, 1, 6, 5, 4, 3, 2, 7]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7]), [
|
||||
@ -81,7 +81,7 @@ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [6, 1, 7]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6])` should return `[8, 2, 6, 3, 4, 5, 7, 1]`.
|
||||
`sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6])` dovrebbe restituire `[8, 2, 6, 3, 4, 5, 7, 1]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6]), [
|
||||
@ -96,7 +96,7 @@ assert.deepEqual(sortDisjoint([8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 6]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4])` should return `[6, 1, 7, 1, 3, 5, 6]`.
|
||||
`sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4])` dovrebbe restituire `[6, 1, 7, 1, 3, 5, 6]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sortDisjoint([6, 1, 7, 1, 3, 5, 6], [6, 1, 5, 4]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8014
|
||||
title: Sort stability
|
||||
title: Stabilità dell'ordinamento
|
||||
challengeType: 5
|
||||
forumTopicId: 302308
|
||||
dashedName: sort-stability
|
||||
@ -8,9 +8,9 @@ dashedName: sort-stability
|
||||
|
||||
# --description--
|
||||
|
||||
When sorting records in a table by a particular column or field, a [stable sort](https://en.wikipedia.org/wiki/Stable_sort#Stability) will always retain the relative order of records that have the same key.
|
||||
Quando si ordinano i record in una tabella per una particolare colonna o campo, un [ordinamento stabile](https://en.wikipedia.org/wiki/Stable_sort#Stability) manterrà sempre l'ordine relativo dei record che hanno la stessa chiave.
|
||||
|
||||
For example, in this table of countries and cities, a stable sort on the **second** column, the cities, would keep the US Birmingham above the UK Birmingham. (Although an unstable sort *might*, in this case, place the US Birmingham above the UK Birmingham, a stable sort routine would *guarantee* it).
|
||||
Ad esempio, in questa tabella di paesi e città, un ordinamento stabile sulla **seconda** colonna, le città, manterrebbe US Birmingham sopra UK Birmingham. (Anche se un ordinamento instabile *potrebbe*, in questo caso, posizionare US Birmingham sopra UK Birmingham, un ordinamento stabile lo *garantirebbe* esso).
|
||||
|
||||
<pre>UK London
|
||||
US New York
|
||||
@ -18,21 +18,21 @@ US Birmingham
|
||||
UK Birmingham
|
||||
</pre>
|
||||
|
||||
Similarly, stable sorting on just the first column would generate "UK London" as the first item and "US Birmingham" as the last item (since the order of the elements having the same first word – "UK" or "US" – would be maintained).
|
||||
Allo stesso modo, l'ordinamento stabile fatto solo sulla prima colonna genererebbe "UK London" come primo elemento e "US Birmingham" come ultimo elemento (perché l'ordine degli elementi con la stessa prima parola – "UK" o "US" – sarebbe mantenuto).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a 2D array as a parameter. Each element has 2 elements similar to the above example. The function should sort the array as mentioned previously and return the sorted array.
|
||||
Scrivi una funzione che richiede un array bidimensionale come parametro. Ogni elemento ha 2 elementi simili all'esempio precedente. La funzione dovrebbe ordinare l'array come menzionato precedentemente e restituire l'array ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`stableSort` should be a function.
|
||||
`stableSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof stableSort == 'function');
|
||||
```
|
||||
|
||||
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` should return an array.
|
||||
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -47,7 +47,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` should return `[["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]]`.
|
||||
`stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])` dovrebbe restituire `[["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -66,7 +66,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`stableSort([[2, 2], [1, 2], [1, 4], [1, 5]])` should return `[[2, 2], [1, 2], [1, 4], [1, 5]]`.
|
||||
`stableSort([[2, 2], [1, 2], [1, 4], [1, 5]])` dovrebbe restituire `[[2, 2], [1, 2], [1, 4], [1, 5]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -85,7 +85,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`stableSort([[11, 55], [12, 45], [11, 45], [32, 45]])` should return `[[12, 45], [11, 45], [32, 45], [11, 55]]`.
|
||||
`stableSort([[11, 55], [12, 45], [11, 45], [32, 45]])` dovrebbe restituire `[[12, 45], [11, 45], [32, 45], [11, 55]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -104,7 +104,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`stableSort([[10, 22], [1, 2], [1, 4], [1, 5], [10, 9]])` should return `[[1, 2], [1, 4], [1, 5], [10, 9], [10, 22]]`.
|
||||
`stableSort([[10, 22], [1, 2], [1, 4], [1, 5], [10, 9]])` dovrebbe restituire `[[1, 2], [1, 4], [1, 5], [10, 9], [10, 22]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -125,7 +125,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`stableSort([[55, 54], [12, 22], [31, 43], [31, 54], [10, 49]])` should return `[[12, 22], [31, 43], [10, 49], [55, 54], [31, 54]]`.
|
||||
`stableSort([[55, 54], [12, 22], [31, 43], [31, 54], [10, 49]])` dovrebbe restituire `[[12, 22], [31, 43], [10, 49], [55, 54], [31, 54]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8016
|
||||
title: Sort using a custom comparator
|
||||
title: Ordina usando un comparatore personalizzato
|
||||
challengeType: 5
|
||||
forumTopicId: 302309
|
||||
dashedName: sort-using-a-custom-comparator
|
||||
@ -8,17 +8,17 @@ dashedName: sort-using-a-custom-comparator
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length.
|
||||
Scrivi una funzione per ordinare un array (o una lista) di stringhe in ordine di lunghezza decrescente, e in ordine lessicografico ascendente per stringhe di uguale lunghezza.
|
||||
|
||||
# --hints--
|
||||
|
||||
`lengthSorter` should be a function.
|
||||
`lengthSorter` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof lengthSorter == 'function');
|
||||
```
|
||||
|
||||
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` should return an array.
|
||||
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -37,7 +37,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` should return `["strings", "sample", "sorted", "Here", "some", "are", "be", "to"]`.
|
||||
`lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"])` dovrebbe restituire `["strings", "sample", "sorted", "Here", "some", "are", "be", "to"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -55,7 +55,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`lengthSorter(["I", "hope", "your", "day", "is", "going", "good", "?"])` should return `["going", "good", "hope", "your", "day", "is", "?","I"]`.
|
||||
`lengthSorter(["I", "hope", "your", "day", "is", "going", "good", "?"])` dovrebbe restituire `["going", "good", "hope", "your", "day", "is", "?","I"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -64,7 +64,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`lengthSorter(["Mine", "is", "going", "great"])` should return `["going", "great", "Mine", "is"]`.
|
||||
`lengthSorter(["Mine", "is", "going", "great"])` dovrebbe restituire `["going", "great", "Mine", "is"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [
|
||||
@ -75,7 +75,7 @@ assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [
|
||||
]);
|
||||
```
|
||||
|
||||
`lengthSorter(["Have", "fun", "sorting", "!!"])` should return `["sorting", "Have", "fun", "!!"]`.
|
||||
`lengthSorter(["Have", "fun", "sorting", "!!"])` dovrebbe restituire `["sorting", "Have", "fun", "!!"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [
|
||||
@ -86,7 +86,7 @@ assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [
|
||||
]);
|
||||
```
|
||||
|
||||
`lengthSorter(["Everything", "is", "good", "!!"])` should return `["Everything", "good", "!!", "is"]`.
|
||||
`lengthSorter(["Everything", "is", "good", "!!"])` dovrebbe restituire `["Everything", "good", "!!", "is"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(lengthSorter(['Everything', 'is', 'good', '!!']), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8001
|
||||
title: Sorting algorithms/Bead sort
|
||||
title: Algoritmi di ordinamento/Bead sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302310
|
||||
dashedName: sorting-algorithmsbead-sort
|
||||
@ -8,47 +8,47 @@ dashedName: sorting-algorithmsbead-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Sort an array of positive integers using the [Bead Sort Algorithm](https://en.wikipedia.org/wiki/Bead_sort).
|
||||
Ordina un array di interi positivi usando l'[Algoritmo di ordinamento Bead Sort](https://en.wikipedia.org/wiki/Bead_sort).
|
||||
|
||||
A *bead sort* is also known as a *gravity sort*.
|
||||
Un *bead sort* è anche conosciuto come un *ordinamento per gravità*.
|
||||
|
||||
The algorithm has O(S), where S is the sum of the integers in the input set: Each bead is moved individually.
|
||||
L'algoritmo ha complessità O(S), dove S è la somma degli interi nel set di ingresso: Ogni perla viene spostata singolarmente.
|
||||
|
||||
This is the case when bead sort is implemented without a mechanism to assist in finding empty spaces below the beads, such as in software implementations.
|
||||
Questo è il caso in cui Bead Sort è implementato senza un meccanismo per aiutare a trovare spazi vuoti sotto le perle, ad esempio nelle implementazioni software.
|
||||
|
||||
# --hints--
|
||||
|
||||
`beadSort` should be a function.
|
||||
`beadSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof beadSort == 'function');
|
||||
```
|
||||
|
||||
`beadSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`beadSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(beadSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`beadSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`beadSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(beadSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`beadSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`beadSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(beadSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`beadSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`beadSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(beadSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`beadSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`beadSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(beadSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -62,7 +62,7 @@ assert.deepEqual(beadSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`beadSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`beadSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(beadSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8002
|
||||
title: Sorting algorithms/Bogosort
|
||||
title: Algoritmi di ordinamento/Bogosort
|
||||
challengeType: 5
|
||||
forumTopicId: 302311
|
||||
dashedName: sorting-algorithmsbogosort
|
||||
@ -8,17 +8,17 @@ dashedName: sorting-algorithmsbogosort
|
||||
|
||||
# --description--
|
||||
|
||||
[Bogosort](https://en.wikipedia.org/wiki/Bogosort) a list of numbers.
|
||||
[Bogosort](https://en.wikipedia.org/wiki/Bogosort) un elenco di numeri.
|
||||
|
||||
Bogosort simply shuffles a collection randomly until it is sorted.
|
||||
Bogosort mescola semplicemente una raccolta in modo casuale fino a quando non viene ordinata.
|
||||
|
||||
"Bogosort" is a perversely inefficient algorithm only used as an in-joke.
|
||||
"Bogosort" è un algoritmo perversamente inefficiente usato solo come presa in giro.
|
||||
|
||||
Its average run-time is O(n!) because the chance that any given shuffle of a set will end up in sorted order is about one in *n* factorial, and the worst case is infinite since there's no guarantee that a random shuffling will ever produce a sorted sequence.
|
||||
La sua durata media è O(n!) perché la possibilità che qualsiasi mescolamento di un set finisca con un set ordinato è di circa uno su *n* fattoriale, e il caso peggiore è infinito dal momento che non c'è garanzia che un mescolamento casuale mai produrrà una sequenza ordinata.
|
||||
|
||||
Its best case is O(n) since a single pass through the elements may suffice to order them.
|
||||
Il suo caso migliore è O(n) poiché un singolo passaggio attraverso gli elementi può essere sufficiente per ordinarli.
|
||||
|
||||
Pseudocode:
|
||||
Pseudocodice:
|
||||
|
||||
<pre><b>while not</b> InOrder(list) <b>do</b>
|
||||
Shuffle(list)
|
||||
@ -27,37 +27,37 @@ Pseudocode:
|
||||
|
||||
# --hints--
|
||||
|
||||
`bogosort` should be a function.
|
||||
`bogosort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof bogosort == 'function');
|
||||
```
|
||||
|
||||
`bogosort([25, 32, 12, 7, 20])` should return an array.
|
||||
`bogosort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(bogosort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`bogosort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`bogosort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(bogosort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`bogosort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`bogosort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(bogosort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`bogosort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`bogosort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(bogosort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`bogosort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`bogosort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(bogosort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -71,7 +71,7 @@ assert.deepEqual(bogosort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`bogosort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`bogosort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(bogosort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8004
|
||||
title: Sorting algorithms/Cocktail sort
|
||||
title: Algoritmi di Ordinamento/Cocktail Sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302312
|
||||
dashedName: sorting-algorithmscocktail-sort
|
||||
@ -8,7 +8,7 @@ dashedName: sorting-algorithmscocktail-sort
|
||||
|
||||
# --description--
|
||||
|
||||
The cocktail shaker sort is an improvement on the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). The improvement is basically that values "bubble" both directions through the array, because on each iteration the cocktail shaker sort bubble sorts once forwards and once backwards. Pseudocode for the algorithm (from [wikipedia](https://en.wikipedia.org/wiki/Cocktail sort)):
|
||||
L'algoritmo cocktail shaker sort è un miglioramento rispetto a [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort). Il miglioramento è fondamentalmente che valuta "bolle" in entrambe le direzioni attraverso l'array, perché ad ogni iterazione il cocktail shaker ordina le bolle una volta avanti e una volta all'indietro. Pseudocodice per l'algoritmo (da [wikipedia](https://en.wikipedia.org/wiki/Cocktail sort)):
|
||||
|
||||
<pre><b>function</b> <i>cocktailSort</i>( A : list of sortable items )
|
||||
<b>do</b>
|
||||
@ -34,41 +34,41 @@ The cocktail shaker sort is an improvement on the [Bubble Sort](https://rosettac
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that sorts a given array using cocktail sort.
|
||||
Scrivi una funzione che ordina un dato array usando cocktail sort.
|
||||
|
||||
# --hints--
|
||||
|
||||
`cocktailSort` should be a function.
|
||||
`cocktailSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof cocktailSort == 'function');
|
||||
```
|
||||
|
||||
`cocktailSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`cocktailSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(cocktailSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`cocktailSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`cocktailSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(cocktailSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`cocktailSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`cocktailSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(cocktailSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`cocktailSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`cocktailSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(cocktailSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`cocktailSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`cocktailSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -82,7 +82,7 @@ assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`cocktailSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`cocktailSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(cocktailSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8005
|
||||
title: Sorting algorithms/Comb sort
|
||||
title: Algoritmi di Ordinamento/Comb Sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302313
|
||||
dashedName: sorting-algorithmscomb-sort
|
||||
@ -8,30 +8,30 @@ dashedName: sorting-algorithmscomb-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Implement a *comb sort*.
|
||||
Implementa un *comb sort*.
|
||||
|
||||
The **Comb Sort** is a variant of the [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
Il **Comb Sort** è una variante del [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
|
||||
Like the [Shell sort](https://rosettacode.org/wiki/Shell sort), the Comb Sort increases the gap used in comparisons and exchanges.
|
||||
Come lo [Shell sort](https://rosettacode.org/wiki/Shell sort), il Comb Sort aumenta lo spazio utilizzato nei confronti e negli scambi.
|
||||
|
||||
Dividing the gap by $(1-e^{-\\varphi})^{-1} \\approx 1.247330950103979$ works best, but 1.3 may be more practical.
|
||||
Dividere il divario per $(1-e^{-\\varphi})^{-1} \\ca. 1.247330950103979$ funziona meglio, ma 1.3 può essere più pratico.
|
||||
|
||||
Some implementations use the insertion sort once the gap is less than a certain amount.
|
||||
Alcune implementazioni usano l'insertion sort una volta che il divario è inferiore a una certa quantità.
|
||||
|
||||
**Also see**
|
||||
**Vedi anche**
|
||||
|
||||
<ul>
|
||||
<li>the Wikipedia article: <a href='https://en.wikipedia.org/wiki/Comb sort' target='_blank'>Comb sort</a>.</li>
|
||||
<li>l'articolo Wikipedia: <a href='https://en.wikipedia.org/wiki/Comb sort' target='_blank'>Comb sort</a>.</li>
|
||||
</ul>
|
||||
|
||||
Variants:
|
||||
Varianti:
|
||||
|
||||
<ul>
|
||||
<li>Combsort11 makes sure the gap ends in (11, 8, 6, 4, 3, 2, 1), which is significantly faster than the other two possible endings.</li>
|
||||
<li>Combsort with different endings changes to a more efficient sort when the data is almost sorted (when the gap is small). Comb sort with a low gap isn't much better than the Bubble Sort.</li>
|
||||
<li>Combsort11 assicura che il divario finisca in (11, 8, 6, 4, 3, 2, 1), che è significativamente più veloce delle altre due possibili terminazioni.</li>
|
||||
<li>Combsort con diversi terminali diventa un ordinamento più efficiente quando i dati sono quasi del tutto ordinati (quando il divario è piccolo). Combsort con un gap basso non è molto meglio di Bubble Sort.</li>
|
||||
</ul>
|
||||
|
||||
Pseudocode:
|
||||
Pseudocodice:
|
||||
|
||||
<pre><b>function</b> combsort(<b>array</b> input)
|
||||
gap := input<b>.size</b> <i>//initialize gap size</i>
|
||||
@ -59,41 +59,41 @@ Pseudocode:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that sorts a given array using Comb sort.
|
||||
Scrivi una funzione che ordina un determinato array usando Combsort.
|
||||
|
||||
# --hints--
|
||||
|
||||
`combSort` should be a function.
|
||||
`combSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof combSort == 'function');
|
||||
```
|
||||
|
||||
`combSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`combSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(combSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`combSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`combSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(combSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`combSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`combSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(combSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`combSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`combSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(combSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`combSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`combSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -107,7 +107,7 @@ assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`combSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`combSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(combSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8007
|
||||
title: Sorting algorithms/Gnome sort
|
||||
title: Algoritmi di ordinamento/Gnome sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302314
|
||||
dashedName: sorting-algorithmsgnome-sort
|
||||
@ -8,9 +8,9 @@ dashedName: sorting-algorithmsgnome-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Gnome sort is a sorting algorithm which is similar to [Insertion sort](https://rosettacode.org/wiki/Insertion sort), except that moving an element to its proper place is accomplished by a series of swaps, as in [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
Gnome Sort è un algoritmo di ordinamento che è simile a [Insertion Sort](https://rosettacode.org/wiki/Insertion sort), tranne che lo spostamento di un elemento al suo posto corretto è realizzato da una serie di scambi, come in [Bubble Sort](https://rosettacode.org/wiki/Bubble Sort).
|
||||
|
||||
The pseudocode for the algorithm is:
|
||||
Lo pseudocodice per l'algoritmo è:
|
||||
|
||||
<pre><b>function</b> <i>gnomeSort</i>(a[0..size-1])
|
||||
i := 1
|
||||
@ -33,41 +33,41 @@ The pseudocode for the algorithm is:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to implement the above pseudo code. The function should return the sorted array.
|
||||
Scrivi una funzione che implementi lo pseudocodice di cui sopra. La funzione dovrebbe restituire l'array ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`gnomeSort` should be a function.
|
||||
`gnomeSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof gnomeSort == 'function');
|
||||
```
|
||||
|
||||
`gnomeSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`gnomeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(gnomeSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`gnomeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`gnomeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(gnomeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`gnomeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`gnomeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(gnomeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`gnomeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`gnomeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(gnomeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`gnomeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`gnomeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -81,7 +81,7 @@ assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`gnomeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`gnomeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(gnomeSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc800b
|
||||
title: Sorting algorithms/Pancake sort
|
||||
title: Algoritmi di ordinamento/Pancake sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302315
|
||||
dashedName: sorting-algorithmspancake-sort
|
||||
@ -8,51 +8,51 @@ dashedName: sorting-algorithmspancake-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array of integers (of any convenient size) into ascending order using [Pancake sorting](https://en.wikipedia.org/wiki/Pancake sorting). The function should return the sorted array.
|
||||
Scrivi una funzione per ordinare un array di interi (di qualsiasi dimensione conveniente) in ordine crescente usando [Pancake sorting](https://en.wikipedia.org/wiki/Pancake sorting). La funzione dovrebbe restituire l'array ordinato.
|
||||
|
||||
In short, instead of individual elements being sorted, the only operation allowed is to "flip" one end of the list, like so:
|
||||
In breve, invece di ordinare singoli elementi, l'unica operazione consentita è quella di "capovolgere" una estremità della lista in questo modo:
|
||||
|
||||
<pre>Before:
|
||||
<pre>Prima:
|
||||
<b>6 7 8 9</b> 2 5 3 4 1<br>
|
||||
After:
|
||||
Dopo:
|
||||
<b>9 8 7 6</b> 2 5 3 4 1
|
||||
</pre>
|
||||
|
||||
Only one end of the list can be flipped; this should be the low end, but the high end is okay if it's easier to code or works better, but it **must** be the same end for the entire solution. (The end flipped can't be arbitrarily changed.)
|
||||
Solo una fine della lista può essere capovolta; questa dovrebbe essere l'estremità di valore più basso, ma l'estremità alta va comunque bene se è più facile da codificare o funziona meglio, ma essa **deve** essere la stessa estremità per l'intera soluzione. (L'estremità capovolta non può essere cambiata arbitrariamente.)
|
||||
|
||||
# --hints--
|
||||
|
||||
`pancakeSort` should be a function.
|
||||
`pancakeSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof pancakeSort == 'function');
|
||||
```
|
||||
|
||||
`pancakeSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`pancakeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(pancakeSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`pancakeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`pancakeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pancakeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`pancakeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`pancakeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pancakeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`pancakeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`pancakeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pancakeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`pancakeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`pancakeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -66,7 +66,7 @@ assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`pancakeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`pancakeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pancakeSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc800c
|
||||
title: Sorting algorithms/Permutation sort
|
||||
title: Algoritmi di ordinamento/Permutation sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302316
|
||||
dashedName: sorting-algorithmspermutation-sort
|
||||
@ -8,9 +8,9 @@ dashedName: sorting-algorithmspermutation-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to implement a permutation sort, which proceeds by generating the possible permutations of the input array until discovering the sorted one. The function should return the sorted array.
|
||||
Scrivere una funzione per implementare un ordinamento a permutazione, che procede generando le possibili permutazioni dell'array di input fino a trovare quello ordinato. La funzione dovrebbe restituire l'array ordinato.
|
||||
|
||||
Pseudocode:
|
||||
Pseudocodice:
|
||||
|
||||
<pre><b>while not</b> InOrder(list) <b>do</b>
|
||||
nextPermutation(list)
|
||||
@ -19,37 +19,37 @@ Pseudocode:
|
||||
|
||||
# --hints--
|
||||
|
||||
`permutationSort` should be a function.
|
||||
`permutationSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof permutationSort == 'function');
|
||||
```
|
||||
|
||||
`permutationSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`permutationSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(permutationSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`permutationSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`permutationSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(permutationSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`permutationSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`permutationSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(permutationSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`permutationSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`permutationSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(permutationSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`permutationSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`permutationSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -63,7 +63,7 @@ assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`permutationSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`permutationSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(permutationSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8010
|
||||
title: Sorting algorithms/Shell sort
|
||||
title: Algoritmi di ordinamento/Shell Sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302317
|
||||
dashedName: sorting-algorithmsshell-sort
|
||||
@ -8,51 +8,51 @@ dashedName: sorting-algorithmsshell-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array of elements using the [Shell sort](https://en.wikipedia.org/wiki/Shell sort) algorithm, a diminishing increment sort. The function should return the sorted array.
|
||||
Scrivi una funzione per ordinare un array di elementi usando l'algoritmo [Shell sort](https://en.wikipedia.org/wiki/Shell sort), un tipo di ordinamento a incremento in diminuzione. La funzione dovrebbe restituire l'array ordinato.
|
||||
|
||||
The Shell sort (also known as Shellsort or Shell's method) is named after its inventor, Donald Shell, who published the algorithm in 1959.
|
||||
Shell Short (noto anche come metodo di Shellsort o Shell) prende il nome dal suo inventore, Donald Shell, che ha pubblicato l'algoritmo nel 1959.
|
||||
|
||||
Shell sort is a sequence of interleaved insertion sorts based on an increment sequence. The increment size is reduced after each pass until the increment size is 1.
|
||||
Shell Sort è una sequenza di Insertion Sort intercalati basata su una sequenza di incremento. La dimensione dell'incremento viene ridotta dopo ogni passaggio fino a quando la dimensione dell'incremento è 1.
|
||||
|
||||
With an increment size of 1, the sort is a basic insertion sort, but by this time the data is guaranteed to be almost sorted, which is insertion sort's "best case".
|
||||
Con un incremento della dimensione di 1, l'ordinamento è un classico Insertion Sort, ma per questo esercizio i dati sono garantiti essere quasi ordinati, che è il "caso migliore" per Insertion Sort.
|
||||
|
||||
Any sequence will sort the data as long as it ends in 1, but some work better than others.
|
||||
Qualsiasi sequenza ordinerà i dati finché terminerà in 1, ma alcune funzionano meglio di altre.
|
||||
|
||||
Empirical studies have shown a geometric increment sequence with a ratio of about 2.2 work well in practice.
|
||||
Studi empirici hanno mostrato che una sequenza geometrica di incremento con un rapporto di circa 2.2 funziona bene nella pratica.
|
||||
|
||||
# --hints--
|
||||
|
||||
`shellSort` should be a function.
|
||||
`shellSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof shellSort == 'function');
|
||||
```
|
||||
|
||||
`shellSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`shellSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(shellSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`shellSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`shellSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(shellSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`shellSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`shellSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(shellSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`shellSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`shellSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(shellSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`shellSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`shellSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -66,7 +66,7 @@ assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`shellSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`shellSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(shellSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8012
|
||||
title: Sorting algorithms/Stooge sort
|
||||
title: Algoritmi di Ordinamento/Stooge Sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302318
|
||||
dashedName: sorting-algorithmsstooge-sort
|
||||
@ -8,9 +8,9 @@ dashedName: sorting-algorithmsstooge-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to perform [Stooge Sort](https://en.wikipedia.org/wiki/Stooge sort) on an array of integers. The function should return a sorted array.
|
||||
Scrivi una funzione per eseguire lo [Stooge Sort](https://it.wikipedia.org/wiki/Trippel_sort) su un array di interi. La funzione dovrebbe restituire un array ordinato.
|
||||
|
||||
The Stooge Sort algorithm is as follows:
|
||||
L'algoritmo Stooge Sort è il seguente:
|
||||
|
||||
<pre><b>algorithm</b> stoogesort(<b>array</b> L, i = 0, j = <b>length</b>(L)-1)
|
||||
<b>if</b> L[j] < L[i] <b>then</b>
|
||||
@ -25,37 +25,37 @@ The Stooge Sort algorithm is as follows:
|
||||
|
||||
# --hints--
|
||||
|
||||
`stoogeSort` should be a function.
|
||||
`stoogeSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof stoogeSort == 'function');
|
||||
```
|
||||
|
||||
`stoogeSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`stoogeSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(stoogeSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`stoogeSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`stoogeSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(stoogeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`stoogeSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`stoogeSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(stoogeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`stoogeSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`stoogeSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(stoogeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`stoogeSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`stoogeSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -69,7 +69,7 @@ assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`stoogeSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`stoogeSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(stoogeSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8013
|
||||
title: Sorting algorithms/Strand sort
|
||||
title: Algoritmi di ordinamento/Strand sort
|
||||
challengeType: 5
|
||||
forumTopicId: 302319
|
||||
dashedName: sorting-algorithmsstrand-sort
|
||||
@ -8,43 +8,43 @@ dashedName: sorting-algorithmsstrand-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to sort an array using the [Strand sort](https://en.wikipedia.org/wiki/Strand sort). The function should return the sorted array.
|
||||
Scrivi una funzione per ordinare un array usando l'ordinamento [Strand sort](https://en.wikipedia.org/wiki/Strand sort). La funzione dovrebbe restituire l'array ordinato.
|
||||
|
||||
This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list.
|
||||
Questo è un modo di ordinare i numeri estraendo sequenze più brevi di numeri già ordinati da un elenco non ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`strandSort` should be a function.
|
||||
`strandSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof strandSort == 'function');
|
||||
```
|
||||
|
||||
`strandSort([25, 32, 12, 7, 20])` should return an array.
|
||||
`strandSort([25, 32, 12, 7, 20])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(strandSort([25, 32, 12, 7, 20])));
|
||||
```
|
||||
|
||||
`strandSort([25, 32, 12, 7, 20])` should return `[7, 12, 20, 25, 32]`.
|
||||
`strandSort([25, 32, 12, 7, 20])` dovrebbe restituire `[7, 12, 20, 25, 32]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(strandSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32]);
|
||||
```
|
||||
|
||||
`strandSort([38, 45, 35, 8, 13])` should return `[8, 13, 35, 38, 45]`.
|
||||
`strandSort([38, 45, 35, 8, 13])` dovrebbe restituire `[8, 13, 35, 38, 45]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(strandSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45]);
|
||||
```
|
||||
|
||||
`strandSort([43, 36, 20, 34, 24])` should return `[20, 24, 34, 36, 43]`.
|
||||
`strandSort([43, 36, 20, 34, 24])` dovrebbe restituire `[20, 24, 34, 36, 43]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(strandSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43]);
|
||||
```
|
||||
|
||||
`strandSort([12, 33, 26, 18, 1, 16, 38])` should return `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
`strandSort([12, 33, 26, 18, 1, 16, 38])` dovrebbe restituire `[1, 12, 16, 18, 26, 33, 38]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
@ -58,7 +58,7 @@ assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`strandSort([3, 39, 48, 16, 1, 4, 29])` should return `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
`strandSort([3, 39, 48, 16, 1, 4, 29])` dovrebbe restituire `[1, 3, 4, 16, 29, 39, 48]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(strandSort([3, 39, 48, 16, 1, 4, 29]), [
|
||||
|
@ -8,86 +8,86 @@ dashedName: soundex
|
||||
|
||||
# --description--
|
||||
|
||||
Soundex is an algorithm for creating indices for words based on their pronunciation. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling (from [the WP article](https://en.wikipedia.org/wiki/soundex)). There is a major issue in many of the implementations concerning the separation of two consonants that have the same soundex code! According to the [official Rules](https://www.archives.gov/research/census/soundex.html). So check for instance if **Ashcraft** is coded to **A-261**.
|
||||
Soundex è un algoritmo per creare indici per le parole basato sulla loro pronuncia. L'obbiettivo è avere gli omofoni codificati alla stessa rappresentazione così che possano essere combaciati nonostante piccole differenze di ortografia (dall'[articolo di Wikipedia](https://en.wikipedia.org/wiki/soundex)). C'è un problema importante in molte delle implementazioni riguardanti la separazione di due consonanti che hanno lo stesso codice soundex! In accordo con le [regole ufficiali](https://www.archives.gov/research/census/soundex.html). Quindi controlla se per esempio **Ashcraft** è codificato a **A-261**.
|
||||
|
||||
<ul>
|
||||
<li>If a vowel (A, E, I, O, U) separates two consonants that have the same soundex code, the consonant to the right of the vowel is coded. Tymczak is coded as T-522 (T, 5 for the M, 2 for the C, Z ignored (see "Side-by-Side" rule above), 2 for the K). Since the vowel "A" separates the Z and K, the K is coded.</li>
|
||||
<li>If "H" or "W" separate two consonants that have the same soundex code, the consonant to the right of the vowel is not coded. Example: Ashcraft is coded A-261 (A, 2 for the S, C ignored, 6 for the R, 1 for the F). It is not coded A-226.</li>
|
||||
<li>Se una vocale (A, E, I, O, U) separata due consonanti che hanno lo stesso codice soundex, la consonante a destra della vocale è codificata. Tymczak è codificato come T-522 (T, 5 per M, 2 per C, Z ignorata (vedi regola "Fianco-a-fianco" qua sopra), 2 per K). Visto che la "A" separa la Z e la K, la K è codificata.</li>
|
||||
<li>Se "H" o "W" separano due consonanti che hanno lo stesso codice soundex, la consonante alla destra della vocale non è codificata. Per esempio: Ashcraft è codificato come A-261 (A, 2 per S, C ignorata, 6 per R, 1 per F). Non è codificata come A-226.</li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a string as a parameter and returns the encoded string.
|
||||
Scrivi una funzione che prende una stringa come parametro e restituisce la stringa codificata.
|
||||
|
||||
# --hints--
|
||||
|
||||
`soundex` should be a function.
|
||||
`soundex` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof soundex == 'function');
|
||||
```
|
||||
|
||||
`soundex("Soundex")` should return a string.
|
||||
`soundex("Soundex")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof soundex('Soundex') == 'string');
|
||||
```
|
||||
|
||||
`soundex("Soundex")` should return `"S532"`.
|
||||
`soundex("Soundex")` dovrebbe restituire `"S532"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Soundex'), 'S532');
|
||||
```
|
||||
|
||||
`soundex("Example")` should return `"E251"`.
|
||||
`soundex("Example")` dovrebbe restituire `"E251"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Example'), 'E251');
|
||||
```
|
||||
|
||||
`soundex("Sownteks")` should return `"S532"`.
|
||||
`soundex("Sownteks")` dovrebbe restituire `"S532"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Sownteks'), 'S532');
|
||||
```
|
||||
|
||||
`soundex("Ekzampul")` should return `"E251"`.
|
||||
`soundex("Ekzampul")` dovrebbe restituire `"E251"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Ekzampul'), 'E251');
|
||||
```
|
||||
|
||||
`soundex("Euler")` should return `"E460"`.
|
||||
`soundex("Euler")` dovrebbe restituire `"E460"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Euler'), 'E460');
|
||||
```
|
||||
|
||||
`soundex("Gauss")` should return `"G200"`.
|
||||
`soundex("Gauss")` dovrebbe restituire `"G200"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Gauss'), 'G200');
|
||||
```
|
||||
|
||||
`soundex("Hilbert")` should return `"H416"`.
|
||||
`soundex("Hilbert")` dovrebbe restituire `"H416"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Hilbert'), 'H416');
|
||||
```
|
||||
|
||||
`soundex("Knuth")` should return `"K530"`.
|
||||
`soundex("Knuth")` dovrebbe restituire `"K530"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Knuth'), 'K530');
|
||||
```
|
||||
|
||||
`soundex("Lloyd")` should return `"L300"`.
|
||||
`soundex("Lloyd")` dovrebbe restituire `"L300"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Lloyd'), 'L300');
|
||||
```
|
||||
|
||||
`soundex("Lukasiewicz")` should return `"L222"`.
|
||||
`soundex("Lukasiewicz")` dovrebbe restituire `"L222"`.
|
||||
|
||||
```js
|
||||
assert.equal(soundex('Lukasiewicz'), 'L222');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc801c
|
||||
title: Spiral matrix
|
||||
title: Matrice a spirale
|
||||
challengeType: 5
|
||||
forumTopicId: 302321
|
||||
dashedName: spiral-matrix
|
||||
@ -8,7 +8,7 @@ dashedName: spiral-matrix
|
||||
|
||||
# --description--
|
||||
|
||||
Produce a spiral array. A *spiral array* is a square arrangement of the first N<sup>2</sup> natural numbers, where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given **5**, produce this array:
|
||||
Produci un array a spirale. Un *array a spirale* è una disposizione quadrata dei primi numeri naturali N<sup>2</sup>, dove i numeri aumentano in sequenza mentre si percorrono i bordi dell'array a spirale verso l'interno. Per esempio, dato **5**, viene prodotto questo array:
|
||||
|
||||
<pre>
|
||||
0 1 2 3 4
|
||||
@ -20,19 +20,19 @@ Produce a spiral array. A *spiral array* is a square arrangement of the first N<
|
||||
|
||||
# --hints--
|
||||
|
||||
`spiralArray` should be a function.
|
||||
`spiralArray` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof spiralArray == 'function');
|
||||
```
|
||||
|
||||
`spiralArray(3)` should return an array.
|
||||
`spiralArray(3)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(spiralArray(3)));
|
||||
```
|
||||
|
||||
`spiralArray(3)` should return `[[0, 1, 2],[7, 8, 3],[6, 5, 4]]`.
|
||||
`spiralArray(3)` dovrebbe restituire `[[0, 1, 2],[7, 8, 3],[6, 5, 4]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(spiralArray(3), [
|
||||
@ -42,7 +42,7 @@ assert.deepEqual(spiralArray(3), [
|
||||
]);
|
||||
```
|
||||
|
||||
`spiralArray(4)` should return `[[0, 1, 2, 3],[11, 12, 13, 4],[10, 15, 14, 5],[9, 8, 7, 6]]`.
|
||||
`spiralArray(4)` dovrebbe restituire `[[0, 1, 2, 3],[11, 12, 13, 4],[10, 15, 14, 5],[9, 8, 7, 6]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(spiralArray(4), [
|
||||
@ -53,7 +53,7 @@ assert.deepEqual(spiralArray(4), [
|
||||
]);
|
||||
```
|
||||
|
||||
`spiralArray(5)` should return `[[0, 1, 2, 3, 4],[15, 16, 17, 18, 5],[14, 23, 24, 19, 6],[13, 22, 21, 20, 7],[12, 11, 10, 9, 8]]`.
|
||||
`spiralArray(5)` dovrebbe restituire `[[0, 1, 2, 3, 4],[15, 16, 17, 18, 5],[14, 23, 24, 19, 6],[13, 22, 21, 20, 7],[12, 11, 10, 9, 8]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(spiralArray(5), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc801d
|
||||
title: Split a character string based on change of character
|
||||
title: Dividi una stringa di caratteri in base al cambiamento di carattere
|
||||
challengeType: 5
|
||||
forumTopicId: 302322
|
||||
dashedName: split-a-character-string-based-on-change-of-character
|
||||
@ -8,13 +8,13 @@ dashedName: split-a-character-string-based-on-change-of-character
|
||||
|
||||
# --description--
|
||||
|
||||
Split a (character) string into comma (plus a blank) delimited strings based on a change of character (left to right). Blanks should be treated as any other character (except they are problematic to display clearly). The same applies to commas. For instance, the string:
|
||||
Dividere una stringa di caratteri in stringhe delimitate da virgola (più uno spazio bianco) in base a un cambiamento di carattere (da sinistra a destra). Gli spazi vuoti devono essere trattati come qualsiasi altro carattere (tranne per il fatto che sono problematici da visualizzare chiaramente). Lo stesso vale per le virgole. Per esempio, la stringa:
|
||||
|
||||
<pre>
|
||||
"gHHH5YY++///\\"
|
||||
</pre>
|
||||
|
||||
should be split as:
|
||||
dovrebbe essere diviso come:
|
||||
|
||||
<pre>
|
||||
["g", "HHH", "5", "YY", "++", "///", "\\" ];
|
||||
@ -22,25 +22,25 @@ should be split as:
|
||||
|
||||
# --hints--
|
||||
|
||||
`split` should be a function.
|
||||
`split` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof split == 'function');
|
||||
```
|
||||
|
||||
`split("hello")` should return an array.
|
||||
`split("hello")` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(split('hello')));
|
||||
```
|
||||
|
||||
`split("hello")` should return `["h", "e", "ll", "o"]`.
|
||||
`split("hello")` dovrebbe restituire `["h", "e", "ll", "o"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(split('hello'), ['h', 'e', 'll', 'o']);
|
||||
```
|
||||
|
||||
`split("commission")` should return `["c", "o", "mm", "i", "ss", "i", "o", "n"]`.
|
||||
`split("commission")` dovrebbe restituire `["c", "o", "mm", "i", "ss", "i", "o", "n"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(split('commission'), [
|
||||
@ -55,7 +55,7 @@ assert.deepEqual(split('commission'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`split("ssss----====llloooo")` should return `["ssss", "----", "====", "lll", "oooo"]`.
|
||||
`split("ssss----====llloooo")` dovrebbe restituire `["ssss", "----", "====", "lll", "oooo"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(split('ssss----====llloooo'), [
|
||||
@ -67,7 +67,7 @@ assert.deepEqual(split('ssss----====llloooo'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`split("sssmmmaaammmaaat")` should return `["sss", "mmm", "aaa", "mmm", "aaa", "t"]`.
|
||||
`split("sssmmmaaammmaaat")` dovrebbe restituire `["sss", "mmm", "aaa", "mmm", "aaa", "t"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(split('sssmmmaaammmaaat'), [
|
||||
@ -80,7 +80,7 @@ assert.deepEqual(split('sssmmmaaammmaaat'), [
|
||||
]);
|
||||
```
|
||||
|
||||
`split("gHHH5YY++///\\")` should return `["g", "HHH", "5", "YY", "++", "///", "\\"]`.
|
||||
`split("gHHH5YY++///\\")` dovrebbe restituire `["g", "HHH", "5", "YY", "++", "///", "\\"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(split('gHHH5YY++///\\'), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8024
|
||||
title: State name puzzle
|
||||
title: Puzzle sui nomi degli Stati
|
||||
challengeType: 5
|
||||
forumTopicId: 302323
|
||||
dashedName: state-name-puzzle
|
||||
@ -8,21 +8,21 @@ dashedName: state-name-puzzle
|
||||
|
||||
# --description--
|
||||
|
||||
This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [\[1\]](https://www.npr.org/templates/story/story.php?storyId=9264290) and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the names of two *different* U.S. States (so that all four state names differ from one another). What states are these? The problem was reissued on [the Unicon Discussion Web](https://tapestry.tucson.az.us/twiki/bin/view/Main/StateNamesPuzzle) which includes several solutions with analysis. Several techniques may be helpful and you may wish to refer to [Gödel numbering](https://en.wikipedia.org/wiki/Goedel_numbering), [equivalence relations](https://en.wikipedia.org/wiki/Equivalence_relation), and [equivalence classes](https://en.wikipedia.org/wiki/Equivalence_classes). The basic merits of these were discussed in the Unicon Discussion Web. A second challenge in the form of a set of fictitious new states was also presented.
|
||||
Questo compito è ispirato dalla colonna DDJ di Mark Nelson "Wordplay" e una delle sfide del puzzle settimanale da Will Shortz sulla NPR Weekend Edition [\[1\]](https://www.npr.org/templates/story/story.php?storyId=9264290) e originariamente attribuito a David Edelheit. La sfida è di prendere i nomi di due stati dell'USA, mischiarli, poi riarrangiare le lettere per formare i nomi di due *diversi* stati dell'USA (così da avere 4 nomi di stati diversi). Quali sono questi Stati? Il problema è stato ristampato su [Unicon Discussion Web](https://tapestry.tucson.az.us/twiki/bin/view/Main/StateNamesPuzzle) che include diverse soluzioni con analisi. Diverse tecniche possono essere utili e potresti voler fare riferimento a [ Gödel numbering](https://en.wikipedia.org/wiki/Goedel_numbering), [relazioni di equivalenza](https://en.wikipedia.org/wiki/Equivalence_relation), e [classi di equivalenza](https://en.wikipedia.org/wiki/Equivalence_classes). I meriti fondamentali di questi sono stati discussi nell'Unicon Discussion Web. È stata presentata anche una seconda sfida sotto forma di una serie di nuovi Stati fittizi.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to solve the challenge for the given array of names of states. The function should return an array. Each element should be an object in this form: `{"from":[],"to":[]}`. The "from" array should contain the original names and the "to" array should contain the resultant names.
|
||||
Scrivere una funzione per risolvere la sfida per la gamma data di nomi di Stati. La funzione dovrebbe restituire un array. Ogni elemento deve essere un oggetto in questa forma: `{"from":[],"to":[]}`. L'array "from" dovrebbe contenere i nomi originali e l'array "to" dovrebbe contenere i nomi risultanti.
|
||||
|
||||
# --hints--
|
||||
|
||||
`solve` should be a function.
|
||||
`solve` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof solve == 'function');
|
||||
```
|
||||
|
||||
`solve(["New Mexico", "New York", "North Carolina ", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota"])` should return an array.
|
||||
`solve(["New Mexico", "New York", "North Carolina ", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -44,7 +44,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`solve(["New Mexico", "New York", "North Carolina ", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota"])` should return `[{ from: ["North Carolina ", "South Dakota"], to: ["North Dakota", "South Carolina"] }]`.
|
||||
`solve(["New Mexico", "New York", "North Carolina ", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota"])` dovrebbe restituire `[{ from: ["North Carolina ", "South Dakota"], to: ["North Dakota", "South Carolina"] }]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -70,7 +70,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`solve(["New York", "New Kory", "Wen Kory", "York New", "Kory New", "New Kory"])` should return `[{ from: ["New Kory", "New York"], to: ["Wen Kory", "York New"] }, { from: ["New Kory", "New York"], to: ["Kory New", "Wen Kory"] }, { from: ["New Kory", "New York"], to: ["Kory New", "York New"] }, { from: ["New York", "Wen Kory"], to: ["New Kory", "York New"] }, { from: ["New York", "Wen Kory"], to: ["Kory New", "New Kory"] }, { from: ["New York", "Wen Kory"], to: ["Kory New", "York New"] }, { from: ["New York", "York New"], to: ["New Kory", "Wen Kory"] }, { from: ["New York", "York New"], to: ["Kory New", "New Kory"] }, { from: ["New York", "York New"], to: ["Kory New", "Wen Kory"] }, { from: ["Kory New", "New York"], to: ["New Kory", "Wen Kory"] }, { from: ["Kory New", "New York"], to: ["New Kory", "York New"] }, { from: ["Kory New", "New York"], to: ["Wen Kory", "York New"] }, { from: ["New Kory", "Wen Kory"], to: ["Kory New", "York New"] }, { from: ["New Kory", "York New"], to: ["Kory New", "Wen Kory"] }, { from: ["Kory New", "New Kory"], to: ["Wen Kory", "York New"] }]`.
|
||||
`solve(["New York", "New Kory", "Wen Kory", "York New", "Kory New", "New Kory"])` dovrebbe restituire `[{ from: ["New Kory", "New York"], to: ["Wen Kory", "York New"] }, { from: ["New Kory", "New York"], to: ["Kory New", "Wen Kory"] }, { from: ["New Kory", "New York"], to: ["Kory New", "York New"] }, { from: ["New York", "Wen Kory"], to: ["New Kory", "York New"] }, { from: ["New York", "Wen Kory"], to: ["Kory New", "New Kory"] }, { from: ["New York", "Wen Kory"], to: ["Kory New", "York New"] }, { from: ["New York", "York New"], to: ["New Kory", "Wen Kory"] }, { from: ["New York", "York New"], to: ["Kory New", "New Kory"] }, { from: ["New York", "York New"], to: ["Kory New", "Wen Kory"] }, { from: ["Kory New", "New York"], to: ["New Kory", "Wen Kory"] }, { from: ["Kory New", "New York"], to: ["New Kory", "York New"] }, { from: ["Kory New", "New York"], to: ["Wen Kory", "York New"] }, { from: ["New Kory", "Wen Kory"], to: ["Kory New", "York New"] }, { from: ["New Kory", "York New"], to: ["Kory New", "Wen Kory"] }, { from: ["Kory New", "New Kory"], to: ["Wen Kory", "York New"] }]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8028
|
||||
title: Stern-Brocot sequence
|
||||
title: Sequenza di Stern-Brocot
|
||||
challengeType: 5
|
||||
forumTopicId: 302324
|
||||
dashedName: stern-brocot-sequence
|
||||
@ -8,75 +8,73 @@ dashedName: stern-brocot-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence).
|
||||
Per questa sfida, la serie di Stern-Brocot deve essere generata da un algoritmo simile a quello usato per generare la [serie di Fibonacci](https://rosettacode.org/wiki/Fibonacci sequence).
|
||||
|
||||
<ol>
|
||||
<li>The first and second members of the sequence are both 1:</li>
|
||||
<li>Il primo e il secondo elemento della serie sono entrambi 1:</li>
|
||||
<ul><li>1, 1</li></ul>
|
||||
<li>Start by considering the second member of the sequence</li>
|
||||
<li>Sum the considered member of the sequence and its precedent, (1 + 1) = 2, and append it to the end of the
|
||||
sequence:</li>
|
||||
<li>Inizia considerando il secondo elemento della serie</li>
|
||||
<li>Somma l'elemento considerato della sequenza e il precedente, (1 + 1) = 2, e aggiungilo alla fine della sequenza:</li>
|
||||
<ul><li>1, 1, 2</li></ul>
|
||||
<li>Append the considered member of the sequence to the end of the sequence:</li>
|
||||
<li>Aggiungi l'elemento considerato alla fine della sequenza:</li>
|
||||
<ul><li>1, 1, 2, 1</li></ul>
|
||||
<li>Consider the next member of the series, (the third member i.e. 2)</li>
|
||||
<li>GOTO 3 </li>
|
||||
<li>Considera l'elemento successivo della serie, (il terzo elemento, cioè 2)</li>
|
||||
<li>Vai a 3 </li>
|
||||
<ul>
|
||||
<li></li>
|
||||
<li> ─── Expanding another loop we get: ───</li>
|
||||
<li> ─── Espandendo un altro ciclo otteniamo: ───</li>
|
||||
<li></li>
|
||||
</ul>
|
||||
<li>Sum the considered member of the sequence and its precedent, (2 + 1) = 3, and append it to the end of the
|
||||
sequence:</li>
|
||||
<li>Somma l'elemento considerato della sequenza e il suo predecessore, (2 + 1) = 3, e appendilo alla fine della sequenza:</li>
|
||||
<ul><li>1, 1, 2, 1, 3</li></ul>
|
||||
<li>Append the considered member of the sequence to the end of the sequence:</li>
|
||||
<li>Aggiungi l'elemento considerato alla fine della sequenza:</li>
|
||||
<ul><li>1, 1, 2, 1, 3, 2</li></ul>
|
||||
<li>Consider the next member of the series, (the fourth member i.e. 1)</li>
|
||||
<li>Considera l'elemento successivo della serie, (il quarto elemento, cioè 1)</li>
|
||||
</ol>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Create a function that returns the position in the Stern-Brocot sequence at which $ n $ is first encountered, where the sequence is generated with the method outlined above. Note that this sequence uses 1 based indexing.
|
||||
Crea una funzione che restituisce la posizione della serie di Stern-Brocot a cui $ n $ si trova per la prima volte, dove la serie è generata con il metodo mostrato sopra. Nota che questa sequenza usa indicizzazione che parte da 1.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sternBrocot` should be a function.
|
||||
`sternBrocot` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sternBrocot == 'function');
|
||||
```
|
||||
|
||||
`sternBrocot(2)` should return a number.
|
||||
`sternBrocot(2)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof sternBrocot(2) == 'number');
|
||||
```
|
||||
|
||||
`sternBrocot(2)` should return `3`.
|
||||
`sternBrocot(2)` dovrebbe restiture `3`.
|
||||
|
||||
```js
|
||||
assert.equal(sternBrocot(2), 3);
|
||||
```
|
||||
|
||||
`sternBrocot(3)` should return `5`.
|
||||
`sternBrocot(3)` dovrebbe restituire `5`.
|
||||
|
||||
```js
|
||||
assert.equal(sternBrocot(3), 5);
|
||||
```
|
||||
|
||||
`sternBrocot(5)` should return `11`.
|
||||
`sternBrocot(5)` dovrebbe restiture `11`.
|
||||
|
||||
```js
|
||||
assert.equal(sternBrocot(5), 11);
|
||||
```
|
||||
|
||||
`sternBrocot(7)` should return `19`.
|
||||
`sternBrocot(7)` dovrebbe restiture `19`.
|
||||
|
||||
```js
|
||||
assert.equal(sternBrocot(7), 19);
|
||||
```
|
||||
|
||||
`sternBrocot(10)` should return `39`.
|
||||
`sternBrocot(10)` dovrebbe restiture `39`.
|
||||
|
||||
```js
|
||||
assert.equal(sternBrocot(10), 39);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8029
|
||||
title: Straddling checkerboard
|
||||
title: Scacchiera a cavallo
|
||||
challengeType: 5
|
||||
forumTopicId: 302325
|
||||
dashedName: straddling-checkerboard
|
||||
@ -8,17 +8,17 @@ dashedName: straddling-checkerboard
|
||||
|
||||
# --description--
|
||||
|
||||
Implement functions to encrypt and decrypt a message using the [straddling checkerboard](https://en.wikipedia.org/wiki/Straddling_checkerboard) method. The functions will take a string and an array as parameters. The array has 3 strings representing the 3 rows of the checkerboard. The output will be a series of decimal digits. Numbers should be encrypted by inserting the escape character before each digit, then including the digit unencrypted. This should be reversed for decryption.
|
||||
Implementa le funzioni per crittografare e decrittografare un messaggio usando il metodo [straddling checkerboard](https://en.wikipedia.org/wiki/Straddling_checkerboard). Le funzioni prenderanno una stringa e un array come parametri. L'array ha 3 stringhe che rappresentano le 3 righe della scacchiera. L'output sarà una serie di cifre decimali. I numeri devono essere cifrati inserendo il carattere di escape prima di ogni cifra, quindi includendo la cifra non cifrata. Questo dovrebbe essere invertito per la decifratura.
|
||||
|
||||
# --hints--
|
||||
|
||||
`straddle` should be a function.
|
||||
`straddle` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof straddle == 'function');
|
||||
```
|
||||
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning.",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` should return a string.
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning.",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -29,7 +29,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning.",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` should return `"34045747525284613427502840425027537379697175891898898898584619028294547488"`.
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning.",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` dovrebbe restituire `"34045747525284613427502840425027537379697175891898898898584619028294547488"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -41,7 +41,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning",["HOL MES RT", "ABCDFGIJKN", "PQUVWXYZ./"])` should return `"139539363509369743061399059745399365901344308320791798798798367430685972839363935"`.
|
||||
`straddle("One night-it was on the twentieth of March, 1888-I was returning",["HOL MES RT", "ABCDFGIJKN", "PQUVWXYZ./"])` dovrebbe restituire `"139539363509369743061399059745399365901344308320791798798798367430685972839363935"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -54,7 +54,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`straddle("Thecheckerboardcakerecipespecifies3largeeggsand2.25cupsofflour.",["ET AON RIS", "BCDFGHJKLM", "PQ/UVWXYZ."])` should return `"125021250212707204372221327070218600960021823809623283724002424935226226962262521636094232328463769"`.
|
||||
`straddle("Thecheckerboardcakerecipespecifies3largeeggsand2.25cupsofflour.",["ET AON RIS", "BCDFGHJKLM", "PQ/UVWXYZ."])` dovrebbe restituire `"125021250212707204372221327070218600960021823809623283724002424935226226962262521636094232328463769"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -67,13 +67,13 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`unstraddle` should be a function.
|
||||
`unstraddle` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof unstraddle == 'function');
|
||||
```
|
||||
|
||||
`unstraddle("34045747525284613427502840425027537379697175891898898898584619028294547488",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` should return a string.
|
||||
`unstraddle("34045747525284613427502840425027537379697175891898898898584619028294547488",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -84,7 +84,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`unstraddle("34045747525284613427502840425027537379697175891898898898584619028294547488",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` should return `"ONENIGHTITWASONTHETWENTIETHOFMARCH1888IWASRETURNING."`.
|
||||
`unstraddle("34045747525284613427502840425027537379697175891898898898584619028294547488",["ESTONIA R", "BCDFGHJKLM", "PQUVWXYZ./"])` dovrebbe restituire `"ONENIGHTITWASONTHETWENTIETHOFMARCH1888IWASRETURNING."`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -96,7 +96,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`unstraddle("139539363509369743061399059745399365901344308320791798798798367430685972839363935",["HOL MES RT", "ABCDFGIJKN", "PQUVWXYZ./"])` should return `"ONENIGHTITWASONTHETWENTIETHOFMARCH1888IWASRETURNING"`.
|
||||
`unstraddle("139539363509369743061399059745399365901344308320791798798798367430685972839363935",["HOL MES RT", "ABCDFGIJKN", "PQUVWXYZ./"])` dovrebbe restituire `"ONENIGHTITWASONTHETWENTIETHOFMARCH1888IWASRETURNING"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -108,7 +108,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`unstraddle("125021250212707204372221327070218600960021823809623283724002424935226226962262521636094232328463769",["ET AON RIS", "BCDFGHJKLM", "PQ/UVWXYZ."])` should return `"THECHECKERBOARDCAKERECIPESPECIFIES3LARGEEGGSAND2.25CUPSOFFLOUR."`.
|
||||
`unstraddle("125021250212707204372221327070218600960021823809623283724002424935226226962262521636094232328463769",["ET AON RIS", "BCDFGHJKLM", "PQ/UVWXYZ."])` dovrebbe restituire `"THECHECKERBOARDCAKERECIPESPECIFIES3LARGEEGGSAND2.25CUPSOFFLOUR."`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc802a
|
||||
title: Stream Merge
|
||||
title: Unione di flussi
|
||||
challengeType: 5
|
||||
forumTopicId: 302326
|
||||
dashedName: stream-merge
|
||||
@ -8,17 +8,17 @@ dashedName: stream-merge
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that takes multiple sorted arrays of items, and returns one array of sorted items.
|
||||
Scrivi una funzione che riceve vari array ordinati, e restituisce un unico array di elementi ordinato.
|
||||
|
||||
# --hints--
|
||||
|
||||
`mergeLists` should be a function.
|
||||
`mergeLists` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof mergeLists == 'function');
|
||||
```
|
||||
|
||||
`mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])` should return an array.
|
||||
`mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -31,7 +31,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])` should return `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`.
|
||||
`mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])` dovrebbe restituire `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -43,7 +43,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeLists([[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]])` should return `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]`.
|
||||
`mergeLists([[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]])` dovrebbe restituire `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -56,7 +56,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeLists([[1, 3, 9, 14, 15, 17, 28], [7, 8, 14, 14, 23, 26, 28, 29, 30], [9, 23, 25, 29]])` should return `[1, 3, 7, 8, 9, 9, 14, 14, 14, 15, 17, 23, 23, 25, 26, 28, 28, 29, 29, 30]`.
|
||||
`mergeLists([[1, 3, 9, 14, 15, 17, 28], [7, 8, 14, 14, 23, 26, 28, 29, 30], [9, 23, 25, 29]])` dovrebbe restituire `[1, 3, 7, 8, 9, 9, 14, 14, 14, 15, 17, 23, 23, 25, 26, 28, 28, 29, 29, 30]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -69,7 +69,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`mergeLists([[3, 14, 15], [2, 17, 18], [], [2, 3, 5, 7]])` should return `[2, 2, 3, 3, 5, 7, 14, 15, 17, 18]`.
|
||||
`mergeLists([[3, 14, 15], [2, 17, 18], [], [2, 3, 5, 7]])` dovrebbe restituire `[2, 2, 3, 3, 5, 7, 14, 15, 17, 18]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(mergeLists([[3, 14, 15], [2, 17, 18], [], [2, 3, 5, 7]]), [
|
||||
@ -86,7 +86,7 @@ assert.deepEqual(mergeLists([[3, 14, 15], [2, 17, 18], [], [2, 3, 5, 7]]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`mergeLists([[1, 19, 1999], [17, 33, 2999, 3000], [8, 500, 3999]])` should return `[1, 8, 17, 19, 33, 500, 1999, 2999, 3000, 3999]`.
|
||||
`mergeLists([[1, 19, 1999], [17, 33, 2999, 3000], [8, 500, 3999]])` dovrebbe restituire `[1, 8, 17, 19, 33, 500, 1999, 2999, 3000, 3999]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8036
|
||||
title: Strip control codes and extended characters from a string
|
||||
title: Rimozione di codici di controllo e caratteri estesi da una stringa
|
||||
challengeType: 5
|
||||
forumTopicId: 302327
|
||||
dashedName: strip-control-codes-and-extended-characters-from-a-string
|
||||
@ -8,47 +8,47 @@ dashedName: strip-control-codes-and-extended-characters-from-a-string
|
||||
|
||||
# --description--
|
||||
|
||||
The task is to strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results: A string with control codes and extended characters stripped. In ASCII, the control codes have decimal codes 0 through to 31 and 127. On an ASCII based system, if the control codes are stripped, the resultant string would have all of its characters within the range of 32 to 126 decimal on the ASCII table. On a non-ASCII based system, we consider characters that do not have a corresponding glyph on the ASCII table (within the ASCII range of 32 to 126 decimal) to be an extended character for the purpose of this task.
|
||||
Il compito è quello di rimuovere i codici di controllo e i caratteri estesi da una stringa. La soluzione dovrebbe dimostrare come ottenere ciascuno dei seguenti risultati: una stringa con codici di controllo e caratteri estesi rimossi. Nell'ASCII, i codici di controllo hanno codici decimali da 0 a 31 e 127. Su un sistema basato su ASCII, se i codici di controllo sono rimossi, la stringa risultante avrebbe tutti i suoi caratteri nell'intervallo da 32 a 126 decimale nella tabella ASCII. Su un sistema non basato su ASCII, consideriamo i caratteri che non hanno un glifo corrispondente nella tabella ASCII (entro l'intervallo ASCII da 32 a 126 decimale) un carattere esteso ai fini di questo compito.
|
||||
|
||||
# --hints--
|
||||
|
||||
`strip` should be a function.
|
||||
`strip` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof strip == 'function');
|
||||
```
|
||||
|
||||
`strip("abc")` should return a string.
|
||||
`strip("abc")` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(typeof strip('abc') == 'string');
|
||||
```
|
||||
|
||||
`strip("\ba\x00b\n\rc\fd\xc3")` should return `"abcd"`.
|
||||
`strip("\ba\x00b\n\rc\fd\xc3")` dovrebbe restituire `"abcd"`.
|
||||
|
||||
```js
|
||||
assert.equal(strip('\ba\x00b\n\rc\fd\xc3'), 'abcd');
|
||||
```
|
||||
|
||||
`strip("\u0000\n abc\u00E9def\u007F")` should return `" abcdef"`.
|
||||
`strip("\u0000\n abc\u00E9def\u007F")` dovrebbe restituire `" abcdef"`.
|
||||
|
||||
```js
|
||||
assert.equal(strip('\u0000\n abc\u00E9def\u007F'), ' abcdef');
|
||||
```
|
||||
|
||||
`strip("a\n\tb\u2102d\u2147f")` should return `"abdf"`.
|
||||
`strip("a\n\tb\u2102d\u2147f")` dovrebbe restituire `"abdf"`.
|
||||
|
||||
```js
|
||||
assert.equal(strip('a\n\tb\u2102d\u2147f'), 'abdf');
|
||||
```
|
||||
|
||||
`strip("Français.")` should return `"Franais."`.
|
||||
`strip("Français.")` dovrebbe restituire `"Franais."`.
|
||||
|
||||
```js
|
||||
assert.equal(strip('Français.'), 'Franais.');
|
||||
```
|
||||
|
||||
`strip("123\tabc\u0007DEF\u007F+-*/€æŧðłþ")` should return `"123abcDEF+-*/"`.
|
||||
`strip("123\tabc\u0007DEF\u007F+-*/€æŧðłþ")` dovrebbe restituire `"123abcDEF+-*/"`.
|
||||
|
||||
```js
|
||||
assert.equal(strip('123\tabc\u0007DEF\u007F+-*/€æŧðłþ'), '123abcDEF+-*/');
|
||||
|
@ -8,50 +8,34 @@ dashedName: subleq
|
||||
|
||||
# --description--
|
||||
|
||||
[Subleq](https://rosettacode.org/wiki/eso:Subleq) is an example of a [One-Instruction Set Computer (OISC)](https://en.wikipedia.org/wiki/One_instruction_set_computer).
|
||||
[Subleq](https://rosettacode.org/wiki/eso:Subleq) è un esempio di un [Computer One-Instruction Set (OISC)](https://en.wikipedia.org/wiki/One_instruction_set_computer).
|
||||
|
||||
It is named after its only instruction, which is **SU**btract and **B**ranch if **L**ess than or **EQ**ual
|
||||
Esso prende il nome dalla sua unica istruzione, che è **SU**btract e **B**ranch se **L**ess than or **EQ**ual to zero (sottrai e dirama se minore o uguale a zero).
|
||||
|
||||
to zero.
|
||||
Il tuo compito è quello di creare un interprete che emula una macchina del genere.
|
||||
|
||||
Your task is to create an interpreter which emulates such a machine.
|
||||
La memoria della macchina è costituita da una serie di numeri interi con segno. Qualsiasi dimensione ragionevole di parola va bene, ma la memoria deve essere in grado di contenere numeri negativi e positivi.
|
||||
|
||||
The machine's memory consists of an array of signed integers. Any reasonable word size is fine, but the memory must be
|
||||
|
||||
able to hold negative as well as positive numbers.
|
||||
|
||||
Execution begins with the instruction pointer aimed at the first word, which is address 0. It proceeds as follows:
|
||||
L'esecuzione inizia con il puntatore di istruzioni rivolto alla prima parola, che è l'indirizzo 0. Essa procede come segue:
|
||||
|
||||
<ol>
|
||||
<li>Let A, B, and C be the value stored in the three consecutive words in memory starting at the instruction pointer.</li>
|
||||
<li>Advance the instruction pointer 3 words to point at the address after the one containing C.</li>
|
||||
<li>If A is -1, then a character is read from standard input and its code point stored in the address given by B. C
|
||||
is unused.</li>
|
||||
<li>If B is -1, then the number contained in the address given by A is interpreted as a code point and the
|
||||
corresponding character output. C is again unused.</li>
|
||||
<li>Otherwise, both A and B are treated as the addresses of memory locations. The number contained in the address
|
||||
given by A is subtracted from the number at the address given by B (and the result stored back in address B). If
|
||||
the result is zero or negative, the value C becomes the new instruction pointer.</li>
|
||||
<li>If the instruction pointer becomes negative, execution halts.</li>
|
||||
<li>Sia A, B e C il valore memorizzato nelle tre parole consecutive in memoria a partire dal puntatore di istruzioni.</li>
|
||||
<li>Fai avanzare il puntatore di tre parole in modo da puntare all'indirizzo successivo a quello contenente C.</li>
|
||||
<li>Se A è -1, viene letto un carattere dallo standard input e il suo codice punto memorizzato nell'indirizzo indicato da B. C è inutilizzato.</li>
|
||||
<li>Se B è -1, allora il numero contenuto nell'indirizzo dato da A è interpretato come un punto di codice e viene fatto l'output del carattere corrispondente. C è di nuovo inutilizzato.</li>
|
||||
<li>Altrimenti, sia A che B sono trattati come gli indirizzi di luoghi di memoria. Il numero contenuto nell’indirizzo indicato da A viene sottratto dal numero all’indirizzo indicato da B (e il risultato memorizzato nell’indirizzo B). Se il risultato è zero o negativo, il valore C diventa il nuovo puntatore di istruzione.</li>
|
||||
<li>Se il puntatore di istruzioni diventa negativo, l'esecuzione si ferma.</li>
|
||||
</ol>
|
||||
|
||||
Other negative addresses besides -1 may be treated as equivalent to -1, or generate an error, as you see fit.
|
||||
Altri indirizzi negativi oltre a -1 possono essere trattati come equivalenti a -1, o generare un errore, come si ritiene opportuno.
|
||||
|
||||
Your solution should accept a program to execute on the machine, separately from the input fed to the program itself.
|
||||
La tua soluzione dovrebbe accettare un programma da eseguire sulla macchina, separatamente dall'input fornito al programma stesso.
|
||||
|
||||
This program should be in raw subleq "machine code" - whitespace-separated decimal numbers, with no symbolic names or
|
||||
|
||||
other assembly-level extensions, to be loaded into memory starting at address 0. Show the output of your solution when
|
||||
|
||||
fed this "Hello, world!" program. (Note that the example assumes ASCII or a superset of it, such as any of the Latin-N
|
||||
|
||||
character sets or Unicode. You may translate it into another character set if your implementation is on a
|
||||
|
||||
non-ASCiI-compatible environment.)
|
||||
Questo programma dovrebbe essere "linguaggio macchina" subleq grezzo - numeri decimali separati da spazi, senza nomi simbolici o altre estensioni a livello di assembly, da caricare in memoria a partire dall'indirizzo 0. Mostra l'output della tua soluzione quando alimentato con questo programma "Hello, world!". (Nota che l'esempio assume ASCII o un superset di esso, come uno dei set di caratteri Latin-N o Unicode. Puoi tradurlo in un altro set di caratteri se la tua implementazione è in un ambiente non compatibile con ASCII.)
|
||||
|
||||
<pre>15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0</pre>
|
||||
|
||||
Which corresponds to something like this in a hypothetical assembler language:
|
||||
Che corrisponde a qualcosa di simile in un ipotetico linguaggio assembler:
|
||||
|
||||
<pre>start:
|
||||
zero, message, -1
|
||||
@ -66,19 +50,17 @@ message: "Hello, world!\n\0"
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes an array of integers as a parameter. This represents the memory elements. The function
|
||||
|
||||
should interpret the sequence and return the output string. For this task, assume that there is no standard input.
|
||||
Scrivi una funzione che richiede un array di interi come parametro. Questo rappresenta gli elementi di memoria. La funzione deve interpretare la sequenza e restituire la stringa di output. Per questo compito, supponiamo che non ci sia uno standard input.
|
||||
|
||||
# --hints--
|
||||
|
||||
`Subleq` should be a function.
|
||||
`Subleq` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof Subleq == 'function');
|
||||
```
|
||||
|
||||
`Subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 0])` should return a string.
|
||||
`Subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 0])` dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -118,7 +100,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`Subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 0])` should return `"Hello, world!"`.
|
||||
`Subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 0])` dovrebbe restituire `"Hello, world!"`.
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -8,17 +8,17 @@ dashedName: sudoku
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to solve a partially filled-in normal 9x9 [Sudoku](https://en.wikipedia.org/wiki/Sudoku) grid and return the result. The blank fields are represented by `-1`. [Algorithmics of Sudoku](https://en.wikipedia.org/wiki/Algorithmics_of_sudoku) may help implement this.
|
||||
Scrivi una funzione per risolvere una normale griglia di [Sudoku](https://en.wikipedia.org/wiki/Sudoku) 9x9 parzialmente riempita e restituisci il risultato. I campi vuoti sono rappresentati da `-1`. [Gli algoritmi di risoluzione di Sudoku](https://en.wikipedia.org/wiki/Algorithmics_of_sudoku) possono aiutare ad implementarlo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`solveSudoku` should be a function.
|
||||
`solveSudoku` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof solveSudoku == 'function');
|
||||
```
|
||||
|
||||
`solveSudoku([[8, 1, 9, -1, -1, 5, -1, -1, -1],[-1, -1, 2, -1, -1, -1, 7, 5, -1],[-1, 3, 7, 1, -1, 4, -1, 6, -1],[4, -1, -1, 5, 9, -1, 1, -1, -1],[7, -1, -1, 3, -1, 8, -1, -1, 2],[-1, -1, 3, -1, 6, 2, -1, -1, 7],[-1, 5, -1, 7, -1, 9, 2, 1, -1],[-1, 6, 4, -1, -1, -1, 9, -1, -1],[-1, -1, -1, 2, -1, -1, 4, 3, 8]])` should return an array.
|
||||
`solveSudoku([[8, 1, 9, -1, -1, 5, -1, -1, -1],[-1, -1, 2, -1, -1, -1, 7, 5, -1],[-1, 3, 7, 1, -1, 4, -1, 6, -1],[4, -1, -1, 5, 9, -1, 1, -1, -1],[7, -1, -1, 3, -1, 8, -1, -1, 2],[-1, -1, 3, -1, 6, 2, -1, -1, 7],[-1, 5, -1, 7, -1, 9, 2, 1, -1],[-1, 6, 4, -1, -1, -1, 9, -1, -1],[-1, -1, -1, 2, -1, -1, 4, 3, 8]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -38,7 +38,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`solveSudoku([[8, 1, 9, -1, -1, 5, -1, -1, -1],[-1, -1, 2, -1, -1, -1, 7, 5, -1],[-1, 3, 7, 1, -1, 4, -1, 6, -1],[4, -1, -1, 5, 9, -1, 1, -1, -1],[7, -1, -1, 3, -1, 8, -1, -1, 2],[-1, -1, 3, -1, 6, 2, -1, -1, 7],[-1, 5, -1, 7, -1, 9, 2, 1, -1],[-1, 6, 4, -1, -1, -1, 9, -1, -1],[-1, -1, -1, 2, -1, -1, 4, 3, 8]])` should return `[[8, 1, 9, 6, 7, 5, 3, 2, 4],[6, 4, 2, 9, 8, 3, 7, 5, 1],[5, 3, 7, 1, 2, 4, 8, 6, 9],[4, 2, 6, 5, 9, 7, 1, 8, 3],[7, 9, 5, 3, 1, 8, 6, 4, 2],[1, 8, 3, 4, 6, 2, 5, 9, 7],[3, 5, 8, 7, 4, 9, 2, 1, 6],[2, 6, 4, 8, 3, 1, 9, 7, 5],[9, 7, 1, 2, 5, 6, 4, 3, 8]]`.
|
||||
`solveSudoku([[8, 1, 9, -1, -1, 5, -1, -1, -1],[-1, -1, 2, -1, -1, -1, 7, 5, -1],[-1, 3, 7, 1, -1, 4, -1, 6, -1],[4, -1, -1, 5, 9, -1, 1, -1, -1],[7, -1, -1, 3, -1, 8, -1, -1, 2],[-1, -1, 3, -1, 6, 2, -1, -1, 7],[-1, 5, -1, 7, -1, 9, 2, 1, -1],[-1, 6, 4, -1, -1, -1, 9, -1, -1],[-1, -1, -1, 2, -1, -1, 4, 3, 8]])` dovrebbe restituire `[[8, 1, 9, 6, 7, 5, 3, 2, 4],[6, 4, 2, 9, 8, 3, 7, 5, 1],[5, 3, 7, 1, 2, 4, 8, 6, 9],[4, 2, 6, 5, 9, 7, 1, 8, 3],[7, 9, 5, 3, 1, 8, 6, 4, 2],[1, 8, 3, 4, 6, 2, 5, 9, 7],[3, 5, 8, 7, 4, 9, 2, 1, 6],[2, 6, 4, 8, 3, 1, 9, 7, 5],[9, 7, 1, 2, 5, 6, 4, 3, 8]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -67,7 +67,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`solveSudoku([[5, 3, -1, -1, 2, 4, 7, -1, -1],[-1, -1, 2, -1, -1, -1, 8, -1, -1],[1, -1, -1, 7, -1, 3, 9, -1, 2],[-1, -1, 8, -1, 7, 2, -1, 4, 9],[-1, 2, -1, 9, 8, -1, -1, 7, -1],[7, 9, -1, -1, -1, -1, -1, 8, -1],[-1, -1, -1, -1, 3, -1, 5, -1, 6],[9, 6, -1, -1, 1, -1, 3, -1, -1],[-1, 5, -1, 6, 9, -1, -1, 1, -1]])` should return `[[5, 3, 9, 8, 2, 4, 7, 6, 1],[6, 7, 2, 1, 5, 9, 8, 3, 4],[1, 8, 4, 7, 6, 3, 9, 5, 2],[3, 1, 8, 5, 7, 2, 6, 4, 9],[4, 2, 5, 9, 8, 6, 1, 7, 3],[7, 9, 6, 3, 4, 1, 2, 8, 5],[8, 4, 1, 2, 3, 7, 5, 9, 6],[9, 6, 7, 4, 1, 5, 3, 2, 8],[2, 5, 3, 6, 9, 8, 4, 1, 7]]`.
|
||||
`solveSudoku([[5, 3, -1, -1, 2, 4, 7, -1, -1],[-1, -1, 2, -1, -1, -1, 8, -1, -1],[1, -1, -1, 7, -1, 3, 9, -1, 2],[-1, -1, 8, -1, 7, 2, -1, 4, 9],[-1, 2, -1, 9, 8, -1, -1, 7, -1],[7, 9, -1, -1, -1, -1, -1, 8, -1],[-1, -1, -1, -1, 3, -1, 5, -1, 6],[9, 6, -1, -1, 1, -1, 3, -1, -1],[-1, 5, -1, 6, 9, -1, -1, 1, -1]])` dovrebbe restituire `[[5, 3, 9, 8, 2, 4, 7, 6, 1],[6, 7, 2, 1, 5, 9, 8, 3, 4],[1, 8, 4, 7, 6, 3, 9, 5, 2],[3, 1, 8, 5, 7, 2, 6, 4, 9],[4, 2, 5, 9, 8, 6, 1, 7, 3],[7, 9, 6, 3, 4, 1, 2, 8, 5],[8, 4, 1, 2, 3, 7, 5, 9, 6],[9, 6, 7, 4, 1, 5, 3, 2, 8],[2, 5, 3, 6, 9, 8, 4, 1, 7]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -96,7 +96,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`solveSudoku([[-1, -1, 3, -1, 2, -1, 6, -1, -1],[9, -1, -1, 3, -1, 5, -1, -1, 1],[-1, -1, 1, 8, -1, 6, 4, -1, -1],[-1, -1, 8, 1, -1, 2, 9, -1, -1],[7, -1, -1, -1, -1, -1, -1, -1, 8],[-1, -1, 6, 7, -1, 8, 2, -1, -1],[-1, -1, 2, 6, -1, 9, 5, -1, -1],[8, -1, -1, 2, -1, 3, -1, -1, 9],[-1, -1, 5, -1, 1, -1, 3, -1, -1]])` should return `[[4, 8, 3, 9, 2, 1, 6, 5, 7],[9, 6, 7, 3, 4, 5, 8, 2, 1],[2, 5, 1, 8, 7, 6, 4, 9, 3],[5, 4, 8, 1, 3, 2, 9, 7, 6],[7, 2, 9, 5, 6, 4, 1, 3, 8],[1, 3, 6, 7, 9, 8, 2, 4, 5],[3, 7, 2, 6, 8, 9, 5, 1, 4],[8, 1, 4, 2, 5, 3, 7, 6, 9],[6, 9, 5, 4, 1, 7, 3, 8, 2]]`.
|
||||
`solveSudoku([[-1, -1, 3, -1, 2, -1, 6, -1, -1],[9, -1, -1, 3, -1, 5, -1, -1, 1],[-1, -1, 1, 8, -1, 6, 4, -1, -1],[-1, -1, 8, 1, -1, 2, 9, -1, -1],[7, -1, -1, -1, -1, -1, -1, -1, 8],[-1, -1, 6, 7, -1, 8, 2, -1, -1],[-1, -1, 2, 6, -1, 9, 5, -1, -1],[8, -1, -1, 2, -1, 3, -1, -1, 9],[-1, -1, 5, -1, 1, -1, 3, -1, -1]])` dovrebbe restituire `[[4, 8, 3, 9, 2, 1, 6, 5, 7],[9, 6, 7, 3, 4, 5, 8, 2, 1],[2, 5, 1, 8, 7, 6, 4, 9, 3],[5, 4, 8, 1, 3, 2, 9, 7, 6],[7, 2, 9, 5, 6, 4, 1, 3, 8],[1, 3, 6, 7, 9, 8, 2, 4, 5],[3, 7, 2, 6, 8, 9, 5, 1, 4],[8, 1, 4, 2, 5, 3, 7, 6, 9],[6, 9, 5, 4, 1, 7, 3, 8, 2]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc803f
|
||||
title: Sum digits of an integer
|
||||
title: Somma delle cifre di un intero
|
||||
challengeType: 5
|
||||
forumTopicId: 302331
|
||||
dashedName: sum-digits-of-an-integer
|
||||
@ -8,7 +8,7 @@ dashedName: sum-digits-of-an-integer
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that takes a string as a parameter. This string represents a number that can be in any base (less than 37) and return the sum of its digits.
|
||||
Scrivi una funzione che prende una stringa come parametro. Questa stringa rappresenta un numero che può essere in qualsiasi base (inferiore a 37) e restituisce la somma delle sue cifre.
|
||||
|
||||
<ul>
|
||||
<li><b>1</b><sub>10</sub> sums to <b>1</b></li>
|
||||
@ -19,49 +19,49 @@ Write a function that takes a string as a parameter. This string represents a nu
|
||||
|
||||
# --hints--
|
||||
|
||||
`sumDigits` should be a function.
|
||||
`sumDigits` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sumDigits == 'function');
|
||||
```
|
||||
|
||||
`sumDigits("1")` should return a number.
|
||||
`sumDigits("1")` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof sumDigits('1') == 'number');
|
||||
```
|
||||
|
||||
`sumDigits("1")` should return `1`.
|
||||
`sumDigits("1")` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('1'), 1);
|
||||
```
|
||||
|
||||
`sumDigits("12345")` should return `15`.
|
||||
`sumDigits("12345")` dovrebbe restituire `15`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('12345'), 15);
|
||||
```
|
||||
|
||||
`sumDigits("254")` should return `11`.
|
||||
`sumDigits("254")` dovrebbe restituire `11`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('254'), 11);
|
||||
```
|
||||
|
||||
`sumDigits("fe")` should return `29`.
|
||||
`sumDigits("fe")` dovrebbe restituire `29`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('fe'), 29);
|
||||
```
|
||||
|
||||
`sumDigits("f0e")` should return `29`.
|
||||
`sumDigits("f0e")` dovrebbe restituire `29`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('f0e'), 29);
|
||||
```
|
||||
|
||||
`sumDigits("999ABCXYZ")` should return `162`.
|
||||
`sumDigits("999ABCXYZ")` dovrebbe restituire `162`.
|
||||
|
||||
```js
|
||||
assert.equal(sumDigits('999ABCXYZ'), 162);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8040
|
||||
title: Sum multiples of 3 and 5
|
||||
title: Somma multipli di 3 e 5
|
||||
challengeType: 5
|
||||
forumTopicId: 302332
|
||||
dashedName: sum-multiples-of-3-and-5
|
||||
@ -8,47 +8,47 @@ dashedName: sum-multiples-of-3-and-5
|
||||
|
||||
# --description--
|
||||
|
||||
The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below *n*.
|
||||
L'obiettivo è quello di scrivere una funzione che trova la somma di tutti i multipli positivi di 3 o 5 inferiori a *n*.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sumMults` should be a function.
|
||||
`sumMults` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sumMults == 'function');
|
||||
```
|
||||
|
||||
`sumMults(10)` should return a number.
|
||||
`sumMults(10)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof sumMults(10) == 'number');
|
||||
```
|
||||
|
||||
`sumMults(10)` should return `23`.
|
||||
`sumMults(10)` dovrebbe restituire `23`.
|
||||
|
||||
```js
|
||||
assert.equal(sumMults(10), 23);
|
||||
```
|
||||
|
||||
`sumMults(100)` should return `2318`.
|
||||
`sumMults(100)` dovrebbe restituire `2318`.
|
||||
|
||||
```js
|
||||
assert.equal(sumMults(100), 2318);
|
||||
```
|
||||
|
||||
`sumMults(1000)` should return `233168`.
|
||||
`sumMults(1000)` dovrebbe restituire `233168`.
|
||||
|
||||
```js
|
||||
assert.equal(sumMults(1000), 233168);
|
||||
```
|
||||
|
||||
`sumMults(10000)` should return `23331668`.
|
||||
`sumMults(10000)` dovrebbe restituire `23331668`.
|
||||
|
||||
```js
|
||||
assert.equal(sumMults(10000), 23331668);
|
||||
```
|
||||
|
||||
`sumMults(100000)` should return `2333316668`.
|
||||
`sumMults(100000)` dovrebbe restituire `2333316668`.
|
||||
|
||||
```js
|
||||
assert.equal(sumMults(100000), 2333316668);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8041
|
||||
title: Sum of a series
|
||||
title: Somma di una serie
|
||||
challengeType: 5
|
||||
forumTopicId: 302333
|
||||
dashedName: sum-of-a-series
|
||||
@ -8,51 +8,51 @@ dashedName: sum-of-a-series
|
||||
|
||||
# --description--
|
||||
|
||||
Compute the **n**<sup>th</sup> term of a [series](https://en.wikipedia.org/wiki/Series (mathematics)), i.e. the sum of the **n** first terms of the corresponding [sequence](https://en.wikipedia.org/wiki/sequence). Informally this value, or its limit when **n** tends to infinity, is also called the *sum of the series*, thus the title of this task. For this task, use: $S_n = \displaystyle\sum_{k=1}^n \frac{1}{k^2}$.
|
||||
Calcola il termine **n**<sup>mo</sup> di una [serie](https://en.wikipedia.org/wiki/Series (mathematics)), cioè la somma dei primi **n** termini della successione [corrispondente](https://en.wikipedia.org/wiki/sequence). In modo informale questo valore, o il suo limite quando **n** tende all'infinito, è anche chiamato la *somma della serie*, quindi il titolo di questo compito. Per questo compito, usa: $S_n = \displaystyle\sum_{k=1}^n \frac{1}{k^2}$.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that take $a$ and $b$ as parameters and returns the sum of $a^{th}$ to $b^{th}$ members of the sequence.
|
||||
Scrivi una funzione che prende $a$ e $b$ come parametri e restituisce la somma dall'$a^{mo}$ al $b^{mo}$ elemento della successione.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sum` should be a function.
|
||||
`sum` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sum == 'function');
|
||||
```
|
||||
|
||||
`sum(1, 100)` should return a number.
|
||||
`sum(1, 100)` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof sum(1, 100) == 'number');
|
||||
```
|
||||
|
||||
`sum(1, 100)` should return `1.6349839001848923`.
|
||||
`sum(1, 100)` dovrebbe restituire `1.6349839001848923`.
|
||||
|
||||
```js
|
||||
assert.equal(sum(1, 100), 1.6349839001848923);
|
||||
```
|
||||
|
||||
`sum(33, 46)` should return `0.009262256361481223`.
|
||||
`sum(33, 46)` dovrebbe restituire `0.009262256361481223`.
|
||||
|
||||
```js
|
||||
assert.equal(sum(33, 46), 0.009262256361481223);
|
||||
```
|
||||
|
||||
`sum(21, 213)` should return `0.044086990748706555`.
|
||||
`sum(21, 213)` dovrebbe restituire `0.044086990748706555`.
|
||||
|
||||
```js
|
||||
assert.equal(sum(21, 213), 0.044086990748706555);
|
||||
```
|
||||
|
||||
`sum(11, 111)` should return `0.08619778593108679`.
|
||||
`sum(11, 111)` dovrebbe restituire `0.08619778593108679`.
|
||||
|
||||
```js
|
||||
assert.equal(sum(11, 111), 0.08619778593108679);
|
||||
```
|
||||
|
||||
`sum(1, 10)` should return `1.5497677311665408`.
|
||||
`sum(1, 10)` dovrebbe restituire `1.5497677311665408`.
|
||||
|
||||
```js
|
||||
assert.equal(sum(1, 10), 1.5497677311665408);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8042
|
||||
title: Sum of squares
|
||||
title: Somma di quadrati
|
||||
challengeType: 5
|
||||
forumTopicId: 302334
|
||||
dashedName: sum-of-squares
|
||||
@ -8,47 +8,47 @@ dashedName: sum-of-squares
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to find the sum of squares of an array of integers.
|
||||
Scrivi una funzione per trovare la somma dei quadrati di un array di interi.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sumsq` should be a function.
|
||||
`sumsq` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sumsq == 'function');
|
||||
```
|
||||
|
||||
`sumsq([1, 2, 3, 4, 5])` should return a number.
|
||||
`sumsq([1, 2, 3, 4, 5])` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert(typeof sumsq([1, 2, 3, 4, 5]) == 'number');
|
||||
```
|
||||
|
||||
`sumsq([1, 2, 3, 4, 5])` should return `55`.
|
||||
`sumsq([1, 2, 3, 4, 5])` dovrebbe restituire `55`.
|
||||
|
||||
```js
|
||||
assert.equal(sumsq([1, 2, 3, 4, 5]), 55);
|
||||
```
|
||||
|
||||
`sumsq([25, 32, 12, 7, 20])` should return `2242`.
|
||||
`sumsq([25, 32, 12, 7, 20])` dovrebbe restituire `2242`.
|
||||
|
||||
```js
|
||||
assert.equal(sumsq([25, 32, 12, 7, 20]), 2242);
|
||||
```
|
||||
|
||||
`sumsq([38, 45, 35, 8, 13])` should return `4927`.
|
||||
`sumsq([38, 45, 35, 8, 13])` dovrebbe restituire `4927`.
|
||||
|
||||
```js
|
||||
assert.equal(sumsq([38, 45, 35, 8, 13]), 4927);
|
||||
```
|
||||
|
||||
`sumsq([43, 36, 20, 34, 24])` should return `5277`.
|
||||
`sumsq([43, 36, 20, 34, 24])` dovrebbe restituire `5277`.
|
||||
|
||||
```js
|
||||
assert.equal(sumsq([43, 36, 20, 34, 24]), 5277);
|
||||
```
|
||||
|
||||
`sumsq([12, 33, 26, 18, 1, 16, 3])` should return `2499`.
|
||||
`sumsq([12, 33, 26, 18, 1, 16, 3])` dovrebbe restituire `2499`.
|
||||
|
||||
```js
|
||||
assert.equal(sumsq([12, 33, 26, 18, 1, 16, 3]), 2499);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8043
|
||||
title: Sum to 100
|
||||
title: Somma a 100
|
||||
challengeType: 5
|
||||
forumTopicId: 302335
|
||||
dashedName: sum-to-100
|
||||
@ -8,33 +8,33 @@ dashedName: sum-to-100
|
||||
|
||||
# --description--
|
||||
|
||||
Find solutions to the *sum to one hundred* puzzle.
|
||||
Trova le soluzioni per il puzzle *Somma a cento*.
|
||||
|
||||
Add (insert) the mathematical operators **+** or **─** (plus or minus) before any of the digits in the decimal numeric string **123456789** such that the resulting mathematical expression adds up to a particular sum (in this iconic case, **100**).
|
||||
Aggiungi (inserisci) gli operatori matematici **+** o **─** (più o meno) prima di una qualsiasi delle cifre della stringa numerica decimale **123456789** in modo che l'espressione matematica risultante sommi a una particolare somma (in questo caso iconico, **100**).
|
||||
|
||||
Example:
|
||||
Esempio:
|
||||
|
||||
<pre><b>123 + 4 - 5 + 67 - 89 = 100</b></pre>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a number as parameter. The function should return an array containing all solutions for the given number. The solutions should be strings representing the expressions. For example: "1+23-456+78-9". Sort the array before returning it.
|
||||
Scrivi una funzione che prende un numero come parametro. La funzione dovrebbe restituire un array contenente tutte le soluzioni per il numero dato. Le soluzioni dovrebbero essere stringhe che rappresentino le espressioni. Per esempio: "1+23-456+78-9". Ordina l'array prima di restituirlo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`sumTo100` should be a function.
|
||||
`sumTo100` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof sumTo100 == 'function');
|
||||
```
|
||||
|
||||
`sumTo100(199)` should return an array.
|
||||
`sumTo100(199)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(sumTo100(199)));
|
||||
```
|
||||
|
||||
`sumTo100(199)` should return `["-1+2-3+45+67+89", "123-4+5+6+78-9", "123-4+56+7+8+9"]`.
|
||||
`sumTo100(199)` dovrebbe restituire `["-1+2-3+45+67+89", "123-4+5+6+78-9", "123-4+56+7+8+9"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sumTo100(199), [
|
||||
@ -44,13 +44,13 @@ assert.deepEqual(sumTo100(199), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sumTo100(209)` should return `["1+234+56+7-89"]`.
|
||||
`sumTo100(209)` dovrebbe restituire `["1+234+56+7-89"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sumTo100(209), ['1+234+56+7-89']);
|
||||
```
|
||||
|
||||
`sumTo100(243)` should return `["-1-234+567-89", "-12+345+6-7-89", "123+45+6+78-9"]`.
|
||||
`sumTo100(243)` dovrebbe restituire `["-1-234+567-89", "-12+345+6-7-89", "123+45+6+78-9"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sumTo100(243), [
|
||||
@ -60,7 +60,7 @@ assert.deepEqual(sumTo100(243), [
|
||||
]);
|
||||
```
|
||||
|
||||
`sumTo100(197)` should return `["1-2-3+45+67+89", "12+34-5+67+89", "123+4-5+6+78-9"]`.
|
||||
`sumTo100(197)` dovrebbe restituire `["1-2-3+45+67+89", "12+34-5+67+89", "123+4-5+6+78-9"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(sumTo100(197), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8045
|
||||
title: Sutherland-Hodgman polygon clipping
|
||||
title: Taglio di un poligono di Sutherland-Hodgman
|
||||
challengeType: 5
|
||||
forumTopicId: 302336
|
||||
dashedName: sutherland-hodgman-polygon-clipping
|
||||
@ -8,27 +8,27 @@ dashedName: sutherland-hodgman-polygon-clipping
|
||||
|
||||
# --description--
|
||||
|
||||
The [Sutherland-Hodgman clipping algorithm](https://en.wikipedia.org/wiki/Sutherland-Hodgman clipping algorithm) finds the polygon that is the intersection between an arbitrary polygon (the "subject polygon") and a convex polygon (the "clip polygon"). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a polygon that do not need to be displayed. Take the closed polygon defined by the points:
|
||||
L'algoritmo [di ritaglio Sutherland-Hodgman](https://en.wikipedia.org/wiki/Sutherland-Hodgman clipping algorithm) trova il poligono che è l'intersezione tra un poligono arbitrario (il "poligono soggetto") e un poligono convesso (il "poligono di taglio"). Viene utilizzato nella grafica informatica (in particolare nella grafica 2D) per ridurre la complessità di una scena che viene visualizzata eliminando parti di un poligono che non hanno bisogno di essere visualizzate. Prende il poligono chiuso definito dai punti:
|
||||
|
||||
<pre>[(50, 150), (200, 50), (350, 150), (350, 300), (250, 300), (200, 250), (150, 350), (100, 250), (100, 200)]</pre>
|
||||
|
||||
and clip it by the rectangle defined by the points:
|
||||
e lo ritaglia dal rettangolo definito dai punti:
|
||||
|
||||
<pre>[(100, 100), (300, 100), (300, 300), (100, 300)]</pre>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes 2 arrays as parameters. The first array contains the points of the subject polygon and the second array contains the points of the clipping polygon. The function should return an array containing the points of the clipped polygon. Each number should be rounded to 3 decimal places.
|
||||
Scrivi una funzione che richiede 2 array come parametri. Il primo array contiene i punti del poligono soggetto e il secondo array contiene i punti del poligono di ritaglio. La funzione dovrebbe restituire un array contenente i punti del poligono ritagliato. Ogni numero deve essere arrotondato al terzo decimale.
|
||||
|
||||
# --hints--
|
||||
|
||||
`clip` should be a function.
|
||||
`clip` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof clip == 'function');
|
||||
```
|
||||
|
||||
`clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])` should return an array.
|
||||
`clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -56,7 +56,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])` should return `[[100, 116.667], [125, 100], [275, 100], [300, 116.667], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]]`.
|
||||
`clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])` dovrebbe restituire `[[100, 116.667], [125, 100], [275, 100], [300, 116.667], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -94,7 +94,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`clip([[150, 200], [400, 450], [30, 50]], [[10, 10], [300, 200], [400, 600], [100, 300]])` should return `[[150, 200], [350, 400], [348.611, 394.444], [30, 50]]`.
|
||||
`clip([[150, 200], [400, 450], [30, 50]], [[10, 10], [300, 200], [400, 600], [100, 300]])` dovrebbe restituire `[[150, 200], [350, 400], [348.611, 394.444], [30, 50]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -120,7 +120,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`clip([[250, 200], [100, 450], [130, 250]], [[50, 60], [100, 230], [400, 600], [100, 300]])` should return `[[129.167, 329.167], [119.565, 319.565], [121.854, 304.305]]`.
|
||||
`clip([[250, 200], [100, 450], [130, 250]], [[50, 60], [100, 230], [400, 600], [100, 300]])` dovrebbe restituire `[[129.167, 329.167], [119.565, 319.565], [121.854, 304.305]]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc8046
|
||||
title: Symmetric difference
|
||||
title: Differenza simmetrica
|
||||
challengeType: 5
|
||||
forumTopicId: 16086
|
||||
dashedName: symmetric-difference
|
||||
@ -8,21 +8,21 @@ dashedName: symmetric-difference
|
||||
|
||||
# --description--
|
||||
|
||||
Given two [set](https://rosettacode.org/wiki/set)s *A* and *B*, compute $(A \\setminus B) \\cup (B \\setminus A).$ That is, enumerate the items that are in *A* or *B* but not both. This set is called the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric difference) of *A* and *B*. In other words: $(A \\cup B) \\setminus (A \\cap B)$ (the set of items that are in at least one of *A* or *B* minus the set of items that are in both *A* and *B*).
|
||||
Dati due [insiemi](https://rosettacode.org/wiki/set) *A* e *B*, calcola $(A \\setminus B) \\cup (B \\setminus A). Vale a dire elenca gli elementi che sono in *A* o *B*, ma non in entrambi. Questo insieme è chiamato la [differenza simmetrica](https://en.wikipedia.org/wiki/Symmetric difference) di *A* e *B*. In altre parole: $(A \\cup B) \\setminus (A \\cap B)$ (l'insieme di elementi che sono in almeno uno di *A* o *B* meno l'insieme di elementi che sono sia in *A* che in *B*).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes two arrays as parameters and returns the symmetric difference. Sort the resultant array before returning it.
|
||||
Scrivi una funzione che prende due array come parametri e restituisce la differenza simmetrica. Ordina l'array risultante prima di restituirlo.
|
||||
|
||||
# --hints--
|
||||
|
||||
`symmetricDifference` should be a function.
|
||||
`symmetricDifference` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof symmetricDifference == 'function');
|
||||
```
|
||||
|
||||
`symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])` should return an array.
|
||||
`symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -35,7 +35,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])` should return `["Jim", "Serena"]`.
|
||||
`symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])` dovrebbe restituire `["Jim", "Serena"]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -47,13 +47,13 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`symmetricDifference([1, 2, 3], [3, 4])` should return `[1, 2, 4]`.
|
||||
`symmetricDifference([1, 2, 3], [3, 4])` dovrebbe restituire `[1, 2, 4]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(symmetricDifference([1, 2, 3], [3, 4]), [1, 2, 4]);
|
||||
```
|
||||
|
||||
`symmetricDifference([1, 2, 3, 4, 5], [3, 4, 8, 7])` should return `[1, 2, 5, 7, 8]`.
|
||||
`symmetricDifference([1, 2, 3, 4, 5], [3, 4, 8, 7])` dovrebbe restituire `[1, 2, 5, 7, 8]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(symmetricDifference([1, 2, 3, 4, 5], [3, 4, 8, 7]), [
|
||||
@ -65,7 +65,7 @@ assert.deepEqual(symmetricDifference([1, 2, 3, 4, 5], [3, 4, 8, 7]), [
|
||||
]);
|
||||
```
|
||||
|
||||
`symmetricDifference([1, 2, 3, 4, 5, 6, 7, 8], [1, 3, 5, 6, 7, 8, 9])` should return `[2, 4, 9]`.
|
||||
`symmetricDifference([1, 2, 3, 4, 5, 6, 7, 8], [1, 3, 5, 6, 7, 8, 9])` dovrebbe restituire `[2, 4, 9]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -74,7 +74,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`symmetricDifference([1, 2, 4, 7, 9], [2, 3, 7, 8, 9])` should return `[1, 3, 4, 8]`.
|
||||
`symmetricDifference([1, 2, 4, 7, 9], [2, 3, 7, 8, 9])` dovrebbe restituire `[1, 3, 4, 8]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(symmetricDifference([1, 2, 4, 7, 9], [2, 3, 7, 8, 9]), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594ecc0d9a8cf816e3340187
|
||||
title: Taxicab numbers
|
||||
title: Numeri dei taxi
|
||||
challengeType: 5
|
||||
forumTopicId: 302337
|
||||
dashedName: taxicab-numbers
|
||||
@ -8,67 +8,67 @@ dashedName: taxicab-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A [taxicab number](https://en.wikipedia.org/wiki/Hardy–Ramanujan number "wp: Hardy–Ramanujan number") (the definition that is being used here) is a positive integer that can be expressed as the sum of two positive cubes in more than one way.
|
||||
Un [numero taxicab](https://en.wikipedia.org/wiki/Hardy–Ramanujan number "wp: Hardy–Ramanujan number") (la definizione che viene utilizzata qui) è un intero positivo che può essere espresso come la somma di due cubi positivi in più di un modo.
|
||||
|
||||
The first taxicab number is `1729`, which is:
|
||||
Il primo numero di taxi è `1729`, che è:
|
||||
|
||||
1<sup>3</sup> + 12<sup>3</sup> and
|
||||
1<sup>3</sup> + 12<sup>3</sup> e
|
||||
|
||||
9<sup>3</sup> + 10<sup>3</sup>.
|
||||
|
||||
Taxicab numbers are also known as:
|
||||
I numeri dei taxi sono anche conosciuti come:
|
||||
|
||||
<ul>
|
||||
<li>taxi numbers</li>
|
||||
<li>taxi-cab numbers</li>
|
||||
<li>taxi cab numbers</li>
|
||||
<li>Hardy-Ramanujan numbers</li>
|
||||
<li>Numeri di Hardy-Ramanujan</li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns the lowest `n` taxicab numbers. For each of the taxicab numbers, show the number as well as its constituent cubes.
|
||||
Scrivi una funzione che restituisce i numeri di taxi più bassi `n`. Per ciascuno dei numeri taxicab indica il numero e i suoi cubi costituenti.
|
||||
|
||||
**See also:**
|
||||
**Vedi anche:**
|
||||
|
||||
<ul>
|
||||
<li><a href='https://oeis.org/A001235' target='_blank'>A001235 taxicab numbers</a> on The On-Line Encyclopedia of Integer Sequences.</li>
|
||||
<li><a href='https://en.wikipedia.org/wiki/Taxicab_number' target='_blank'>taxicab number</a> on Wikipedia.</li>
|
||||
<li><a href='https://oeis.org/A001235' target='_blank'>A001235 numeri taxicab</a> su Enciclopedia On-Line di sequenze di numeri interi.</li>
|
||||
<li><a href='https://en.wikipedia.org/wiki/Taxicab_number' target='_blank'>numero di taxi</a> su Wikipedia.</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`taxicabNumbers` should be a function.
|
||||
`taxicabNumbers` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof taxicabNumbers === 'function');
|
||||
```
|
||||
|
||||
`taxicabNumbers` should return an array.
|
||||
`taxicabNumbers` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(typeof taxicabNumbers(2) === 'object');
|
||||
```
|
||||
|
||||
`taxicabNumbers` should return an array of numbers.
|
||||
`taxicabNumbers` dovrebbe restituire un array di numeri.
|
||||
|
||||
```js
|
||||
assert(typeof taxicabNumbers(100)[0] === 'number');
|
||||
```
|
||||
|
||||
`taxicabNumbers(4)` should return [1729, 4104, 13832, 20683].
|
||||
`taxicabNumbers(4)` dovrebbe restituire [1729, 4104, 13832, 20683].
|
||||
|
||||
```js
|
||||
assert.deepEqual(taxicabNumbers(4), res4);
|
||||
```
|
||||
|
||||
`taxicabNumbers(25)` should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]
|
||||
`taxicabNumbers(25)` dovrebbe restituire [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]
|
||||
|
||||
```js
|
||||
assert.deepEqual(taxicabNumbers(25), res25);
|
||||
```
|
||||
|
||||
`taxicabNumbers(39)` resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].
|
||||
I numeri risultanti di `taxicabNumbers(39)` da 20 a 29 dovrebbero essere [314496,320264,327763,373464,402597,439101,443889,513000,513856].
|
||||
|
||||
```js
|
||||
assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594faaab4e2a8626833e9c3d
|
||||
title: Tokenize a string with escaping
|
||||
title: Tokenizzare una stringa con escaping
|
||||
challengeType: 5
|
||||
forumTopicId: 302338
|
||||
dashedName: tokenize-a-string-with-escaping
|
||||
@ -8,65 +8,65 @@ dashedName: tokenize-a-string-with-escaping
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function or program that can split a string at each non-escaped occurrence of a separator character.
|
||||
Scrivi una funzione o un programma che può dividere una stringa ad ogni occorrenza di un carattere separatore (salvo escape).
|
||||
|
||||
It should accept three input parameters:
|
||||
Dovrebbe accettare tre parametri di input:
|
||||
|
||||
<ul>
|
||||
<li>The <strong>string</strong></li>
|
||||
<li>The <strong>separator character</strong></li>
|
||||
<li>The <strong>escape character</strong></li>
|
||||
<li>La <strong>stringa</strong></li>
|
||||
<li>Il carattere <strong>separatore</strong></li>
|
||||
<li>Il <strong>carattere di escape</strong></li>
|
||||
</ul>
|
||||
|
||||
It should output a list of strings.
|
||||
Dovrebbe produrre un elenco di stringhe.
|
||||
|
||||
Rules for splitting:
|
||||
Regole di suddivisione:
|
||||
|
||||
<ul>
|
||||
<li>The fields that were separated by the separators, become the elements of the output list.</li>
|
||||
<li>Empty fields should be preserved, even at the start and end.</li>
|
||||
<li>I campi separati dai separatori diventano gli elementi della lista di output.</li>
|
||||
<li>I campi vuoti dovrebbero essere preservati, anche all'inizio e alla fine.</li>
|
||||
</ul>
|
||||
|
||||
Rules for escaping:
|
||||
Regole di escape:
|
||||
|
||||
<ul>
|
||||
<li>"Escaped" means preceded by an occurrence of the escape character that is not already escaped itself.</li>
|
||||
<li>When the escape character precedes a character that has no special meaning, it still counts as an escape (but does not do anything special).</li>
|
||||
<li>Each occurrences of the escape character that was used to escape something, should not become part of the output.</li>
|
||||
<li>"Fare l'escape" significa far precedere il carattere da una occorrenza del carattere di escape.</li>
|
||||
<li>Quando il carattere di escape precede un carattere che non ha alcun significato speciale, conta ancora come un escape (ma non fa nulla di speciale).</li>
|
||||
<li>Ogni occorrenza del carattere di escape che è stato usato per evitare qualcosa, non dovrebbe diventare parte dell'output.</li>
|
||||
</ul>
|
||||
|
||||
Demonstrate that your function satisfies the following test-case:
|
||||
Dimostra che la tua funzione soddisfa il seguente caso di test:
|
||||
|
||||
Given the string
|
||||
Data la stringa
|
||||
|
||||
<pre>one^|uno||three^^^^|four^^^|^cuatro|</pre>
|
||||
|
||||
and using `|` as a separator and `^` as escape character, your function should output the following array:
|
||||
e usando `|` come separatore e `^` come carattere di escape la funzione dovrebbe produrre il seguente array:
|
||||
|
||||
<pre> ['one|uno', '', 'three^^', 'four^|cuatro', '']
|
||||
</pre>
|
||||
|
||||
# --hints--
|
||||
|
||||
`tokenize` should be a function.
|
||||
`tokenize` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof tokenize === 'function');
|
||||
```
|
||||
|
||||
`tokenize` should return an array.
|
||||
`tokenize` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(typeof tokenize('a', 'b', 'c') === 'object');
|
||||
```
|
||||
|
||||
`tokenize('one^|uno||three^^^^|four^^^|^cuatro|', '|', '^')` should return `['one|uno', '', 'three^^', 'four^|cuatro', '']`
|
||||
`tokenize('one^|uno||three^^^^|four^^^|^cuatro|', '|', '^')` dovrebbe restituire `['one|uno', '', 'three^^', 'four^|cuatro', '']`
|
||||
|
||||
```js
|
||||
assert.deepEqual(tokenize(testStr1, '|', '^'), res1);
|
||||
```
|
||||
|
||||
`tokenize('a@&bcd&ef&&@@hi', '&', '@')` should return `['a&bcd', 'ef', '', '@hi']`
|
||||
`tokenize('a@&bcd&ef&&@@hi', '&', '@')` dovrebbe restituire `['a&bcd', 'ef', '', '@hi']`
|
||||
|
||||
```js
|
||||
assert.deepEqual(tokenize(testStr2, '&', '@'), res2);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 595011cba5a81735713873bd
|
||||
title: Top rank per group
|
||||
title: Classifica superiore per gruppo
|
||||
challengeType: 5
|
||||
forumTopicId: 302339
|
||||
dashedName: top-rank-per-group
|
||||
@ -8,9 +8,9 @@ dashedName: top-rank-per-group
|
||||
|
||||
# --description--
|
||||
|
||||
Find the top `n` ranked data in each group, where `n` is provided as a parameter. Name of the rank and the group are also provided as parameter.
|
||||
Trova i primi `n` dati classificati in ogni gruppo, dove `n` è fornito come parametro. Anche il nome del rango e del gruppo sono forniti come parametri.
|
||||
|
||||
Given the following data:
|
||||
Forniti i seguenti dati:
|
||||
|
||||
```js
|
||||
testData1 = [
|
||||
@ -30,13 +30,13 @@ testData1 = [
|
||||
];
|
||||
```
|
||||
|
||||
One could rank top 10 employees in each department by calling:
|
||||
Si potrebbero classificare i primi 10 dipendenti in ogni reparto chiamando:
|
||||
|
||||
```js
|
||||
topRankPerGroup(10, testData1, 'dept', 'salary')
|
||||
```
|
||||
|
||||
Given the following data:
|
||||
Forniti i seguenti dati:
|
||||
|
||||
```js
|
||||
testData2 = [
|
||||
@ -48,15 +48,15 @@ testData2 = [
|
||||
];
|
||||
```
|
||||
|
||||
One could rank the top-rated movie in each genre by calling:
|
||||
Si potrebbe classificare il film più votato in ogni genere chiamando:
|
||||
|
||||
```js
|
||||
topRankPerGroup(1, testData2, 'genre', 'rating')
|
||||
```
|
||||
|
||||
The function should return an array with an array for each group containing the top `n` objects.
|
||||
La funzione dovrebbe restituire un array con un array per ogni gruppo contenente gli `n` oggetti superiori.
|
||||
|
||||
For example, given data:
|
||||
Per esempio, dati:
|
||||
|
||||
```js
|
||||
[
|
||||
@ -69,7 +69,7 @@ For example, given data:
|
||||
];
|
||||
```
|
||||
|
||||
Top two ranking employees in each department by salary would be:
|
||||
I primi due dipendenti in classifica per stipendio in ogni reparto saranno:
|
||||
|
||||
```js
|
||||
[ [ { name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D050' },
|
||||
@ -80,37 +80,37 @@ Top two ranking employees in each department by salary would be:
|
||||
|
||||
# --hints--
|
||||
|
||||
`topRankPerGroup` should be a function.
|
||||
`topRankPerGroup` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof topRankPerGroup === 'function');
|
||||
```
|
||||
|
||||
`topRankPerGroup` should return undefined on negative n values.
|
||||
`topRankPerGroup` dovrebbe restituire undefined per i valori negativi di n.
|
||||
|
||||
```js
|
||||
assert(typeof topRankPerGroup(-1, []) === 'undefined');
|
||||
```
|
||||
|
||||
For `topRankPerGroup(10, testData1, 'dept', 'salary')`, the first result in the first group should be `{ name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050'}`.
|
||||
Per `topRankPerGroup(10, testData1, 'dept', 'salary')`, il primo risultato nel primo gruppo dovrebbe essere `{ name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050'}`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(res1[0][0], { name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050'});
|
||||
```
|
||||
|
||||
For `topRankPerGroup(10, testData1, 'dept', 'salary')`, the last result in the last group should be `{ name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' }`.
|
||||
Per `topRankPerGroup(10, testData1, 'dept', 'salary')`, l'ultimo risultato nell'ultimo gruppo dovrebbe essere `{ name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' }`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(res1[3][3], { name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' });
|
||||
```
|
||||
|
||||
`topRankPerGroup(1, ...)` should return only top ranking result per group.
|
||||
`topRankPerGroup(1, ...)` dovrebbe restituire solo il il primo risultato in classifica per ogni gruppo.
|
||||
|
||||
```js
|
||||
assert.equal(res2[2].length, 1);
|
||||
```
|
||||
|
||||
`topRankPerGroup(2, ...)` should return two ranking results per group.
|
||||
`topRankPerGroup(2, ...)` dovrebbe restituire due risultati di classifica per gruppo.
|
||||
|
||||
```js
|
||||
assert.equal(res3[2][1].name, 'Maze Runner');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594fa2746886f41f7d8bf225
|
||||
title: Topological sort
|
||||
title: Ordinamento topologico
|
||||
challengeType: 5
|
||||
forumTopicId: 302340
|
||||
dashedName: topological-sort
|
||||
@ -8,21 +8,21 @@ dashedName: topological-sort
|
||||
|
||||
# --description--
|
||||
|
||||
Given a mapping between items, and items they depend on, a topological sort orders items so that no item precedes an item it depends upon. There are two popular algorithms for topological sorting: Kahn's (1962) topological sort and depth-first search.
|
||||
Data una mappatura tra elementi, e elementi da cui dipendono, un ordine topologico ordina elementi in modo che nessun elemento ne precede uno da cui dipende. Ci sono due algoritmi popolari per l'ordinamento topologico: l'ordinamento topologico di Kahn (1962) e la ricerca depth-first.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that will return a list with valid compile order of libraries from their dependencies.
|
||||
Scrivi una funzione che restituirà una lista con un valido ordine di compilazione delle librerie dalle loro dipendenze.
|
||||
|
||||
- Assume library names are single words.
|
||||
- Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.
|
||||
- Any self dependencies should be ignored.
|
||||
- Any un-orderable dependencies should be ignored.
|
||||
- Supponiamo che i nomi delle librerie siano parole singole.
|
||||
- Gli elementi citati solo come persone a carico non hanno dipendenze proprie, ma il loro ordine di compilazione deve essere dato.
|
||||
- Qualsiasi autosufficienza dovrebbe essere ignorata.
|
||||
- Eventuali dipendenze non ordinabili dovrebbero essere ignorate.
|
||||
|
||||
Use the following data as an example:
|
||||
Utilizzare i seguenti dati come esempio:
|
||||
|
||||
<pre>
|
||||
LIBRARY LIBRARY DEPENDENCIES
|
||||
LIBRERIA DIPENDENZA DELLE LIBRERIE
|
||||
======= ====================
|
||||
des_system_lib std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee
|
||||
dw01 ieee dw01 dware gtech
|
||||
@ -39,11 +39,11 @@ std_cell_lib ieee std_cell_lib
|
||||
synopsys
|
||||
</pre>
|
||||
|
||||
The compiling of a library in the VHDL language has the constraint that a library must be compiled after any library it depends on. The above data would be un-orderable if, for example, `dw04` is added to the list of dependencies of `dw01`.
|
||||
La compilazione di una libreria nel linguaggio VHDL ha il vincolo che una libreria può essere compilata solo dopo ogni libreria da cui dipende. I dati di cui sopra non sarebbero ordinabili se, ad esempio, `dw04` venisse aggiunto alla lista delle dipendenze di `dw01`.
|
||||
|
||||
The input of the function will be a multiline string, each line will consist of the name of the library, followed by its dependencies (if exist).
|
||||
L'input della funzione sarà una stringa multilinea, ogni riga consisterà del nome della libreria, seguito dalle sue dipendenze (se esistenti).
|
||||
|
||||
For example:
|
||||
Ad esempio:
|
||||
|
||||
```js
|
||||
const libsSimple =
|
||||
@ -53,37 +53,37 @@ const libsSimple =
|
||||
|
||||
# --hints--
|
||||
|
||||
`topologicalSort` should be a function.
|
||||
`topologicalSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof topologicalSort === 'function');
|
||||
```
|
||||
|
||||
`topologicalSort(libsSimple)` should return an array.
|
||||
`topologicalSort(libsSimple)` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(topologicalSort(libsSimple)));
|
||||
```
|
||||
|
||||
`topologicalSort(libsSimple)` should return `['bbb', 'aaa']`.
|
||||
`topologicalSort(libsSimple)` dovrebbe restituire `['bbb', 'aaa']`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(topologicalSort(libsSimple), ['bbb', 'aaa']);
|
||||
```
|
||||
|
||||
`topologicalSort(libsVHDL)` should return `['ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', 'dw03', 'des_system_lib']`.
|
||||
`topologicalSort(libsVHDL)` dovrebbe restituire `['ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', 'dw03', 'des_system_lib']`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(topologicalSort(libsVHDL), ['ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', 'dw03', 'des_system_lib']);
|
||||
```
|
||||
|
||||
`topologicalSort(libsCustom)` should return `['base', 'c', 'd', 'b', 'a']`.
|
||||
`topologicalSort(libsCustom)` dovrebbe restituire `['base', 'c', 'd', 'b', 'a']`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(topologicalSort(libsCustom), ['base', 'c', 'd', 'b', 'a']);
|
||||
```
|
||||
|
||||
`topologicalSort` should ignore unorderable dependencies.
|
||||
`topologicalSort` dovrebbe ignorare le dipendenze non ordinabili.
|
||||
|
||||
```js
|
||||
assert.deepEqual(topologicalSort(libsUnorderable), ['Base']);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5951ed8945deab770972ae56
|
||||
title: Towers of Hanoi
|
||||
title: Torri di Hanoi
|
||||
challengeType: 5
|
||||
forumTopicId: 302341
|
||||
dashedName: towers-of-hanoi
|
||||
@ -8,41 +8,41 @@ dashedName: towers-of-hanoi
|
||||
|
||||
# --description--
|
||||
|
||||
Solve the [Towers of Hanoi](https://en.wikipedia.org/wiki/Towers_of_Hanoi "wp: Towers_of_Hanoi") problem.
|
||||
Risolvi il problema delle [Torri di Hanoi](https://en.wikipedia.org/wiki/Towers_of_Hanoi "wp: Towers_of_Hanoi").
|
||||
|
||||
Your solution should accept the number of discs as the first parameters, and three string used to identify each of the three stacks of discs, for example `towerOfHanoi(4, 'A', 'B', 'C')`. The function should return an array of arrays containing the list of moves, source -> destination.
|
||||
La soluzione dovrebbe accettare il numero di dischi come primo parametro, e tre stringhe usate per identificare ciascuna delle tre pile di dischi, ad esempio `towerOfHanoi(4, 'A', 'B', 'C')`. La funzione dovrebbe restituire un array di array contenente l'elenco delle mosse, sorgente -> destinazione.
|
||||
|
||||
For example, the array `[['A', 'C'], ['B', 'A']]` indicates that the 1st move was to move a disc from stack A to C, and the 2nd move was to move a disc from stack B to A.
|
||||
Per esempio, l'array `[['A', 'C'], ['B', 'A']]` indica che la prima mossa è stata di spostare un disco dalla pila A alla C, e la seconda mossa è stata quella di spostare un disco dalla pila B alla A.
|
||||
|
||||
<p></p>
|
||||
|
||||
# --hints--
|
||||
|
||||
`towerOfHanoi` should be a function.
|
||||
`towerOfHanoi` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof towerOfHanoi === 'function');
|
||||
```
|
||||
|
||||
`towerOfHanoi(3, ...)` should return 7 moves.
|
||||
`towerOfHanoi(3, ...)` dovrebbe restituire 7 mosse.
|
||||
|
||||
```js
|
||||
assert(res3.length === 7);
|
||||
```
|
||||
|
||||
`towerOfHanoi(3, 'A', 'B', 'C')` should return `[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B']]`.
|
||||
`towerOfHanoi(3, 'A', 'B', 'C')` dovrebbe restituire `[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B']]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);
|
||||
```
|
||||
|
||||
`towerOfHanoi(5, "X", "Y", "Z")` 10th move should be Y -> X.
|
||||
La decima mossa di `towerOfHanoi(5, "X", "Y", "Z")` dovrebbe essere Y -> X.
|
||||
|
||||
```js
|
||||
assert.deepEqual(res5[9], ['Y', 'X']);
|
||||
```
|
||||
|
||||
`towerOfHanoi(7, 'A', 'B', 'C')` first ten moves should be `[['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B'], ['A','C'], ['B','C'], ['B','A']]`
|
||||
Le prime dieci mosse di `towerOfHanoi(7, 'A', 'B', 'C')` dovrebbero essere `['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B'], ['A','C'], ['B','A']]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad2
|
||||
title: Vector cross product
|
||||
title: Prodotto vettoriale
|
||||
challengeType: 5
|
||||
forumTopicId: 302342
|
||||
dashedName: vector-cross-product
|
||||
@ -8,27 +8,27 @@ dashedName: vector-cross-product
|
||||
|
||||
# --description--
|
||||
|
||||
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z).
|
||||
Un vettore è definito come avente tre dimensioni e può essere rappresentato da una raccolta ordinata di tre numeri: (X, Y, Z).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes two vectors (arrays) as input and computes their cross product. Your function should return `null` on invalid inputs such as vectors of different lengths.
|
||||
Scrivi una funzione che prende due vettori (arrays) come input e calcola il loro prodotto vettoriale. La tua funzione dovrebbe restituire `null` su input non validi, come vettori di diverse lunghezze.
|
||||
|
||||
# --hints--
|
||||
|
||||
`crossProduct` should be a function.
|
||||
`crossProduct` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof crossProduct, 'function');
|
||||
```
|
||||
|
||||
`crossProduct()` should return null.
|
||||
`crossProduct()` dovrebbe restituire null.
|
||||
|
||||
```js
|
||||
assert.equal(crossProduct(), null);
|
||||
```
|
||||
|
||||
`crossProduct([1, 2, 3], [4, 5, 6])` should return `[-3, 6, -3]`.
|
||||
`crossProduct([1, 2, 3], [4, 5, 6])` dovrebbe restituire `[-3, 6, -3]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(res12, exp12);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad3
|
||||
title: Vector dot product
|
||||
title: Prodotto scalare
|
||||
challengeType: 5
|
||||
forumTopicId: 302343
|
||||
dashedName: vector-dot-product
|
||||
@ -8,51 +8,51 @@ dashedName: vector-dot-product
|
||||
|
||||
# --description--
|
||||
|
||||
A vector can have one or more values represented by an ordered collection. Examples could be (x), (x, y), or (x, y, z).
|
||||
Un vettore può avere uno o più valori rappresentati da una collezione ordinata. Esempi potrebbero essere (x), (x, y), o (x, y, z).
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes two vectors (represented as one-dimensional arrays) as input and computes their dot product. Your function should return `null` on invalid inputs such as vectors of different lengths or passing anything other than two vectors.
|
||||
Scrivi una funzione che prende due vettori (rappresentati come matrici unidimensionali) come input e calcola il loro prodotto scalare. La tua funzione dovrebbe restituire `null` per input non validi come vettori di diverse lunghezze, o per qualsiasi cosa che non sia due vettori.
|
||||
|
||||
# --hints--
|
||||
|
||||
`dotProduct` should be a function.
|
||||
`dotProduct` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof dotProduct, 'function');
|
||||
```
|
||||
|
||||
`dotProduct()` should return `null`.
|
||||
`dotProduct()` dovrebbe restituire `null`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct(), null);
|
||||
```
|
||||
|
||||
`dotProduct([1], [1])` should return `1`.
|
||||
`dotProduct([1], [1])` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([1], [1]), 1);
|
||||
```
|
||||
|
||||
`dotProduct([1], [1, 2])` should return `null`.
|
||||
`dotProduct([1], [1, 2])` dovrebbe restituire `null`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([1], [1, 2]), null);
|
||||
```
|
||||
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` should return `3`.
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` dovrebbe restituire `3`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3);
|
||||
```
|
||||
|
||||
`dotProduct([3, 2, 1], [2, 4, 2], [5, 3, 1])` should return `null`.
|
||||
`dotProduct([3, 2, 1], [2, 4, 2], [5, 3, 1])` dovrebbe restituire `null`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([3, 2, 1], [2, 4, 2], [5, 3, 1]), null);
|
||||
```
|
||||
|
||||
`dotProduct([ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ])` should return `360`.
|
||||
`dotProduct([ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ])` dovrebbe restituire `360`.
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ]), 360);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5e94a54cc7b022105bf0fd2c
|
||||
title: Word frequency
|
||||
title: Frequenza delle parole
|
||||
challengeType: 5
|
||||
forumTopicId: 393913
|
||||
dashedName: word-frequency
|
||||
@ -8,68 +8,68 @@ dashedName: word-frequency
|
||||
|
||||
# --description--
|
||||
|
||||
Given a text string and an integer n, return the n most common words in the file (and the number of their occurrences) in decreasing frequency.
|
||||
Data una stringa di testo e un intero n, restituire le n parole più comuni nel file (e il numero delle loro occorrenze) in ordine di frequenza decrescente.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to count the occurrences of each word and return the n most commons words along with the number of their occurences in decreasing frequency.
|
||||
Scrivere una funzione per contare le occorrenze di ogni parola e restituire le n parole più comuni insieme al numero delle loro occorrenze in ordine di frequenza decrescente.
|
||||
|
||||
The function should return a 2D array with each of the elements in the following form: `[word, freq]`. `word` should be the lowercase version of the word and `freq` the number denoting the count.
|
||||
La funzione dovrebbe restituire un array 2D con ciascuno degli elementi nella seguente forma: `[word, freq]`. `word` dovrebbe essere la versione minuscola della parola e `freq` il numero che indica il conteggio.
|
||||
|
||||
The function should return an empty array, if no string is provided.
|
||||
La funzione dovrebbe restituire un array vuoto, se non viene fornita alcuna stringa.
|
||||
|
||||
The function should be case insensitive, for example, the strings "Hello" and "hello" should be treated the same.
|
||||
La funzione dovrebbe ignorare maiuscole e minuscole, per esempio, le stringe "Hello" e "hello" devono essere trattate allo stesso modo.
|
||||
|
||||
You can treat words that have special characters such as underscores, dashes, apostrophes, commas, etc., as distinct words.
|
||||
Puoi le parole che hanno caratteri speciali come sottolineature, trattini, apostrofi, virgole, ecc., come parole distinte.
|
||||
|
||||
For example, given the string "Hello hello goodbye", your function should return `[['hello', 2], ['goodbye', 1]]`.
|
||||
Per esempio, data la stringa "Hello hello goodbye", la tua funzione dovrebbe restituire `[['hello', 2], ['goodbye', 1]]`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`wordFrequency` should be a function.
|
||||
`wordFrequency` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof wordFrequency == 'function');
|
||||
```
|
||||
|
||||
`wordFrequency` should return an array.
|
||||
`wordFrequency` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(wordFrequency('test')));
|
||||
```
|
||||
|
||||
`wordFrequency("Hello hello world", 2)` should return `[['hello', 2], ['world', 1]]`
|
||||
`wordFrequency("Hello hello world", 2)` dovrebbe restituire `[['hello', 2], ['world', 1]]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(wordFrequency(example_1, 2), example_1_solution);
|
||||
```
|
||||
|
||||
`wordFrequency("The quick brown fox jumped over the lazy dog", 1)` should return `[['the', 2]]`
|
||||
`wordFrequency("The quick brown fox jumped over the lazy dog", 1)` dovrebbe restituire `[['the', 2]]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(wordFrequency(example_2, 1), example_2_solution);
|
||||
```
|
||||
|
||||
`wordFrequency("Opensource opensource open-source open source", 1)` should return `[['opensource', 2]]`
|
||||
`wordFrequency("Opensource opensource open-source open source", 1)` dovrebbe restituire `[['opensource', 2]]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(wordFrequency(example_3, 1), example_3_solution);
|
||||
```
|
||||
|
||||
`wordFrequency("Apple App apply aPP aPPlE", 3)` should return `[['app', 2], ['apple', 2], ['apply', 1]]` or `[['apple', 2], ['app', 2], ['apply', 1]]`
|
||||
`wordFrequency("Apple App apply aPP aPPlE", 3)` dovrebbe restituire `[['app', 2], ['apple', 2], ['apply', 1]]` oppure `[['apple', 2], ['app', 2], ['apply', 1]]`
|
||||
|
||||
```js
|
||||
const arr = JSON.stringify(wordFrequency(example_4, 3));
|
||||
assert(arr === example_4_solution_a || arr === example_4_solution_b);
|
||||
```
|
||||
|
||||
`wordFrequency("c d a d c a b d d c", 4)` should return `[['d', 4], ['c', 3], ['a', 2], ['b', 1]]`
|
||||
`wordFrequency("c d a d c a b d d c", 4)` dovrebbe restituire `[['d', 4], ['c', 3], ['a', 2], ['b', 1]]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(wordFrequency(example_5, 4), example_5_solution);
|
||||
```
|
||||
|
||||
`wordFrequency("", 5)` should return `[]`
|
||||
`wordFrequency("", 5)` dovrebbe restituire `[]`
|
||||
|
||||
```js
|
||||
assert.deepEqual(wordFrequency(example_6, 5), example_6_solution);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad4
|
||||
title: Word wrap
|
||||
title: Mandare a capo
|
||||
challengeType: 5
|
||||
forumTopicId: 302344
|
||||
dashedName: word-wrap
|
||||
@ -8,11 +8,11 @@ dashedName: word-wrap
|
||||
|
||||
# --description--
|
||||
|
||||
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. The basic task is to wrap a paragraph of text in a simple way.
|
||||
Ancora oggi, con caratteri proporzionali e layout complessi, ci sono ancora casi in cui è necessario mandare a capo il testo in una colonna specificata. Il compito di base è quello di chiudere un paragrafo di testo in modo semplice.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that can wrap this text to any number of characters. As an example, the text wrapped to 80 characters should look like the following:
|
||||
Scrivi una funzione che può mandare a capo questo testo a qualsiasi numero di caratteri. Ad esempio, il testo a capo di 80 caratteri dovrebbe assomigliare a quanto segue:
|
||||
|
||||
<pre>
|
||||
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX
|
||||
@ -23,37 +23,37 @@ than a simple minimum length algorithm.
|
||||
|
||||
# --hints--
|
||||
|
||||
wrap should be a function.
|
||||
wrap dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof wrap, 'function');
|
||||
```
|
||||
|
||||
wrap should return a string.
|
||||
wrap dovrebbe restituire una stringa.
|
||||
|
||||
```js
|
||||
assert.equal(typeof wrap('abc', 10), 'string');
|
||||
```
|
||||
|
||||
wrap(80) should return 4 lines.
|
||||
wrap(80) dovrebbe restituire 4 righe.
|
||||
|
||||
```js
|
||||
assert(wrapped80.split('\n').length === 4);
|
||||
```
|
||||
|
||||
Your `wrap` function should return our expected text.
|
||||
La funzione `wrap` dovrebbe restituire il testo previsto.
|
||||
|
||||
```js
|
||||
assert.equal(wrapped80.split('\n')[0], firstRow80);
|
||||
```
|
||||
|
||||
wrap(42) should return 7 lines.
|
||||
wrap(42) dovrebbe restituire 7 righe.
|
||||
|
||||
```js
|
||||
assert(wrapped42.split('\n').length === 7);
|
||||
```
|
||||
|
||||
Your `wrap` function should return our expected text.
|
||||
La funzione `wrap` dovrebbe restituire il testo previsto.
|
||||
|
||||
```js
|
||||
assert.equal(wrapped42.split('\n')[0], firstRow42);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad5
|
||||
title: Y combinator
|
||||
title: Combinatore Y
|
||||
challengeType: 5
|
||||
forumTopicId: 302345
|
||||
dashedName: y-combinator
|
||||
@ -8,11 +8,11 @@ dashedName: y-combinator
|
||||
|
||||
# --description--
|
||||
|
||||
In strict [functional programming](https://en.wikipedia.org/wiki/Functional programming "wp: functional programming") and the [lambda calculus](https://en.wikipedia.org/wiki/lambda calculus "wp: lambda calculus"), functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's state is used in the body of the function. The [Y combinator](https://mvanier.livejournal.com/2897.html) is itself a stateless function that, when applied to another stateless function, returns a recursive version of the function. The Y combinator is the simplest of the class of such functions, called [fixed-point combinators](https://en.wikipedia.org/wiki/Fixed-point combinator "wp: fixed-point combinator").
|
||||
In rigorosa [proframmazione funzionale](https://www.freecodecamp.org/news/the-principles-of-functional-programming/ "news: the principles of functional programming") e [calcolo lambda](https://en.wikipedia.org/wiki/lambda calculus "wp: lambda calculus"), le funzioni (espressioni lambda) non hanno stato e sono autorizzate solo a fare riferimento a argomenti di funzioni di chiusura. Questo esclude la definizione abituale di una funzione ricorsiva in cui una funzione è associata allo stato di una variabile e lo stato di questa variabile è usato nel corpo della funzione. Il combinatore [Y](https://mvanier.livejournal.com/2897.html) è di per sé una funzione apolide che, se applicata ad un'altra funzione senza stato, restituisce una versione ricorsiva della funzione. Il combinatore Y è il più semplice della classe di tali funzioni, chiamati [combinatori a punto fisso](https://en.wikipedia.org/wiki/Fixed-point combinator "wp: fixed-point combinator").
|
||||
|
||||
# --instructions--
|
||||
|
||||
Define the stateless Y combinator function and use it to compute [factorial](https://en.wikipedia.org/wiki/Factorial "wp: factorial"). The `factorial(N)` function is already given to you. **See also:**
|
||||
Definire la funzione di combinatore Y senza stato e usarla per calcolare il [fattoriale](https://en.wikipedia.org/wiki/Factorial "wp: factorial"). La funzione `factorial(N)` ti viene data. **Vedi anche:**
|
||||
|
||||
<ul>
|
||||
<li><a href="https://vimeo.com/45140590" target="_blank">Jim Weirich: Adventures in Functional Programming</a>.</li>
|
||||
@ -20,37 +20,37 @@ Define the stateless Y combinator function and use it to compute [factorial](htt
|
||||
|
||||
# --hints--
|
||||
|
||||
Y should return a function.
|
||||
Y dovrebbe restituire una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof Y((f) => (n) => n), 'function');
|
||||
```
|
||||
|
||||
factorial(1) should return 1.
|
||||
factorial(1) dovrebbe restituire 1.
|
||||
|
||||
```js
|
||||
assert.equal(factorial(1), 1);
|
||||
```
|
||||
|
||||
factorial(2) should return 2.
|
||||
factorial(2) dovrebbe restituire 2.
|
||||
|
||||
```js
|
||||
assert.equal(factorial(2), 2);
|
||||
```
|
||||
|
||||
factorial(3) should return 6.
|
||||
factorial(3) dovrebbe restituire 6.
|
||||
|
||||
```js
|
||||
assert.equal(factorial(3), 6);
|
||||
```
|
||||
|
||||
factorial(4) should return 24.
|
||||
factorial(4) dovrebbe restituire 24.
|
||||
|
||||
```js
|
||||
assert.equal(factorial(4), 24);
|
||||
```
|
||||
|
||||
factorial(10) should return 3628800.
|
||||
factorial(10) dovrebbe restituire 3628800.
|
||||
|
||||
```js
|
||||
assert.equal(factorial(10), 3628800);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad6
|
||||
title: Zeckendorf number representation
|
||||
title: Rappresentazione di Zeckendorf dei numeri
|
||||
challengeType: 5
|
||||
forumTopicId: 302346
|
||||
dashedName: zeckendorf-number-representation
|
||||
@ -8,144 +8,144 @@ dashedName: zeckendorf-number-representation
|
||||
|
||||
# --description--
|
||||
|
||||
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: `1, 2, 3, 5, 8, 13`.
|
||||
Così come i numeri possono essere rappresentati in una notazione posizionale come somme di multipli delle potenze di dieci (decimali) o due (binario), tutti gli interi positivi possono essere rappresentati come la somma di una o zero volte i membri distinti della serie di Fibonacci. Ricorda che i primi sei numeri distinti di Fibonacci sono: `1, 2, 3, 5, 8, 13`.
|
||||
|
||||
The decimal number eleven can be written as `0*13 + 1*8 + 0*5 + 1*3 + 0*2 + 0*1` or `010100` in positional notation where the columns represent multiplication by a particular member of the sequence. Leading zeroes are dropped so that 11 decimal becomes `10100`. 10100 is not the only way to make 11 from the Fibonacci numbers however `0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1` or 010011 would also represent decimal 11. For a true Zeckendorf number there is the added restriction that *no two consecutive Fibonacci numbers can be used* which leads to the former unique solution.
|
||||
Il numero decimale undici può essere scritto come `0*13 + 1*8 + 0*5 + 1*3 + 0*2 + 0*1` o `010100` nella notazione posizionale in cui le colonne rappresentano la moltiplicazione per un particolare membro della sequenza. Gli zeri iniziali sono caduti in modo che 11 decimale diventa `10100`. 10100 non è l'unico modo per formare 11 dai numeri di Fibonacci: anche `0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1` o 010011 rappresenta il decimale 11. Per un vero numero di Zeckendorf c'è la restrizione che *non possono essere utilizzati due numeri consecutivi di Fibonacci* che porta alla precedente soluzione unica.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that generates and returns the Zeckendorf number representation of `n`.
|
||||
Scrivi una funzione che genera e restituisce la rappresentazione di Zeckendorf del numero `n`.
|
||||
|
||||
# --hints--
|
||||
|
||||
`zeckendorf` should be a function.
|
||||
`zeckendorf` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof zeckendorf, 'function');
|
||||
```
|
||||
|
||||
`zeckendorf(0)` should return `0`.
|
||||
`zeckendorf(0)` dovrebbe restituire `0`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(0), 0);
|
||||
|
||||
```
|
||||
|
||||
`zeckendorf(1)` should return `1`.
|
||||
`zeckendorf(1)` dovrebbe restituire `1`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(1), 1);
|
||||
```
|
||||
|
||||
`zeckendorf(2)` should return `10`.
|
||||
`zeckendorf(2)` dovrebbe restituire `10`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(2), 10);
|
||||
```
|
||||
|
||||
`zeckendorf(3)` should return `100`.
|
||||
`zeckendorf(3)` dovrebbe restituire `100`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(3), 100);
|
||||
```
|
||||
|
||||
`zeckendorf(4)` should return `101`.
|
||||
`zeckendorf(4)` dovrebbe restituire `101`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(4), 101);
|
||||
```
|
||||
|
||||
`zeckendorf(5)` should return `1000`.
|
||||
`zeckendorf(5)` dovrebbe restituire `1000`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(5), 1000);
|
||||
```
|
||||
|
||||
`zeckendorf(6)` should return `1001`.
|
||||
`zeckendorf(6)` dovrebbe restituire `1001`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(6), 1001);
|
||||
```
|
||||
|
||||
`zeckendorf(7)` should return `1010`.
|
||||
`zeckendorf(7)` dovrebbe restituire `1010`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(7), 1010);
|
||||
```
|
||||
|
||||
`zeckendorf(8)` should return `10000`.
|
||||
`zeckendorf(8)` dovrebbe restituire `10000`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(8), 10000);
|
||||
```
|
||||
|
||||
`zeckendorf(9)` should return `10001`.
|
||||
`zeckendorf(9)` dovrebbe restituire `10001`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(9), 10001);
|
||||
```
|
||||
|
||||
`zeckendorf(10)` should return `10010`.
|
||||
`zeckendorf(10)` dovrebbe restituire `10010`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(10), 10010);
|
||||
```
|
||||
|
||||
`zeckendorf(11)` should return `10100`.
|
||||
`zeckendorf(11)` dovrebbe restituire `10100`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(11), 10100);
|
||||
```
|
||||
|
||||
`zeckendorf(12)` should return `10101`.
|
||||
`zeckendorf(12)` dovrebbe restituire `10101`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(12), 10101);
|
||||
```
|
||||
|
||||
`zeckendorf(13)` should return `100000`.
|
||||
`zeckendorf(13)` dovrebbe restituire `100000`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(13), 100000);
|
||||
```
|
||||
|
||||
`zeckendorf(14)` should return `100001`.
|
||||
`zeckendorf(14)` dovrebbe restituire `100001`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(14), 100001);
|
||||
```
|
||||
|
||||
`zeckendorf(15)` should return `100010`.
|
||||
`zeckendorf(15)` dovrebbe restituire `100010`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(15), 100010);
|
||||
```
|
||||
|
||||
`zeckendorf(16)` should return `100100`.
|
||||
`zeckendorf(16)` dovrebbe restituire `100100`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(16), 100100);
|
||||
```
|
||||
|
||||
`zeckendorf(17)` should return `100101`.
|
||||
`zeckendorf(17)` dovrebbe restituire `100101`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(17), 100101);
|
||||
```
|
||||
|
||||
`zeckendorf(18)` should return `101000`.
|
||||
`zeckendorf(18)` dovrebbe restituire `101000`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(18), 101000);
|
||||
```
|
||||
|
||||
`zeckendorf(19)` should return `101001`.
|
||||
`zeckendorf(19)` dovrebbe restituire `101001`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(19), 101001);
|
||||
```
|
||||
|
||||
`zeckendorf(20)` should return `101010`.
|
||||
`zeckendorf(20)` dovrebbe restituire `101010`.
|
||||
|
||||
```js
|
||||
assert.equal(zeckendorf(20), 101010);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad7
|
||||
title: Zhang-Suen thinning algorithm
|
||||
title: L'algoritmo di semplificazione di Zhang-Suen
|
||||
challengeType: 5
|
||||
forumTopicId: 302347
|
||||
dashedName: zhang-suen-thinning-algorithm
|
||||
@ -8,7 +8,7 @@ dashedName: zhang-suen-thinning-algorithm
|
||||
|
||||
# --description--
|
||||
|
||||
This is an algorithm used to thin a black and white i.e. one bit per pixel images. For example, with an input image of:
|
||||
Questo è un algoritmo usato per comprimere immagini in bianco e nero, cioè con un bit per ogni pixel. Ad esempio, fornendo la seguente immagine:
|
||||
|
||||
```js
|
||||
const testImage1 = [
|
||||
@ -25,7 +25,7 @@ const testImage1 = [
|
||||
];
|
||||
```
|
||||
|
||||
It produces the thinned output:
|
||||
Produce il seguente output semplificato:
|
||||
|
||||
```js
|
||||
[ ' ',
|
||||
@ -40,76 +40,76 @@ It produces the thinned output:
|
||||
' ' ];
|
||||
```
|
||||
|
||||
## Algorithm
|
||||
## Algoritmo
|
||||
|
||||
Assume black pixels are one and white pixels zero, and that the input image is a rectangular N by M array of ones and zeroes. The algorithm operates on all black pixels P1 that can have eight neighbours. The neighbours are, in order, arranged as:
|
||||
Supponiamo che i pixel neri siano 1 e i pixel bianchi 0, e che l'immagine in ingresso sia una matrice rettangolare N x M di 1 e 0. L'algoritmo opera su tutti i pixel P1 neri che possono avere otto vicini. I vicini sono, in ordine, disposti come:
|
||||
|
||||
$$\begin{array}{|c|c|c|} \\hline P9 & P2 & P3\\\\ \\hline P8 & \boldsymbol{P1} & P4\\\\ \\hline P7 & P6 & P5\\\\ \\hline \end{array}$$
|
||||
|
||||
Obviously the boundary pixels of the image cannot have the full eight neighbours.
|
||||
Ovviamente i pixel ai margini dell'immagine non possono avere gli otto vicini.
|
||||
|
||||
- Define $A(P1)$ = the number of transitions from white to black, ($0 \to 1$) in the sequence P2, P3, P4, P5, P6, P7, P8, P9, P2. (Note the extra P2 at the end - it is circular).
|
||||
- Define $B(P1)$ = the number of black pixel neighbours of P1. ($= \\sum(P2 \ldots P9)$)
|
||||
- Definire $A(P1)$ = il numero di transizioni da bianco a nero, ($0 \to 1$) nella sequenza P2, P3, P4, P5, P6, P7, P8, P9, P2. (Si noti il P2 extra alla fine - è circolare).
|
||||
- Sia $B(P1)$ = il numero di pixel neri vicini a P1. ($= \\sum(P2 \ldots P9)$)
|
||||
|
||||
**Step 1:**
|
||||
|
||||
All pixels are tested and pixels satisfying all the following conditions (simultaneously) are just noted at this stage.
|
||||
Tutti i pixel sono testati e i pixel che soddisfano tutte le condizioni seguenti (contemporaneamente) sono solo annotati in questa fase.
|
||||
|
||||
1. The pixel is black and has eight neighbours
|
||||
1. Il pixel è nero e ha otto vicini
|
||||
2. $2 \le B(P1) \le 6$
|
||||
3. $A(P1) = 1$
|
||||
4. At least one of $P2$, $P4$ and $P6$ is white
|
||||
5. At least one of $P4$, $P6$ and $P8$ is white
|
||||
4. Almeno uno tra $P2$, $P4$ e $P6$ è bianco
|
||||
5. Almeno uno tra $P4$, $P6$ e $P8$ è bianco
|
||||
|
||||
After iterating over the image and collecting all the pixels satisfying all step 1 conditions, all these condition satisfying pixels are set to white.
|
||||
Dopo aver iterato sull'immagine e aver raccolto tutti i pixel che soddisfano tutte le condizioni del passaggio 1, tutti questi pixel sono impostati su bianco.
|
||||
|
||||
**Step 2:**
|
||||
|
||||
All pixels are again tested and pixels satisfying all the following conditions are just noted at this stage.
|
||||
Tutti i pixel sono di nuovo testati e i pixel che soddisfano tutte le condizioni seguenti sono solo annotati in questa fase.
|
||||
|
||||
1. The pixel is black and has eight neighbours
|
||||
1. Il pixel è nero e ha otto vicini
|
||||
2. $2 \le B(P1) \le 6$
|
||||
3. $A(P1) = 1$
|
||||
4. At least one of $P2$, $P4$ and $P8$ is white
|
||||
5. At least one of $P2$, $P6$ and $P8$ is white
|
||||
4. Almeno uno tra $P2$, $P4$ e $P8$ è bianco
|
||||
5. Almeno uno tra $P2$, $P6$ e $P8$ è bianco
|
||||
|
||||
After iterating over the image and collecting all the pixels satisfying all step 2 conditions, all these condition satisfying pixels are again set to white.
|
||||
Dopo aver iterato sull'intera immagine e aver raccolto tutti i pixel che soddisfano tutte le condizioni del passaggio 2, tutti questi pixel sono di nuovo impostati su bianco.
|
||||
|
||||
**Iteration:**
|
||||
**Iterazione:**
|
||||
|
||||
If any pixels were set in this round of either step 1 or step 2 then all steps are repeated until no image pixels are so changed.
|
||||
Se un pixel è stato impostato in questa iterazione al passo 1 o 2, tutti i passi vengono ripetuti fino a quando nessun pixel dell'immagine non viene così modificato.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a routine to perform Zhang-Suen thinning on the provided `image`, an array of strings, where each string represents single line of the image. In the string, `#` represents black pixel, and whitespace represents white pixel. Function should return thinned image, using the same representation.
|
||||
Scrivi una routine per eseguire la compressione di Zhang-Suen sull'immagine `image` fornita, un insieme di stringhe, in cui ogni stringa rappresenta una singola riga dell'immagine. Nella stringa, `#` rappresenta i pixel neri e lo spazio vuoto quelli bianchi. La funzione dovrebbe restituire l'immagine assottigliata, usando la stessa rappresentazione.
|
||||
|
||||
# --hints--
|
||||
|
||||
`thinImage` should be a function.
|
||||
`thinImage` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof thinImage, 'function');
|
||||
```
|
||||
|
||||
`thinImage` should return an array.
|
||||
`thinImage` dovrebbe restituire un array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(thinImage(_testImage1)));
|
||||
```
|
||||
|
||||
`thinImage` should return an array of strings.
|
||||
`thinImage` dovrebbe restituire un array di stringhe.
|
||||
|
||||
```js
|
||||
assert.equal(typeof thinImage(_testImage1)[0], 'string');
|
||||
```
|
||||
|
||||
`thinImage(testImage1)` should return a thinned image as in the example.
|
||||
`thinImage(testImage1)` dovrebbe restituire un'immagine assottigliata come nell'esempio.
|
||||
|
||||
```js
|
||||
assert.deepEqual(thinImage(_testImage1), expected1);
|
||||
```
|
||||
|
||||
`thinImage(testImage2)` should return a thinned image.
|
||||
`thinImage(testImage2)` dovrebbe restituire un'immagine assottigliata.
|
||||
|
||||
```js
|
||||
assert.deepEqual(thinImage(_testImage2), expected2);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad8
|
||||
title: Zig-zag matrix
|
||||
title: Matrice a zig-zag
|
||||
challengeType: 5
|
||||
forumTopicId: 302348
|
||||
dashedName: zig-zag-matrix
|
||||
@ -8,9 +8,9 @@ dashedName: zig-zag-matrix
|
||||
|
||||
# --description--
|
||||
|
||||
A 'zig-zag' array is a square arrangement of the first $N^2$ integers, where the numbers increase sequentially as you zig-zag along the array's [anti-diagonals](https://en.wiktionary.org/wiki/antidiagonal).
|
||||
Un array 'zig-zag' è una disposizione quadrata dei primi $N^2$ interi, dove i numeri aumentano sequenzialmente mentre si zig-zaga lungo le [anti-diagonali](https://en.wiktionary.org/wiki/antidiagonal) dell'array.
|
||||
|
||||
For example, for the input `5`, the following result should be produced:
|
||||
Per esempio, se come input viene fornito `5`, questo dovrebbe essere il risultato prodotto:
|
||||
|
||||
<pre>
|
||||
0 1 5 6 14
|
||||
@ -22,41 +22,41 @@ For example, for the input `5`, the following result should be produced:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes the size of the zig-zag matrix, and returns the corresponding matrix as two-dimensional array.
|
||||
Scrivi una funzione che prendere la dimensione della matrice a zig-zag, e ritorna la matrice corrispondente come un array a 2 dimensioni.
|
||||
|
||||
# --hints--
|
||||
|
||||
ZigZagMatrix should be a function.
|
||||
ZigZagMatrix dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert.equal(typeof ZigZagMatrix, 'function');
|
||||
```
|
||||
|
||||
ZigZagMatrix should return array.
|
||||
ZigZagMatrix deve restituire array.
|
||||
|
||||
```js
|
||||
assert.equal(typeof ZigZagMatrix(1), 'object');
|
||||
```
|
||||
|
||||
ZigZagMatrix should return an array of nested arrays.
|
||||
ZigZagMatrix dovrebbe restituire un array di array annidati.
|
||||
|
||||
```js
|
||||
assert.equal(typeof ZigZagMatrix(1)[0], 'object');
|
||||
```
|
||||
|
||||
ZigZagMatrix(1) should return \[[0]].
|
||||
ZigZagMatrix(1) dovrebbe restituire \[[0]].
|
||||
|
||||
```js
|
||||
assert.deepEqual(ZigZagMatrix(1), zm1);
|
||||
```
|
||||
|
||||
ZigZagMatrix(2) should return \[[0, 1], [2, 3]].
|
||||
ZigZagMatrix(2) dovrebbe restituire \[[0, 1], [2, 3]].
|
||||
|
||||
```js
|
||||
assert.deepEqual(ZigZagMatrix(2), zm2);
|
||||
```
|
||||
|
||||
ZigZagMatrix(5) should return specified matrix.
|
||||
ZigZagMatrix(5) deve restituire la matrice specificata.
|
||||
|
||||
```js
|
||||
assert.deepEqual(ZigZagMatrix(5), zm5);
|
||||
|
Reference in New Issue
Block a user