fix(challenges): Formatted F challenges
This commit is contained in:
@ -6,17 +6,18 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
<p>Write a function to return the factorial of a number.</p>
|
Write a function to return the factorial of a number.
|
||||||
<p>Factorial of a number is given by : </p>
|
Factorial of a number is given by:
|
||||||
n! = n * (n-1) * (n-2) * ..... * 1
|
<pre>
|
||||||
<p>
|
<big>n! = n * (n-1) * (n-2) * ..... * 1</big>
|
||||||
|
</pre>
|
||||||
For example:
|
For example:
|
||||||
3! = 3*2*1 = 6
|
<ul>
|
||||||
4! = 4*3*2*1 = 24
|
<li><big>3! = 3 * 2 * 1 = 6</big></li>
|
||||||
</p>
|
<li><big>4! = 4 * 3 * 2 * 1 = 24</big></li>
|
||||||
<p>Note :
|
</ul>
|
||||||
|
<b>Note:</b>
|
||||||
0! = 1
|
0! = 1
|
||||||
</p>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
|
@ -6,42 +6,39 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
A Mersenne number is a number in the form of 2<sup>P</sup>-1.
|
||||||
<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>
|
If P is prime, the Mersenne number may be a Mersenne prime
|
||||||
<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>
|
(if P is not prime, the Mersenne number is also not prime).
|
||||||
<p>Convert the exponent 23 to binary, you get 10111. Starting with <tt>square</tt> = 1, repeatedly square it.</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" target="_blank">Lucas-Lehmer test</a>.
|
||||||
<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>
|
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>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>
|
Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).
|
||||||
<p>square top bit multiply by 2 mod 47</p>
|
The following is how to implement this modPow yourself:
|
||||||
<p>------------ ------- ------------- ------</p>
|
For example, let's compute 2<sup>23</sup> mod 47.
|
||||||
<p>1*1 = 1 1 0111 1*2 = 2 2</p>
|
Convert the exponent 23 to binary, you get 10111. Starting with <tt>square</tt> = 1, repeatedly square it.
|
||||||
<p>2*2 = 4 0 111 no 4</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>4*4 = 16 1 11 16*2 = 32 32</p>
|
Use the result of the modulo from the last step as the initial value of <tt>square</tt> in the next step:
|
||||||
<p>32*32 = 1024 1 1 1024*2 = 2048 27</p>
|
<pre>
|
||||||
<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>
|
Remove Optional
|
||||||
<p>(To see this, subtract 1 from both sides: 2<sup>23</sup>-1 = 0 mod 47.)</p>
|
square top bit multiply by 2 mod 47
|
||||||
<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>
|
1*1 = 1 1 0111 1*2 = 2 2
|
||||||
<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>
|
2*2 = 4 0 111 no 4
|
||||||
<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>
|
4*4 = 16 1 11 16*2 = 32 32
|
||||||
<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>
|
32*32 = 1024 1 1 1024*2 = 2048 27
|
||||||
Task:
|
27*27 = 729 1 729*2 = 1458 1
|
||||||
<p>Using the above method find a factor of 2<sup>929</sup>-1 (aka M929)</p>
|
</pre>
|
||||||
Related tasks:
|
Since 2<sup>23</sup> mod 47 = 1, 47 is a factor of 2<sup>P</sup>-1.
|
||||||
<a href="http://rosettacode.org/wiki/count in factors" title="count in factors">count in factors</a>
|
(To see this, subtract 1 from both sides: 2<sup>23</sup>-1 = 0 mod 47.)
|
||||||
<a href="http://rosettacode.org/wiki/prime decomposition" title="prime decomposition">prime decomposition</a>
|
Since we've shown that 47 is a factor, 2<sup>23</sup>-1 is not prime.
|
||||||
<a href="http://rosettacode.org/wiki/factors of an integer" title="factors of an integer">factors of an integer</a>
|
Further properties of Mersenne numbers allow us to refine the process even more.
|
||||||
<a href="http://rosettacode.org/wiki/Sieve of Eratosthenes" title="Sieve of Eratosthenes">Sieve of Eratosthenes</a>
|
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.
|
||||||
<a href="http://rosettacode.org/wiki/primality by trial division" title="primality by trial division">primality by trial division</a>
|
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>.
|
||||||
<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>
|
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.
|
||||||
<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>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='instructions'>
|
<section id='instructions'>
|
||||||
|
Using the above method find a factor of 2<sup>929</sup>-1 (aka M929)
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -6,8 +6,8 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
|
@ -6,24 +6,26 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
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.
|
||||||
<p>Each Farey sequence:</p>
|
The <i>Farey sequence</i> is sometimes incorrectly called a <i>Farey series</i>.
|
||||||
<p>::* starts with the value 0, denoted by the fraction $ \frac{0}{1} $</p>
|
Each Farey sequence:
|
||||||
<p>::* ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</p>
|
<ul>
|
||||||
<p>The Farey sequences of orders 1 to 5 are:</p><p>${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</p>
|
<li>starts with the value 0, denoted by the fraction $ \frac{0}{1} $</li>
|
||||||
<p></p>
|
<li>ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</li>
|
||||||
<p>${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$</p>
|
</ul>
|
||||||
<p></p>
|
The Farey sequences of orders <b>1</b> to <b>5</b> are:
|
||||||
<p>${\bf\it{F}}_3 = \frac{0}{1}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{1}{1}$</p>
|
<ul>
|
||||||
<p></p>
|
<li style="list-style: none;">${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</li>
|
||||||
<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>
|
<li style="list-style: none;">${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$</li>
|
||||||
<p></p>
|
<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>
|
||||||
<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>
|
<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>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='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>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -6,40 +6,34 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
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:
|
||||||
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$
|
<ol>
|
||||||
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>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>
|
||||||
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>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>
|
||||||
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>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>
|
||||||
<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>
|
<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>
|
||||||
<p>|+ Fibonacci $n$-step sequences</p>
|
</ol>
|
||||||
<p>|- style="background-color: rgb(255, 204, 255);"</p>
|
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.
|
||||||
<p>! $n$ !! Series name !! Values</p>
|
Fibonacci $n$-step sequences:
|
||||||
<p>|-</p>
|
|
||||||
<p>| 2 || fibonacci || 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...</p>
|
| $n$ | Series name | Values |
|
||||||
<p>|-</p>
|
| --- | --- | --- |
|
||||||
<p>| 3 || tribonacci || 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...</p>
|
| 2 | fibonacci | 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ... |
|
||||||
<p>|-</p>
|
| 3 | tribonacci | 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ... |
|
||||||
<p>| 4 || tetranacci || 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...</p>
|
| 4 | tetranacci | 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ... |
|
||||||
<p>|-</p>
|
| 5 | pentanacci | 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ... |
|
||||||
<p>| 5 || pentanacci || 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...</p>
|
| 6 | hexanacci | 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ... |
|
||||||
<p>|-</p>
|
| 7 | heptanacci | 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ... |
|
||||||
<p>| 6 || hexanacci || 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...</p>
|
| 8 | octonacci | 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ... |
|
||||||
<p>|-</p>
|
| 9 | nonanacci | 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ... |
|
||||||
<p>| 7 || heptanacci || 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...</p>
|
| 10 | decanacci | 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... |
|
||||||
<p>|-</p>
|
Allied sequences can be generated where the initial values are changed:
|
||||||
<p>| 8 || octonacci || 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...</p>
|
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.
|
||||||
<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>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='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>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -6,12 +6,11 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='description'>
|
<section id='description'>
|
||||||
<p>Write a function to generate the <big> n<sup>th</sup> </big> Fibonacci number.</p>
|
Write a function to generate the <big>n<sup>th</sup></big> Fibonacci number.
|
||||||
///<p>The <big> n<sup>th</sup> </big> Fibonacci number is given by :
|
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>
|
F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub>
|
||||||
///<p>The first two terms of the series are 0, 1.</p>
|
The first two terms of the series are 0, 1.
|
||||||
///<p>Hence, the series is : 0, 1, 1, 2, 3, 5, 8, 13...</p>
|
Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
|
||||||
///
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
|
@ -6,15 +6,18 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
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>:
|
||||||
<p>Define F_Word<sub>2</sub> as 0</p>
|
<pre>
|
||||||
<p>Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: 01</p>
|
Define F_Word<sub>1</sub> as <b>1</b>
|
||||||
<p>Form F_Word<sub>n</sub> as F_Word<sub>n-1</sub> concatenated with F_word<sub>n-2</sub></p>
|
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>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='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>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -6,18 +6,25 @@ challengeType: 5
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id='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>
|
<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>.
|
||||||
<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>
|
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$.
|
||||||
<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>
|
The program is run by updating the integer $n$ as follows:
|
||||||
<br>
|
<ul>
|
||||||
<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>
|
<li>for the first fraction, $f_i$, in the list for which $nf_i$ is an integer, replace $n$ with $nf_i$ ;</li>
|
||||||
<br/><dl class="rosetta__description-list"><dt class="rosetta__description-title">Task:</dt></dl>
|
<li>repeat this rule until no fraction in the list produces an integer when multiplied by $n$, then halt.</li>
|
||||||
<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>
|
</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>
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id='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>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
Reference in New Issue
Block a user