fix(challenges): J problems

This commit is contained in:
Kris Koishigawa 2019-03-06 22:04:30 +09:00 committed by mrugesh
parent 263d2c496b
commit df88daa482
3 changed files with 24 additions and 15 deletions

View File

@ -6,21 +6,31 @@ challengeType: 5
## Description
<section id='description'>
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that <b>0</b> equates to no similarity and <b>1</b> is an exact match. Definition The Jaro distance \( d_j \) of two given strings \(s_1\) and \(s_2\) is
The Jaro distance is a measure of similarity between two strings. The higher the Jaro distance for two strings is, the more similar the strings are. The score is normalized such that <b>0</b> equates to no similarity and <b>1</b> is an exact match.
<b>Definition</b>
The Jaro distance \( d_j \) of two given strings \(s_1\) and \(s_2\) is
\begin{align}d_j = \begin{cases}0&amp; & \text{if }m=0 \\\\{\frac {1}{3}}\left({\frac {m}{|s_{1}|}}+{\frac {m}{|s_{2}|}}+{\frac {m-t}{m}}\right)&amp; & \text{otherwise}\end{cases}\end{align}
Where: <ul><li>\(m\) is the number of <i>matching characters</i>;</li><li> \(t\) is half the number of <i>transpositions</i>.</li></uL>
Where:
<ul>
<li>\(m\) is the number of <i>matching characters</i>;</li>
<li> \(t\) is half the number of <i>transpositions</i>.</li>
</uL>
Two characters from \(s_1\) and \(s_2\) respectively, are considered <i>matching</i> only if they are the same and not farther than \(\left\lfloor\frac{\max(|s_1|,|s_2|)}{2}\right\rfloor-1\).
Each character of \(s_1\) is compared with all its matching characters in \(s_2\) . The number of matching (but different sequence order) characters divided by 2 defines the number of <i>transpositions</i>.
<b>Example</b>
Given the strings \(s_1\) <i>DWAYNE</i> and \(s_2\) <i>DUANE</i> we find:
<ul><li>\(m = 4\)</li><li>\(|s_1| = 6\) </li><li>\(|s_2| = 5\) </li><li>\(t = 0\) </li></ul>
<ul>
<li>\(m = 4\)</li>
<li>\(|s_1| = 6\)</li>
<li>\(|s_2| = 5\)</li>
<li>\(t = 0\)</li>
</ul>
We find a Jaro score of: \(d_j = \frac{1}{3}\left(\frac{4}{6} + \frac{4}{5} + \frac{4-0}{4}\right) = 0.822\).
Write a function a that takes two strings as parameters and returns the associated Jaro distance.
</section>
## Instructions
<section id='instructions'>
Write a function a that takes two strings as parameters and returns the associated Jaro distance.
</section>
## Tests
@ -53,7 +63,7 @@ tests:
<div id='js-seed'>
```js
function jaro (s, t) {
function jaro(s, t) {
// Good luck!
}
```
@ -67,7 +77,7 @@ function jaro (s, t) {
```js
function jaro (s, t) {
function jaro(s, t) {
var s_len = s.length;
var t_len = t.length;

View File

@ -6,7 +6,7 @@ challengeType: 5
## Description
<section id='description'>
jortSort is a sorting toolset that makes the user do the work and guarantees efficiency because you don't have to sort ever again. It was originally presented by Jenn "Moneydollars" Schiffer at the prestigious <a href="https://www.youtube.com/watch?v=pj4U_W0OFoE">JSConf</a>.
jortSort is a sorting toolset that makes the user do the work and guarantees efficiency because you don't have to sort ever again. It was originally presented by Jenn "Moneydollars" Schiffer at the prestigious <a href="https://www.youtube.com/watch?v=pj4U_W0OFoE" target="_blank">JSConf</a>.
jortSort is a function that takes a single array of comparable objects as its argument. It then sorts the array in ascending order and compares the sorted array to the originally provided array. If the arrays match (i.e. the original array was already sorted), the function returns true. If the arrays do not match (i.e. the original array was not sorted), the function returns false.
</section>
@ -47,7 +47,7 @@ tests:
<div id='js-seed'>
```js
function jortsort (array) {
function jortsort(array) {
// Good luck!
}
```
@ -61,7 +61,7 @@ function jortsort (array) {
```js
function jortsort (array) {
function jortsort(array) {
// sort the array
var originalArray = array.slice(0);
array.sort( function(a,b){return a - b} );

View File

@ -6,7 +6,7 @@ challengeType: 5
## Description
<section id='description'>
<a href="https://en.wikipedia.org/wiki/Josephus problem">Josephus problem</a> is a math puzzle with a grim description: $n$ prisoners are standing on a circle, sequentially numbered from $0$ to $n-1$.
<a href="https://en.wikipedia.org/wiki/Josephus problem" target="_blank">Josephus problem</a> is a math puzzle with a grim description: $n$ prisoners are standing on a circle, sequentially numbered from $0$ to $n-1$.
An executioner walks along the circle, starting from prisoner $0$, removing every $k$-th prisoner and killing him.
As the process goes on, the circle becomes smaller and smaller, until only one prisoner remains, who is then freed.
For example, if there are $n=5$ prisoners and $k=2$, the order the prisoners are killed in (let's call it the "killing sequence") will be 1, 3, 0, and 4, and the survivor will be #2.
@ -14,12 +14,11 @@ Given any <big>$n, k > 0$</big>, find out which prisoner will be the final sur
In one such incident, there were 41 prisoners and every 3<sup>rd</sup> prisoner was being killed (<big>$k=3$</big>).
Among them was a clever chap name Josephus who worked out the problem, stood at the surviving position, and lived on to tell the tale.
Which number was he?
Write a function that takes the initial number of prisoners and 'k' as parameter and returns the number of the prisoner that survives.
</section>
## Instructions
<section id='instructions'>
Write a function that takes the initial number of prisoners and 'k' as parameter and returns the number of the prisoner that survives.
</section>
## Tests
@ -52,7 +51,7 @@ tests:
<div id='js-seed'>
```js
function josephus (init, kill) {
function josephus(init, kill) {
// Good luck!
}
```
@ -68,7 +67,7 @@ function josephus (init, kill) {
```js
function josephus (init, kill) {
function josephus(init, kill) {
var Josephus = {
init: function(n) {
this.head = {};