From abbfee11893db4f06b5afc3534a628070a025998 Mon Sep 17 00:00:00 2001 From: Kris Koishigawa Date: Sat, 2 Mar 2019 21:27:55 +0900 Subject: [PATCH] fix(challenges): Formatted F challenges --- .../rosetta-code/factorial.english.md | 23 +++---- .../factors-of-a-mersenne-number.english.md | 63 +++++++++---------- .../factors-of-an-integer.english.md | 6 +- .../rosetta-code/farey-sequence.english.md | 32 +++++----- ...bonacci-n-step-number-sequences.english.md | 56 ++++++++--------- .../fibonacci-sequence.english.md | 11 ++-- .../rosetta-code/fibonacci-word.english.md | 15 +++-- .../rosetta-code/fractran.english.md | 25 +++++--- 8 files changed, 117 insertions(+), 114 deletions(-) diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factorial.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factorial.english.md index 8fb3fa86c9..5663224189 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factorial.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factorial.english.md @@ -6,17 +6,18 @@ challengeType: 5 ## Description
-

Write a function to return the factorial of a number.

-

Factorial of a number is given by :

-n! = n * (n-1) * (n-2) * ..... * 1 -

-For example : -3! = 3*2*1 = 6 -4! = 4*3*2*1 = 24 -

-

Note : +Write a function to return the factorial of a number. +Factorial of a number is given by: +

+n! = n * (n-1) * (n-2) * ..... * 1
+
+For example: + +Note: 0! = 1 -

## Instructions @@ -50,7 +51,7 @@ tests:
```js -function factorial (n) { +function factorial(n) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md index db4f490a76..d3383ecc08 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md @@ -6,42 +6,39 @@ challengeType: 5 ## Description
-

A Mersenne number is a number in the form of 2P-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, Lucas-Lehmer test.

There are very efficient algorithms for determining if a number divides 2P-1 (or equivalently, if 2P 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 223 mod 47.

-

Convert the exponent 23 to binary, you get 10111. Starting with square = 1, repeatedly square it.

-

Remove the top bit of the exponent, and if it's 1 multiply square by the base of the exponentiation (2), then compute square modulo 47.

-

Use the result of the modulo from the last step as the initial value of square in the next step:

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

Since 223 mod 47 = 1, 47 is a factor of 2P-1.

-

(To see this, subtract 1 from both sides: 223-1 = 0 mod 47.)

-

Since we've shown that 47 is a factor, 223-1 is not prime.

-

Further properties of Mersenne numbers allow us to refine the process even more.

-

Any factor q of 2P-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 prime.

-

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, M4=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.

-Task: -

Using the above method find a factor of 2929-1 (aka M929)

-Related tasks: - count in factors - prime decomposition - factors of an integer - Sieve of Eratosthenes - primality by trial division - trial factoring of a Mersenne number - partition an integer X into N primes - sequence of primes by Trial Division - Computers in 1948: 2¹²⁷-1 +A Mersenne number is a number in the form of 2P-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, Lucas-Lehmer test. +There are very efficient algorithms for determining if a number divides 2P-1 (or equivalently, if 2P 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 223 mod 47. +Convert the exponent 23 to binary, you get 10111. Starting with square = 1, repeatedly square it. +Remove the top bit of the exponent, and if it's 1 multiply square by the base of the exponentiation (2), then compute square modulo 47. +Use the result of the modulo from the last step as the initial value of square in the next step: +
+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
+
+Since 223 mod 47 = 1, 47 is a factor of 2P-1. +(To see this, subtract 1 from both sides: 223-1 = 0 mod 47.) +Since we've shown that 47 is a factor, 223-1 is not prime. +Further properties of Mersenne numbers allow us to refine the process even more. +Any factor q of 2P-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 prime. +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, M4=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.
## Instructions
- +Using the above method find a factor of 2929-1 (aka M929)
## Tests @@ -70,7 +67,7 @@ tests:
```js -function check_mersenne (p) { +function check_mersenne(p) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-an-integer.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-an-integer.english.md index 6c38f965ba..b45e8cdfc3 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-an-integer.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-an-integer.english.md @@ -6,8 +6,8 @@ challengeType: 5 ## Description
-

Write a function that returns the factors of a positive integer.

These factors are the positive integers by which the number being factored can be divided to yield a positive integer result.

-/// +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.
## Instructions @@ -39,7 +39,7 @@ tests:
```js -function factors (num) { +function factors(num) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/farey-sequence.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/farey-sequence.english.md index a0b3d0593e..08d6cbf7c6 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/farey-sequence.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/farey-sequence.english.md @@ -6,24 +6,26 @@ challengeType: 5 ## Description
-

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 :

The Farey sequence Fn 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.

The Farey sequence is sometimes incorrectly called a Farey series.

-

Each Farey sequence:

-

::* starts with the value 0, denoted by the fraction $ \frac{0}{1} $

-

::* ends with the value 1, denoted by the fraction $ \frac{1}{1}$.

-

The Farey sequences of orders 1 to 5 are:

${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$

-

-

${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$

-

-

${\bf\it{F}}_3 = \frac{0}{1}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{1}{1}$

-

-

${\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}$

-

-

${\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}$

+The Farey sequence Fn 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. +The Farey sequence is sometimes incorrectly called a Farey series. +Each Farey sequence: +
    +
  • starts with the value 0, denoted by the fraction $ \frac{0}{1} $
  • +
  • ends with the value 1, denoted by the fraction $ \frac{1}{1}$.
  • +
+The Farey sequences of orders 1 to 5 are: +
    +
  • ${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$
  • +
  • ${\bf\it{F}}_2 = \frac{0}{1}, \frac{1}{2}, \frac{1}{1}$
  • +
  • ${\bf\it{F}}_3 = \frac{0}{1}, \frac{1}{3}, \frac{1}{2}, \frac{2}{3}, \frac{1}{1}$
  • +
  • ${\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}$
  • +
  • ${\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}$
  • +
## Instructions
- +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.
## Tests @@ -52,7 +54,7 @@ tests:
```js -function farey (n) { +function farey(n) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-n-step-number-sequences.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-n-step-number-sequences.english.md index af72512351..28b57128d0 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-n-step-number-sequences.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-n-step-number-sequences.english.md @@ -6,40 +6,34 @@ challengeType: 5 ## Description
-

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 :

These number series are an expansion of the ordinary Fibonacci sequence 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$ -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)}}$ -

