diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/department-numbers.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/department-numbers.english.md index 81f8f446c0..ef2537f814 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/department-numbers.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/department-numbers.english.md @@ -60,7 +60,7 @@ tests:
```js -function combinations (possibleNumbers, total) { +function combinations(possibleNumbers, total) { // Good luck! return true; } @@ -103,7 +103,7 @@ const result = [ ```js -function combinations (possibleNumbers, total) { +function combinations(possibleNumbers, total) { let firstNumber; let secondNumber; let thridNumber; diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/discordian-date.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/discordian-date.english.md index fef523781a..b39fae4790 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/discordian-date.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/discordian-date.english.md @@ -46,7 +46,7 @@ tests:
```js -function discordianDate (date) { +function discordianDate(date) { // Good luck! return true; } diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/dot-product.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/dot-product.md index 73a1e3a94b..a971c31111 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/dot-product.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/dot-product.md @@ -42,7 +42,7 @@ tests:
```js -function dotProduct (ary1, ary2) { +function dotProduct(ary1, ary2) { // Good luck! } ``` @@ -54,7 +54,7 @@ function dotProduct (ary1, ary2) {
```js -function dotProduct (ary1, ary2) { +function dotProduct(ary1, ary2) { var dotprod = 0; for (var i = 0; i < ary1.length; i++) dotprod += ary1[i] * ary2[i]; diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md index 6ef38ae64d..65de08bbd8 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md @@ -6,13 +6,16 @@ challengeType: 5 ## Description
-

Implement basic element-wise matrix-matrix and scalar-matrix operations.

Implement:

-

::* addition

-

::* subtraction

-

::* multiplication

-

::* division

-

::* exponentiation

-

The first parameter will be the operation to be performed, for example : "m_add" for matrix addition and "s_add" for scalar addition. The second and third parameters will be the matrices on which the operations are to be performed. +Implement basic element-wise matrix-matrix and scalar-matrix operations. +Implement: +

    +
  • addition
  • +
  • subtraction
  • +
  • multiplication
  • +
  • division
  • +
  • exponentiation
  • +
+The first parameter will be the operation to be performed, for example, "m_add" for matrix addition and "s_add" for scalar addition. The second and third parameters will be the matrices on which the operations are to be performed.
## Instructions @@ -52,7 +55,7 @@ tests:
```js -function operation (op, arr1, arr2) { +function operation(op, arr1, arr2) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md index 491d01cbf5..e792797255 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md @@ -6,13 +6,19 @@ challengeType: 5 ## Description
-

An emirp (prime spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.

-

Write a function that should be able to : Show the first n eprimes numbers.Show the eprimes numbers in a range.Show the number of eprimes in a range.Show the nth eprimes number.

The function should have two parameters. The first will receive n or the range as an array. The second will receive a boolean, that specifies if the function returns the eprimes as an array or a single number(the number of primes in the range or the nth prime). According to the parameters the function should return an array or a number. +An emirp (prime spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.

## Instructions
- +Write a function that: +
    +
  • Shows the first n emirp numbers.
  • +
  • Shows the emirp numbers in a range.
  • +
  • Shows the number of emirps in a range.
  • +
  • Shows the nth emirp number.
  • +
+The function should accept two parameters. The first will receive n or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the nth prime). According to the parameters the function should return an array or a number.
## Tests diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/entropy.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/entropy.english.md index ed3b054fa7..f8926c3741 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/entropy.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/entropy.english.md @@ -6,9 +6,10 @@ challengeType: 5 ## Description
-Task: -

Calculate the Shannon entropy H of a given input string.

Given the discreet random variable $X$ that is a string of $N$ "symbols" (total characters) consisting of $n$ different characters (n=2 for binary), the Shannon entropy of X in bits/symbol is :

-

$H_2(X) = -\sum_{i=1}^n \frac{count_i}{N} \log_2 \left(\frac{count_i}{N}\right)$

where $count_i$ is the count of character $n_i$.

+Calculate the Shannon entropy H of a given input string. +Given the discreet random variable $X$ that is a string of $N$ "symbols" (total characters) consisting of $n$ different characters (n=2 for binary), the Shannon entropy of X in bits/symbol is: +$H_2(X) = -\sum_{i=1}^n \frac{count_i}{N} \log_2 \left(\frac{count_i}{N}\right)$ +where $count_i$ is the count of character $n_i$.
## Instructions @@ -46,7 +47,7 @@ tests:
```js -function entropy (s) { +function entropy(s) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md index 48a677860f..c27caf1d1b 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md @@ -6,20 +6,33 @@ challengeType: 5 ## Description
-

An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices.

-

For example, in a sequence $A$:

:::: $A_0 = -7$

-

:::: $A_1 = 1$

-

:::: $A_2 = 5$

-

:::: $A_3 = 2$

-

:::: $A_4 = -4$

-

:::: $A_5 = 3$

-

:::: $A_6 = 0$

3 is an equilibrium index, because:

:::: $A_0 + A_1 + A_2 = A_4 + A_5 + A_6$

6 is also an equilibrium index, because:

:::: $A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0$

(sum of zero elements is zero)

7 is not an equilibrium index, because it is not a valid index of sequence $A$.

-

Write a function that, given a sequence, returns its equilibrium indices (if any).

Assume that the sequence may be very long.

+An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. +For example, in a sequence $A$: +
    +
  • $A_0 = -7$
  • +
  • $A_1 = 1$
  • +
  • $A_2 = 5$
  • +
  • $A_3 = 2$
  • +
  • $A_4 = -4$
  • +
  • $A_5 = 3$
  • +
  • $A_6 = 0$
  • +
+3 is an equilibrium index, because: +
    +
  • $A_0 + A_1 + A_2 = A_4 + A_5 + A_6$
  • +
+6 is also an equilibrium index, because: +
    +
  • $A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0$
  • +
+(sum of zero elements is zero) +7 is not an equilibrium index, because it is not a valid index of sequence $A$.
## Instructions
- +Write a function that, given a sequence, returns its equilibrium indices (if any). +Assume that the sequence may be very long.
## Tests @@ -52,7 +65,7 @@ tests:
```js -function equilibrium (a) { +function equilibrium(a) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md index a84aac3a80..2341674379 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md @@ -6,53 +6,65 @@ challengeType: 5 ## Description
-

Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.

-

Method:

-Take two numbers to be multiplied and write them down at the top of two columns. -In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of 1. -In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows 1. -Examine the table produced and discard any row where the value in the left column is even. -Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together -

For example: 17 × 34

-

17 34

-

Halving the first column:

-

17 34

-

8

-

4

-

2

-

1

-

Doubling the second column:

-

17 34

-

8 68

-

4 136

-

2 272

-

1 544

-

Strike-out rows whose first cell is even:

-

17 34

-

8 68

-

4 136

-

2 272

-

1 544

-

Sum the remaining numbers in the right-hand column:

-

17 34

-

8 --

-

4 ---

-

2 ---

-

1 544

-

====

-

578

-

So 17 multiplied by 34, by the Ethiopian method is 578.

-Task: -

The task is to define three named functions/methods/procedures/subroutines:

-one to halve an integer, -one to double an integer, and -one to state if an integer is even. -

Use these functions to create a function that does Ethiopian multiplication.

+Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. +Method: +
    +
  1. Take two numbers to be multiplied and write them down at the top of two columns.
  2. +
  3. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of 1.
  4. +
  5. In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows 1.
  6. +
  7. Examine the table produced and discard any row where the value in the left column is even.
  8. +
  9. Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together
  10. +
+For example: 17 × 34 +
+17   34
+
+Halving the first column: +
+17   34
+8
+4
+2
+1
+
+Doubling the second column: +
+17   34
+8    68
+4   136
+2   272
+1   544
+
+Strike-out rows whose first cell is even: +
+17   34
+8    68
+4   136
+2   272
+1   544
+
+Sum the remaining numbers in the right-hand column: +
+17   34
+8    --
+4   ---
+2   ---
+1   544
+   ====
+    578
+
+So 17 multiplied by 34, by the Ethiopian method is 578.
## Instructions
- +The task is to define three named functions/methods/procedures/subroutines: +
    +
  1. one to halve an integer,
  2. +
  3. one to double an integer, and
  4. +
  5. one to state if an integer is even.
  6. +
+Use these functions to create a function that does Ethiopian multiplication.
## Tests @@ -83,7 +95,7 @@ tests:
```js -function eth_mult (a, b) { +function eth_mult(a, b) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/euler-method.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/euler-method.english.md index cc08c7ff1c..ffab4e0572 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/euler-method.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/euler-method.english.md @@ -6,28 +6,64 @@ challengeType: 5 ## Description
-

Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page.

The ODE has to be provided in the following form:

:: $\frac{dy(t)}{dt} = f(t,y(t))$

with an initial value

:: $y(t_0) = y_0$

To get a numeric solution, we replace the derivative on the LHS with a finite difference approximation:

:: $\frac{dy(t)}{dt} \approx \frac{y(t+h)-y(t)}{h}$

then solve for $y(t+h)$:

:: $y(t+h) \approx y(t) + h \, \frac{dy(t)}{dt}$

which is the same as

:: $y(t+h) \approx y(t) + h \, f(t,y(t))$

The iterative solution rule is then:

:: $y_{n+1} = y_n + h \, f(t_n, y_n)$

where $h$ is the step size, the most relevant parameter for accuracy of the solution. A smaller step size increases accuracy but also the computation cost, so it has always has to be hand-picked according to the problem at hand.

-

Example: Newton's Cooling Law

Newton's cooling law describes how an object of initial temperature $T(t_0) = T_0$ cools down in an environment of temperature $T_R$:

:: $\frac{dT(t)}{dt} = -k \, \Delta T$

-

or

-

:: $\frac{dT(t)}{dt} = -k \, (T(t) - T_R)$

-

It says that the cooling rate $\frac{dT(t)}{dt}$ of the object is proportional to the current temperature difference $\Delta T = (T(t) - T_R)$ to the surrounding environment.

The analytical solution, which we will compare to the numerical approximation, is

-

:: $T(t) = T_R + (T_0 - T_R) \; e^{-k t}$

-Task: -

Implement a routine of Euler's method and then to use it to solve the given example of Newton's cooling law with it for three different step sizes of:

-

::* 2 s

-

::* 5 s and

-

::* 10 s

-

and to compare with the analytical solution.

-Initial values: -

::* initial temperature $T_0$ shall be 100 °C

-

::* room temperature $T_R$ shall be 20 °C

-

::* cooling constant $k$ shall be 0.07

-

::* time interval to calculate shall be from 0 s ──► 100 s

+Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. +The ODE has to be provided in the following form: +
    +
  • $\frac{dy(t)}{dt} = f(t,y(t))$
  • +
+with an initial value +
    +
  • $y(t_0) = y_0$
  • +
+To get a numeric solution, we replace the derivative on the LHS with a finite difference approximation: +
    +
  • $\frac{dy(t)}{dt} \approx \frac{y(t+h)-y(t)}{h}$
  • +
+then solve for $y(t+h)$: +
    +
  • $y(t+h) \approx y(t) + h \, \frac{dy(t)}{dt}$
  • +
+which is the same as +
    +
  • $y(t+h) \approx y(t) + h \, f(t,y(t))$
  • +
+The iterative solution rule is then: +
    +
  • $y_{n+1} = y_n + h \, f(t_n, y_n)$
  • +
+where $h$ is the step size, the most relevant parameter for accuracy of the solution. A smaller step size increases accuracy but also the computation cost, so it has always has to be hand-picked according to the problem at hand. +Example: Newton's Cooling Law +Newton's cooling law describes how an object of initial temperature $T(t_0) = T_0$ cools down in an environment of temperature $T_R$: +
    +
  • $\frac{dT(t)}{dt} = -k \, \Delta T$
  • +
+or +
    +
  • $\frac{dT(t)}{dt} = -k \, (T(t) - T_R)$
  • +
+It says that the cooling rate $\frac{dT(t)}{dt}$ of the object is proportional to the current temperature difference $\Delta T = (T(t) - T_R)$ to the surrounding environment. +The analytical solution, which we will compare to the numerical approximation, is +
    +
  • $T(t) = T_R + (T_0 - T_R) \; e^{-k t}$
  • +
## Instructions
- +Implement a routine of Euler's method and then to use it to solve the given example of Newton's cooling law with it for three different step sizes of: +
    +
  • 2 s
  • +
  • 5 s and
  • +
  • 10 s
  • +
+and to compare with the analytical solution. +Initial values: +
    +
  • initial temperature $T_0$ shall be 100 °C
  • +
  • room temperature $T_R$ shall be 20 °C
  • +
  • cooling constant $k$ shall be 0.07
  • +
  • time interval to calculate shall be from 0s to 100 s
  • +
## Tests @@ -56,7 +92,7 @@ tests:
```js -function eulersMethod (x1, y1, x2, h) { +function eulersMethod(x1, y1, x2, h) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/evaluate-binomial-coefficients.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/evaluate-binomial-coefficients.english.md index b0058c0c73..725ed90c07 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/evaluate-binomial-coefficients.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/evaluate-binomial-coefficients.english.md @@ -6,7 +6,8 @@ challengeType: 5 ## Description
-

Write a function to calculate the binomial coefficient for the given value of n and k.

This formula is recommended:

+Write a function to calculate the binomial coefficient for the given value of n and k. +This formula is recommended: $\binom{n}{k} = \frac{n!}{(n-k)!k!} = \frac{n(n-1)(n-2)\ldots(n-k+1)}{k(k-1)(k-2)\ldots 1}$
@@ -43,7 +44,7 @@ tests:
```js -function binom (n, k) { +function binom(n, k) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-a-markov-algorithm.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-a-markov-algorithm.english.md index 920dc4be7a..dc4bb76ce1 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-a-markov-algorithm.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-a-markov-algorithm.english.md @@ -6,45 +6,54 @@ challengeType: 5 ## Description
-Task: -

Create an interpreter for a Markov Algorithm.

Rules have the syntax:

-

::= (( | ) +)*

-

::= # {}

-

::= -> [.]

-

::= ( | ) []

-

There is one rule per line.

If there is a . (period) present before the , then this is a terminating rule in which case the interpreter must halt execution.

A ruleset consists of a sequence of rules, with optional comments.

-

Rulesets

Use the following tests on entries:

-Ruleset 1: +Create an interpreter for a Markov Algorithm. +Rules have the syntax:
-This rules file is extracted from Wikipedia:
-http://en.wikipedia.org/wiki/Markov_AlgorithmA -> apple
+[ruleset] ::= (([comment] | [rule]) [newline]+)*
+[comment] ::= # {[any character]}
+[rule] ::= [pattern] [whitespace] -> [whitespace] [.] [replacement]
+[whitespace] ::= ([tab] | [space]) [[whitespace]]
+
+There is one rule per line. +If there is a . (period) present before the [replacement], then this is a terminating rule in which case the interpreter must halt execution. +A ruleset consists of a sequence of rules, with optional comments. +Rulesets +Use the following tests on entries: +Ruleset 1: +
+# This rules file is extracted from Wikipedia:
+# http://en.wikipedia.org/wiki/Markov_Algorithm
+A -> apple
 B -> bag
 S -> shop
 T -> the
 the shop -> my brother
 a never used -> .terminating rule
 
-

Sample text of:

-

I bought a B of As from T S.

-

Should generate the output:

-

I bought a bag of apples from my brother.

-Ruleset 2: -

A test of the terminating rule

+Sample text of: +I bought a B of As from T S. +Should generate the output: +I bought a bag of apples from my brother. +Ruleset 2: +A test of the terminating rule
-Slightly modified from the rules on WikipediaA -> apple
+# Slightly modified from the rules on Wikipedia
+A -> apple
 B -> bag
 S -> .shop
 T -> the
 the shop -> my brother
-a never used -> .terminating rule
-

Sample text of:

-

I bought a B of As from T S.

-

Should generate:

-

I bought a bag of apples from T shop.

-Ruleset 3: -

This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.

+a never used -> .terminating rule + +Sample text of: +I bought a B of As from T S. +Should generate: +I bought a bag of apples from T shop. +Ruleset 3: +This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.
-BNF Syntax testing rulesA -> apple
+#BNF Syntax testing rules
+A -> apple
 WWWW -> with
 Bgage -> ->.*
 B -> bag
@@ -55,22 +64,24 @@ T -> the
 the shop -> my brother
 a never used -> .terminating rule
 
-

Sample text of:

-

I bought a B of As W my Bgage from T S.

-

Should generate:

-

I bought a bag of apples with my money from T shop.

-Ruleset 4: -

This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)

+Sample text of: +I bought a B of As W my Bgage from T S. +Should generate: +I bought a bag of apples with my money from T shop. +Ruleset 4: +This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)
-## Unary Multiplication Engine, for testing Markov Algorithm implementations
-## By Donal Fellows.
-Unary addition engine_+1 -> _1+
+### Unary Multiplication Engine, for testing Markov Algorithm implementations
+### By Donal Fellows.
+# Unary addition engine
+_+1 -> _1+
 1+1 -> 11+
-Pass for converting from the splitting of multiplication into ordinary
-addition1! -> !1
+# Pass for converting from the splitting of multiplication into ordinary
+# addition
+1! -> !1
 ,! -> !+
 _! -> _
-Unary multiplication by duplicating left side, right side times1*1 -> x,@y
+# Unary multiplication by duplicating left side, right side times1*1 -> x,@y
 1x -> xX
 X, -> 1,1
 X1 -> 1X
@@ -78,39 +89,46 @@ _x -> _X
 ,x -> ,X
 y1 -> 1y
 y_ -> _
-Next phase of applying1@1 -> x,@y
+# Next phase of applying1@1 -> x,@y
 1@_ -> @_
 ,@_ -> !_
 ++ -> +
-Termination cleanup for addition_1 -> 1
+# Termination cleanup for addition_1 -> 1
 1+_ -> 1
 _+_ ->
 
-

Sample text of:

-

_1111*11111_

-

should generate the output:

-

11111111111111111111

-Ruleset 5: -

A simple Turing machine,

-

implementing a three-state busy beaver.

The tape consists of 0s and 1s, the states are A, B, C and H (for Halt), and the head position is indicated by writing the state letter before the character where the head is.

-

All parts of the initial tape the machine operates on have to be given in the input.

Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.

+Sample text of: +_1111*11111_ +should generate the output: +11111111111111111111 +Ruleset 5: +A simple Turing machine, +implementing a three-state busy beaver.The tape consists of 0s and 1s, the states are A, B, C and H (for Halt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input. +Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.
-Turing machine: three-state busy beaver
-# state A, symbol 0 => write 1, move right, new state BA0 -> 1B
-state A, symbol 1 => write 1, move left, new state C0A1 -> C01
+#Turing machine: three-state busy beaver
+#
+# state A, symbol 0 => write 1, move right, new state B
+A0 -> 1B
+# state A, symbol 1 => write 1, move left, new state C
+0A1 -> C01
 1A1 -> C11
-state B, symbol 0 => write 1, move left, new state A0B0 -> A01
+# state B, symbol 0 => write 1, move left, new state A
+0B0 -> A01
 1B0 -> A11
-state B, symbol 1 => write 1, move right, new state BB1 -> 1B
-state C, symbol 0 => write 1, move left, new state B0C0 -> B01
+# state B, symbol 1 => write 1, move right, new state B
+B1 -> 1B
+# state C, symbol 0 => write 1, move left, new state B
+0C0 -> B01
 1C0 -> B11
-state C, symbol 1 => write 1, move left, halt0C1 -> H01
+# state C, symbol 1 => write 1, move left, halt
+0C1 -> H01
 1C1 -> H11
 
-

This ruleset should turn

-

000000A000000

-

into

-

00011H1111000

+This ruleset should turn +000000A000000 +into +00011H1111000
## Instructions @@ -146,7 +164,7 @@ tests:
```js -function markov (rules,test) { +function markov(rules,test) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-brain.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-brain.english.md index ab75c04876..9a7af84438 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-brain.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/execute-brain.english.md @@ -6,30 +6,22 @@ challengeType: 5 ## Description
-

Write a function to implement a Brain**** interpreter. The function will take a string as a parameter and should return a string as the output. More details are given below :

-

RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages.

Below are links to each of the versions of RCBF.

An implementation need only properly implement the following instructions:

-

{|

-

!Command

-

!Description

-

|-

-

| style="text-align:center"| > || Move the pointer to the right

-

|-

-

| style="text-align:center"| < || Move the pointer to the left

-

|-

-

| style="text-align:center"| + || Increment the memory cell under the pointer

-

|-

-

| style="text-align:center"| - || Decrement the memory cell under the pointer

-

|-

-

| style="text-align:center"| . || Output the character signified by the cell at the pointer

-

|-

-

| style="text-align:center"| , || Input a character and store it in the cell at the pointer

-

|-

-

| style="text-align:center"| [ || Jump past the matching ] if the cell under the pointer is 0

-

|-

-

| style="text-align:center"| ] || Jump back to the matching [ if the cell under the pointer is nonzero

-

|}

-

Any cell size is allowed, EOF (End-O-File) support is optional, as is whether you have bounded or unbounded memory.

+Write a function to implement a Brain**** interpreter. The function will take a string as a parameter and should return a string as the output. More details are given below: +RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. +Below are links to each of the versions of RCBF. +An implementation need only properly implement the following instructions: +| Command | Description | +| --- | --- | +| > | Move the pointer to the right | +| < | Move the pointer to the left | +| + | Increment the memory cell under the pointer | +| - | Decrement the memory cell under the pointer | +| . | Output the character signified by the cell at the pointer | +| , | Input a character and store it in the cell at the pointer | +| [ | Jump past the matching ] if the cell under the pointer is 0 | +| ] | Jump back to the matching [ if the cell under the pointer is nonzero | +Any cell size is allowed, EOF (End-O-File) support is optional, as is whether you have bounded or unbounded memory.
## Instructions @@ -63,7 +55,7 @@ tests:
```js -function brain (prog) { +function brain(prog) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md index 8924db78de..723a27149c 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md @@ -6,7 +6,15 @@ challengeType: 5 ## Description
-

Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime.

The generator should be able to : Show the first n prime numbers.Show the prime numbers in a range.Show the number of primes in a range.Show the nth prime number.

The function should have two parameters. The first will receive n or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the nth prime). According to the parameters the function should return an array. +Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime. +The generator should be able to: +

    +
  • Show the first n prime numbers.
  • +
  • Show the prime numbers in a range.
  • +
  • Show the number of primes in a range.
  • +
  • Show the nth prime number.
  • +
+The function should have two parameters. The first will receive n or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the nth prime). According to the parameters the function should return an array.
## Instructions @@ -40,7 +48,7 @@ tests:
```js -function primeGenerator (num, showPrimes) { +function primeGenerator(num, showPrimes) { // Good luck! } ```