-
Notifications
You must be signed in to change notification settings - Fork 0
/
P5.js
65 lines (54 loc) · 1.66 KB
/
P5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ====== Problem 5 =================================== *
*
* 2520 is the smallest number that can be divided by
* each of the numbers from 1 to 10 without any remainder.
*
* What is the smallest positive number that is
* evenly divisible by all of the numbers from 1 to 20?
*
* ========================================**/
const MAX_RANGE = 20;
function isModZero() {
var number = 0;
for (var i = MAX_RANGE; i > 0; i--) {
if (number % i !== 0)
i = MAX_RANGE;
number += 1;
}
return number;
}
function solution() {
var answer = isModZero();
console.log(`The solution to problem 5 is: ${answer}`);
}
solution();
/* ====== Meta ========================================= *
*
* Estimated time of completion: 40 minutes
* Search engine used: Yes. Factorials && recursion
* Concepts learned: That recursive calls for computation
* should rarely be used. Introduction to node CLI, tail calls
*
* Additional notes: Successfully wrote this in a recursive
* call. Worked well for MAX_RANGE = 10, however, upon
* higher ranges, stack_size would be exceeded. Looked
* into this and it looks like recursive functions
* are rarely ever used because of this problem.
*
* With node.js you can use --use-strict --harmony-tailcalls
* to optimize the recursive tail call, but the iterative
* function ran much quicker.
*
* ========================================**/
// Recursive
//
// function isModZero(number, modulus) {
// // base case
// if (modulus === 0) {
// return number;
// }
// if (number % modulus !== 0) {
// return isModZero((number+1), MAX_RANGE);
// }
// return isModZero((number+1), (modulus-1));
// }