For small values of $n$, Greek numeric prefixes are sometimes used to individually name each series.

{| style="text-align: left;" border="4" cellpadding="2" cellspacing="2"

-

|+ Fibonacci $n$-step sequences

-

|- style="background-color: rgb(255, 204, 255);"

-

! $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 Lucas series sums the two preceding values like the fibonacci series for $n=2$ but uses $[2, 1]$ as its initial values.

+These number series are an expansion of the ordinary Fibonacci sequence where: +
    +
  1. 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$
  2. +
  3. 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$
  4. +
  5. 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$...
  6. +
  7. 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)}}$
  8. +
+For small values of $n$, Greek numeric prefixes 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 Lucas series sums the two preceding values like the fibonacci series for $n=2$ but uses $[2, 1]$ as its initial values.
## 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.
## Tests @@ -74,7 +68,7 @@ tests:
```js -function fib_luc (n, len, w) { +function fib_luc(n, len, w) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-sequence.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-sequence.english.md index 2651dc2f95..847a3d2879 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-sequence.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-sequence.english.md @@ -6,12 +6,11 @@ challengeType: 5 ## Description
-

Write a function to generate the nth Fibonacci number.

-///

The nth Fibonacci number is given by : -///

Fn = Fn-1 + Fn-2

-///

The first two terms of the series are 0, 1.

-///

Hence, the series is : 0, 1, 1, 2, 3, 5, 8, 13...

-/// +Write a function to generate the nth Fibonacci number. +The nth Fibonacci number is given by: +Fn = Fn-1 + Fn-2 +The first two terms of the series are 0, 1. +Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
## Instructions diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-word.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-word.english.md index 77138a4aca..32d6c83131 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-word.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fibonacci-word.english.md @@ -6,15 +6,18 @@ challengeType: 5 ## Description
-

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 :

The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence as described here:

Define F_Word1 as 1

-

Define F_Word2 as 0

-

Form F_Word3 as F_Word2 concatenated with F_Word1 i.e.: 01

-

Form F_Wordn as F_Wordn-1 concatenated with F_wordn-2

+The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence as described here: +
+Define  F_Word1  as  1
+Define  F_Word2  as  0
+Form   F_Word3  as  F_Word2   concatenated with  F_Word1   i.e.:  01
+Form   F_Wordn  as  F_Wordn-1  concatenated with  F_wordn-2
+
## Instructions
- +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' }.
## Tests @@ -39,7 +42,7 @@ tests:
```js -function fibWord (n) { +function fibWord(n) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fractran.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fractran.english.md index 5919f89411..3a520193c8 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fractran.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fractran.english.md @@ -6,18 +6,25 @@ challengeType: 5 ## Description
-

FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway.


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:


  • for the first fraction, $f_i$, in the list for which $nf_i$ is an integer, replace $n$ with $nf_i$ ;
  • -
  • repeat this rule until no fraction in the list produces an integer when multiplied by $n$, then halt.
-
-

Conway gave a program for primes in FRACTRAN:


$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$


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:


$2$, $15$, $825$, $725$, $1925$, $2275$, $425$, $390$, $330$, $290$, $770$, $\ldots$


After 2, this sequence contains the following powers of 2:


$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$


which are the prime powers of 2.

-
Task:
-

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.

+FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Horton Conway. +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: +
    +
  • for the first fraction, $f_i$, in the list for which $nf_i$ is an integer, replace $n$ with $nf_i$ ;
  • +
  • repeat this rule until no fraction in the list produces an integer when multiplied by $n$, then halt.
  • +
+Conway gave a program for primes in FRACTRAN: +$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$ +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: +$2$, $15$, $825$, $725$, $1925$, $2275$, $425$, $390$, $330$, $290$, $770$, $\ldots$ +After 2, this sequence contains the following powers of 2: +$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$ +which are the prime powers of 2.
## 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.
## Tests @@ -50,7 +57,7 @@ tests:
```js -function fractran (progStr) { +function fractran(progStr) { // Good luck! } ```