Merge pull request #115 from christianbender/master
collatz algorithm -- changed in 'js'
This commit is contained in:
9
snippets/collatz-algorithm.md
Normal file
9
snippets/collatz-algorithm.md
Normal file
@ -0,0 +1,9 @@
|
||||
### Collatz algorithm
|
||||
|
||||
If `n` is even, return `n/2`. Otherwise return `3n+1`.
|
||||
|
||||
```js
|
||||
const collatz = n => (n % 2 == 0) ? (n/2) : (3*n+1);
|
||||
// collatz(8) --> 4
|
||||
// collatz(5) --> 16
|
||||
```
|
||||
Reference in New Issue
Block a user