fix(challenges): Formatted F challenges
This commit is contained in:
@ -6,17 +6,18 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function to return the factorial of a number.</p>
|
||||
<p>Factorial of a number is given by : </p>
|
||||
n! = n * (n-1) * (n-2) * ..... * 1
|
||||
<p>
|
||||
For example :
|
||||
3! = 3*2*1 = 6
|
||||
4! = 4*3*2*1 = 24
|
||||
</p>
|
||||
<p>Note :
|
||||
Write a function to return the factorial of a number.
|
||||
Factorial of a number is given by:
|
||||
<pre>
|
||||
<big>n! = n * (n-1) * (n-2) * ..... * 1</big>
|
||||
</pre>
|
||||
For example:
|
||||
<ul>
|
||||
<li><big>3! = 3 * 2 * 1 = 6</big></li>
|
||||
<li><big>4! = 4 * 3 * 2 * 1 = 24</big></li>
|
||||
</ul>
|
||||
<b>Note:</b>
|
||||
0! = 1
|
||||
</p>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -50,7 +51,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function factorial (n) {
|
||||
function factorial(n) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,42 +6,39 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>A Mersenne number is a number in the form of 2<sup>P</sup>-1.</p><p>If P is prime, the Mersenne number may be a Mersenne prime</p>
|
||||
<p>(if P is not prime, the Mersenne number is also not prime).</p><p>In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, <a href="http://rosettacode.org/wiki/Lucas-Lehmer test" title="Lucas-Lehmer test">Lucas-Lehmer test</a>.</p><p>There are very efficient algorithms for determining if a number divides 2<sup>P</sup>-1 (or equivalently, if 2<sup>P</sup> mod (the number) = 1).</p>
|
||||
<p>Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).</p><p>The following is how to implement this modPow yourself:</p><p>For example, let's compute 2<sup>23</sup> mod 47.</p>
|
||||
<p>Convert the exponent 23 to binary, you get 10111. Starting with <tt>square</tt> = 1, repeatedly square it.</p>
|
||||
<p>Remove the top bit of the exponent, and if it's 1 multiply <tt>square</tt> by the base of the exponentiation (2), then compute <tt>square</tt> modulo 47.</p>
|
||||
<p>Use the result of the modulo from the last step as the initial value of <tt>square</tt> in the next step:</p><p>Remove Optional</p>
|
||||
<p>square top bit multiply by 2 mod 47</p>
|
||||
<p>------------ ------- ------------- ------</p>
|
||||
<p>1*1 = 1 1 0111 1*2 = 2 2</p>
|
||||
<p>2*2 = 4 0 111 no 4</p>
|
||||
<p>4*4 = 16 1 11 16*2 = 32 32</p>
|
||||
<p>32*32 = 1024 1 1 1024*2 = 2048 27</p>
|
||||
<p>27*27 = 729 1 729*2 = 1458 1</p><p>Since 2<sup>23</sup> mod 47 = 1, 47 is a factor of 2<sup>P</sup>-1.</p>
|
||||
<p>(To see this, subtract 1 from both sides: 2<sup>23</sup>-1 = 0 mod 47.)</p>
|
||||
<p>Since we've shown that 47 is a factor, 2<sup>23</sup>-1 is not prime.</p>
|
||||
<p>Further properties of Mersenne numbers allow us to refine the process even more.</p>
|
||||
<p>Any factor q of 2<sup>P</sup>-1 must be of the form 2kP+1, k being a positive integer or zero. Furthermore, q must be 1 or 7 mod 8.</p>
|
||||
<p>Finally any potential factor q must be <a href="http://rosettacode.org/wiki/Primality by Trial Division" title="Primality by Trial Division">prime</a>.</p>
|
||||
<p>As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N).</p><p>These primality tests only work on Mersenne numbers where P is prime. For example, M<sub>4</sub>=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.</p>
|
||||
Task:
|
||||
<p>Using the above method find a factor of 2<sup>929</sup>-1 (aka M929)</p>
|
||||
Related tasks:
|
||||
<a href="http://rosettacode.org/wiki/count in factors" title="count in factors">count in factors</a>
|
||||
<a href="http://rosettacode.org/wiki/prime decomposition" title="prime decomposition">prime decomposition</a>
|
||||
<a href="http://rosettacode.org/wiki/factors of an integer" title="factors of an integer">factors of an integer</a>
|
||||
<a href="http://rosettacode.org/wiki/Sieve of Eratosthenes" title="Sieve of Eratosthenes">Sieve of Eratosthenes</a>
|
||||
<a href="http://rosettacode.org/wiki/primality by trial division" title="primality by trial division">primality by trial division</a>
|
||||
<a href="http://rosettacode.org/wiki/trial factoring of a Mersenne number" title="trial factoring of a Mersenne number">trial factoring of a Mersenne number</a>
|
||||
<a href="http://rosettacode.org/wiki/partition an integer X into N primes" title="partition an integer X into N primes">partition an integer X into N primes</a>
|
||||
<a href="http://rosettacode.org/wiki/sequence of primes by Trial Division" title="sequence of primes by Trial Division">sequence of primes by Trial Division</a>
|
||||
<a href="https://www.youtube.com/watch?v=SNwvJ7psoow" title="link: https://www.youtube.com/watch?v=SNwvJ7psoow">Computers in 1948: 2¹²⁷-1</a>
|
||||
A Mersenne number is a number in the form of 2<sup>P</sup>-1.
|
||||
If P is prime, the Mersenne number may be a Mersenne prime
|
||||
(if P is not prime, the Mersenne number is also not prime).
|
||||
In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, <a href="http://rosettacode.org/wiki/Lucas-Lehmer test" title="Lucas-Lehmer test" target="_blank">Lucas-Lehmer test</a>.
|
||||
There are very efficient algorithms for determining if a number divides 2<sup>P</sup>-1 (or equivalently, if 2<sup>P</sup> mod (the number) = 1).
|
||||
Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).
|
||||
The following is how to implement this modPow yourself:
|
||||
For example, let's compute 2<sup>23</sup> mod 47.
|
||||
Convert the exponent 23 to binary, you get 10111. Starting with <tt>square</tt> = 1, repeatedly square it.
|
||||
Remove the top bit of the exponent, and if it's 1 multiply <tt>square</tt> by the base of the exponentiation (2), then compute <tt>square</tt> modulo 47.
|
||||
Use the result of the modulo from the last step as the initial value of <tt>square</tt> in the next step:
|
||||
<pre>
|
||||
Remove Optional
|
||||
square top bit multiply by 2 mod 47
|
||||
------------ ------- ------------- ------
|
||||
1*1 = 1 1 0111 1*2 = 2 2
|
||||
2*2 = 4 0 111 no 4
|
||||
4*4 = 16 1 11 16*2 = 32 32
|
||||
32*32 = 1024 1 1 1024*2 = 2048 27
|
||||
27*27 = 729 1 729*2 = 1458 1
|
||||
</pre>
|
||||
Since 2<sup>23</sup> mod 47 = 1, 47 is a factor of 2<sup>P</sup>-1.
|
||||
(To see this, subtract 1 from both sides: 2<sup>23</sup>-1 = 0 mod 47.)
|
||||
Since we've shown that 47 is a factor, 2<sup>23</sup>-1 is not prime.
|
||||
Further properties of Mersenne numbers allow us to refine the process even more.
|
||||
Any factor q of 2<sup>P</sup>-1 must be of the form 2kP+1, k being a positive integer or zero. Furthermore, q must be 1 or 7 mod 8.
|
||||
Finally any potential factor q must be <a href="http://rosettacode.org/wiki/Primality by Trial Division" title="Primality by Trial Division" target="_blank">prime</a>.
|
||||
As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N).These primality tests only work on Mersenne numbers where P is prime. For example, M<sub>4</sub>=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Using the above method find a factor of 2<sup>929</sup>-1 (aka M929)
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -70,7 +67,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function check_mersenne (p) {
|
||||
function check_mersenne(p) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,8 +6,8 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function that returns the factors of a positive integer.</p><p>These factors are the positive integers by which the number being factored can be divided to yield a positive integer result.</p>
|
||||
///
|
||||
Write a function that returns the factors of a positive integer as an array.
|
||||
These factors are the positive integers by which the number being factored can be divided to yield a positive integer result.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -39,7 +39,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function factors (num) {
|
||||
function factors(num) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,24 +6,26 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function that returns the Farey sequence of order n. The function should have one parameter that is n. It should return the sequence as an array. Read the following for more details : </p><p>The <a href="https://en.wikipedia.org/wiki/Farey sequence" title="wp: Farey sequence">Farey sequence</a> F<sub>n</sub> of order n is the sequence of completely reduced fractions between 0 and 1 which, when in lowest terms, have denominators less than or equal to n, arranged in order of increasing size.</p><p>The Farey sequence is sometimes incorrectly called a Farey series.</p>
|
||||
<p>Each Farey sequence:</p>
|
||||
<p>::* starts with the value 0, denoted by the fraction $ \frac{0}{1} $</p>
|
||||
<p>::* ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</p>
|
||||
<p>The Farey sequences of orders 1 to 5 are:</p><p>${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</p>
|
||||
<p></p>
|
||||
<p>${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$</p>
|
||||
<p></p>
|
||||
<p>${\bf\it{F}}_3 = \frac{0}{1}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{1}{1}$</p>
|
||||
<p></p>
|
||||
<p>${\bf\it{F}}_4 = \frac{0}{1}, \frac{1}{4}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{3}{4}, \frac{1}{1}$</p>
|
||||
<p></p>
|
||||
<p>${\bf\it{F}}_5 = \frac{0}{1}, \frac{1}{5}, \frac{1}{4}, \frac{1}{3}, \frac{2}{5}, \frac{1}{2}, \frac{3}{5}, \frac{2}{3}, \frac{3}{4}, \frac{4}{5}, \frac{1}{1}$</p>
|
||||
The <a href="https://en.wikipedia.org/wiki/Farey sequence" title="wp: Farey sequence" target="_blank">Farey sequence</a> <b>F<sub>n</sub></b> of order <b>n</b> is the sequence of completely reduced fractions between <b>0</b> and <b>1</b> which, when in lowest terms, have denominators less than or equal to <b>n</b>, arranged in order of increasing size.
|
||||
The <i>Farey sequence</i> is sometimes incorrectly called a <i>Farey series</i>.
|
||||
Each Farey sequence:
|
||||
<ul>
|
||||
<li>starts with the value 0, denoted by the fraction $ \frac{0}{1} $</li>
|
||||
<li>ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</li>
|
||||
</ul>
|
||||
The Farey sequences of orders <b>1</b> to <b>5</b> are:
|
||||
<ul>
|
||||
<li style="list-style: none;">${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</li>
|
||||
<li style="list-style: none;">${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$</li>
|
||||
<li style="list-style: none;">${\bf\it{F}}_3 = \frac{0}{1}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{1}{1}$</li>
|
||||
<li style="list-style: none;">${\bf\it{F}}_4 = \frac{0}{1}, \frac{1}{4}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{3}{4}, \frac{1}{1}$</li>
|
||||
<li style="list-style: none;">${\bf\it{F}}_5 = \frac{0}{1}, \frac{1}{5}, \frac{1}{4}, \frac{1}{3}, \frac{2}{5}, \frac{1}{2}, \frac{3}{5}, \frac{2}{3}, \frac{3}{4}, \frac{4}{5}, \frac{1}{1}$</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Write a function that returns the Farey sequence of order <b>n</b>. The function should have one parameter that is <b>n</b>. It should return the sequence as an array.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -52,7 +54,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function farey (n) {
|
||||
function farey(n) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,40 +6,34 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function to generate Fibonacci n-step number sequences and Lucas sequences. The first parameter will be n. The second parameter will be the number of elements to be returned. The third parameter will specify whether to output the Fibonacci sequence or the Lucas sequence. If the parameter is "f" then return the Fibonacci sequence and if it is "l", then return the Lucas sequence. The sequences must be returned as an array. More details are given below : </p><p>These number series are an expansion of the ordinary <a href="http://rosettacode.org/wiki/Fibonacci sequence" title="Fibonacci sequence">Fibonacci sequence</a> where:</p>
|
||||
For $n = 2$ we have the Fibonacci sequence; with initial values $[1, 1]$ and $F_k^2 = F_{k-1}^2 + F_{k-2}^2$
|
||||
For $n = 3$ we have the tribonacci sequence; with initial values $[1, 1, 2]$ and $F_k^3 = F_{k-1}^3 + F_{k-2}^3 + F_{k-3}^3$
|
||||
For $n = 4$ we have the tetranacci sequence; with initial values $[1, 1, 2, 4]$ and $F_k^4 = F_{k-1}^4 + F_{k-2}^4 + F_{k-3}^4 + F_{k-4}^4$...
|
||||
For general $n>2$ we have the Fibonacci $n$-step sequence - $F_k^n$; with initial values of the first $n$ values of the $(n-1)$'th Fibonacci $n$-step sequence $F_k^{n-1}$; and $k$'th value of this $n$'th sequence being $F_k^n = \sum_{i=1}^{(n)} {F_{k-i}^{(n)}}$
|
||||
<p>For small values of $n$, <a href="https://en.wikipedia.org/wiki/Number prefix#Greek_series" title="wp: Number prefix#Greek_series">Greek numeric prefixes</a> are sometimes used to individually name each series.</p><p>{| style="text-align: left;" border="4" cellpadding="2" cellspacing="2"</p>
|
||||
<p>|+ Fibonacci $n$-step sequences</p>
|
||||
<p>|- style="background-color: rgb(255, 204, 255);"</p>
|
||||
<p>! $n$ !! Series name !! Values</p>
|
||||
<p>|-</p>
|
||||
<p>| 2 || fibonacci || 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 3 || tribonacci || 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 4 || tetranacci || 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 5 || pentanacci || 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 6 || hexanacci || 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 7 || heptanacci || 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 8 || octonacci || 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 9 || nonanacci || 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...</p>
|
||||
<p>|-</p>
|
||||
<p>| 10 || decanacci || 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ...</p>
|
||||
<p>|}</p><p>Allied sequences can be generated where the initial values are changed:</p>
|
||||
<p> The <a href="https://en.wikipedia.org/wiki/Lucas number" title="wp: Lucas number">Lucas series</a> sums the two preceding values like the fibonacci series for $n=2$ but uses $[2, 1]$ as its initial values.</p><p><!-- Lucas numbers, Lucas number, Lucas series [added to make searches easier.] --></p>
|
||||
These number series are an expansion of the ordinary <a href="http://rosettacode.org/wiki/Fibonacci sequence" title="Fibonacci sequence" target="_blank">Fibonacci sequence</a> where:
|
||||
<ol>
|
||||
<li>For $n = 2$ we have the Fibonacci sequence; with initial values $[1, 1]$ and $F_k^2 = F_{k-1}^2 + F_{k-2}^2$</li>
|
||||
<li>For $n = 3$ we have the tribonacci sequence; with initial values $[1, 1, 2]$ and $F_k^3 = F_{k-1}^3 + F_{k-2}^3 + F_{k-3}^3$</li>
|
||||
<li>For $n = 4$ we have the tetranacci sequence; with initial values $[1, 1, 2, 4]$ and $F_k^4 = F_{k-1}^4 + F_{k-2}^4 + F_{k-3}^4 + F_{k-4}^4$...</li>
|
||||
<li>For general $n>2$ we have the Fibonacci $n$-step sequence - $F_k^n$; with initial values of the first $n$ values of the $(n-1)$'th Fibonacci $n$-step sequence $F_k^{n-1}$; and $k$'th value of this $n$'th sequence being $F_k^n = \sum_{i=1}^{(n)} {F_{k-i}^{(n)}}$</li>
|
||||
</ol>
|
||||
For small values of $n$, <a href="https://en.wikipedia.org/wiki/Number prefix#Greek_series" title="wp: Number prefix#Greek_series" target="_blank">Greek numeric prefixes</a> are sometimes used to individually name each series.
|
||||
Fibonacci $n$-step sequences:
|
||||
|
||||
| $n$ | Series name | Values |
|
||||
| --- | --- | --- |
|
||||
| 2 | fibonacci | 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ... |
|
||||
| 3 | tribonacci | 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ... |
|
||||
| 4 | tetranacci | 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ... |
|
||||
| 5 | pentanacci | 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ... |
|
||||
| 6 | hexanacci | 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ... |
|
||||
| 7 | heptanacci | 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ... |
|
||||
| 8 | octonacci | 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ... |
|
||||
| 9 | nonanacci | 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ... |
|
||||
| 10 | decanacci | 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... |
|
||||
Allied sequences can be generated where the initial values are changed:
|
||||
The <a href="https://en.wikipedia.org/wiki/Lucas number" title="wp: Lucas number" target="_blank">Lucas series</a> sums the two preceding values like the fibonacci series for $n=2$ but uses $[2, 1]$ as its initial values.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Write a function to generate Fibonacci n-step number sequences and Lucas sequences. The first parameter will be n. The second parameter will be the number of elements to be returned. The third parameter will specify whether to output the Fibonacci sequence or the Lucas sequence. If the parameter is "f" then return the Fibonacci sequence and if it is "l", then return the Lucas sequence. The sequences must be returned as an array.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -74,7 +68,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fib_luc (n, len, w) {
|
||||
function fib_luc(n, len, w) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,12 +6,11 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function to generate the <big> n<sup>th</sup> </big> Fibonacci number.</p>
|
||||
///<p>The <big> n<sup>th</sup> </big> Fibonacci number is given by :
|
||||
///<p>F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub></p>
|
||||
///<p>The first two terms of the series are 0, 1.</p>
|
||||
///<p>Hence, the series is : 0, 1, 1, 2, 3, 5, 8, 13...</p>
|
||||
///
|
||||
Write a function to generate the <big>n<sup>th</sup></big> Fibonacci number.
|
||||
The <big>n<sup>th</sup></big> Fibonacci number is given by:
|
||||
F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub>
|
||||
The first two terms of the series are 0, 1.
|
||||
Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
|
@ -6,15 +6,18 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>Write a function to return the Fibonacci Words upto N. N will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form : { N: 1, Length: 1, Entropy: 0, Word: '1' }. More details are given below : </p><p>The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence <a href="http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf" title="link: http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf">as described here</a>:</p><p>Define F_Word<sub>1</sub> as 1</p>
|
||||
<p>Define F_Word<sub>2</sub> as 0</p>
|
||||
<p>Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: 01</p>
|
||||
<p>Form F_Word<sub>n</sub> as F_Word<sub>n-1</sub> concatenated with F_word<sub>n-2</sub></p>
|
||||
The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence <a href="http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf" title="link: http://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf" target="_blank">as described here</a>:
|
||||
<pre>
|
||||
Define F_Word<sub>1</sub> as <b>1</b>
|
||||
Define F_Word<sub>2</sub> as <b>0</b>
|
||||
Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: <b>01</b>
|
||||
Form F_Word<sub>n</sub> as F_Word<sub>n-1</sub> concatenated with F_word<sub>n-2</sub>
|
||||
</pre>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Write a function to return the Fibonacci Words upto <b>N</b>. <b>N</b> will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form: <code>{ N: 1, Length: 1, Entropy: 0, Word: '1' }</code>.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -39,7 +42,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fibWord (n) {
|
||||
function fibWord(n) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
@ -6,18 +6,25 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<div class="rosetta"><p class="rosetta__paragraph"><span class="rosetta__text--bold"><a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/FRACTRAN" title="wp: FRACTRAN">FRACTRAN</a></span> is a Turing-complete esoteric programming language invented by the mathematician <a class="rosetta__link--wiki" href="https://en.wikipedia.org/wiki/John Horton Conway" title="wp: John Horton Conway">John Horton Conway</a>.</p><br/><p class="rosetta__paragraph">A FRACTRAN program is an ordered list of positive fractions $P = (f_1, f_2, \ldots, f_m)$, together with an initial positive integer input $n$.</p>
|
||||
<br/><p class="rosetta__paragraph">The program is run by updating the integer $n$ as follows:</p><br/><ul class="rosetta__unordered-list"><li class="rosetta__list-item--unordered">for the first fraction, $f_i$, in the list for which $nf_i$ is an integer, replace $n$ with $nf_i$ ;</li>
|
||||
<li class="rosetta__list-item--unordered">repeat this rule until no fraction in the list produces an integer when multiplied by $n$, then halt.</li></ul>
|
||||
<br>
|
||||
<p class="rosetta__paragraph">Conway gave a program for primes in FRACTRAN:</p><br/><p class="rosetta__paragraph"><span class="rosetta__text--indented"> $17/91$, $78/85$, $19/51$, $23/38$, $29/33$, $77/29$, $95/23$, $77/19$, $1/17$, $11/13$, $13/11$, $15/14$, $15/2$, $55/1$</span></p><br/><p class="rosetta__paragraph">Starting with $n=2$, this FRACTRAN program will change $n$ to $15=2\times (15/2)$, then $825=15\times (55/1)$, generating the following sequence of integers:</p><br/><p class="rosetta__paragraph"><span class="rosetta__text--indented"> $2$, $15$, $825$, $725$, $1925$, $2275$, $425$, $390$, $330$, $290$, $770$, $\ldots$</span></p><br/><p class="rosetta__paragraph">After 2, this sequence contains the following powers of 2:</p><br/><p class="rosetta__paragraph"><span class="rosetta__text--indented">$2^2=4$, $2^3=8$, $2^5=32$, $2^7=128$, $2^{11}=2048$, $2^{13}=8192$, $2^{17}=131072$, $2^{19}=524288$, $\ldots$</span></p><br/><p class="rosetta__paragraph">which are the prime powers of 2.</p>
|
||||
<br/><dl class="rosetta__description-list"><dt class="rosetta__description-title">Task:</dt></dl>
|
||||
<p class="rosetta__paragraph">Write a function that takes a fractran program as a string parameter and returns the first 10 numbers of the program as an array. If the result does not have 10 numbers then return the numbers as is.</p></div>
|
||||
<a href="https://en.wikipedia.org/wiki/FRACTRAN" title="wp: FRACTRAN" target="_blank">FRACTRAN</a> is a Turing-complete esoteric programming language invented by the mathematician <a href="https://en.wikipedia.org/wiki/John Horton Conway" title="wp: John Horton Conway" target="_blank">John Horton Conway</a>.
|
||||
A FRACTRAN program is an ordered list of positive fractions $P = (f_1, f_2, \ldots, f_m)$, together with an initial positive integer input $n$.
|
||||
The program is run by updating the integer $n$ as follows:
|
||||
<ul>
|
||||
<li>for the first fraction, $f_i$, in the list for which $nf_i$ is an integer, replace $n$ with $nf_i$ ;</li>
|
||||
<li>repeat this rule until no fraction in the list produces an integer when multiplied by $n$, then halt.</li>
|
||||
</ul>
|
||||
Conway gave a program for primes in FRACTRAN:
|
||||
<span style="margin-left: 2em;">$17/91$, $78/85$, $19/51$, $23/38$, $29/33$, $77/29$, $95/23$, $77/19$, $1/17$, $11/13$, $13/11$, $15/14$, $15/2$, $55/1$</span>
|
||||
Starting with $n=2$, this FRACTRAN program will change $n$ to $15=2\times (15/2)$, then $825=15\times (55/1)$, generating the following sequence of integers:
|
||||
<span style="margin-left: 2em;">$2$, $15$, $825$, $725$, $1925$, $2275$, $425$, $390$, $330$, $290$, $770$, $\ldots$</span>
|
||||
After 2, this sequence contains the following powers of 2:
|
||||
<span style="margin-left: 2em;">$2^2=4$, $2^3=8$, $2^5=32$, $2^7=128$, $2^{11}=2048$, $2^{13}=8192$, $2^{17}=131072$, $2^{19}=524288$, $\ldots$</span>
|
||||
which are the prime powers of 2.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Write a function that takes a fractran program as a string parameter and returns the first 10 numbers of the program as an array. If the result does not have 10 numbers then return the numbers as is.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -50,7 +57,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function fractran (progStr) {
|
||||
function fractran(progStr) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user