Skip to content

Commit 585382c

Browse files
author
Vitalii Telychko
committed
qwew
1 parent ce6a8d8 commit 585382c

File tree

7 files changed

+140
-2
lines changed

7 files changed

+140
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
3+
4+
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
5+
6+
By considering the terms in the Fibonacci sequence whose values do not exceed nth term, find the sum of the even-valued terms.
7+
*/
8+
9+
10+
// function fiboEvenSum(n) {
11+
// var fib = [], i, j, sum = 0;
12+
// fib[0] = 1;
13+
// fib[1] = 2;
14+
// for(i = 2; i <= n; i += 1) {
15+
// fib[i] = fib[i - 2] + fib[i - 1];
16+
// }
17+
// for(j = 0; j < fib.length; j += 1) {
18+
// if(fib[j] % 2 === 0) sum += fib[j];
19+
// }
20+
// return sum;
21+
// }
22+
//
23+
// fiboEvenSum(10);

euler_project/multiples_of_3_and_5.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
3+
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
4+
Find the sum of all the multiples of 3 or 5 below the provided parameter value number.
5+
6+
*/
7+
8+
// function multiplesOf3and5(number) {
9+
// var i, arr = [];
10+
// for(i = 0; i < number; i += 1) {
11+
// if(i % 3 === 0 || i % 5 === 0) arr.push(i);
12+
// }
13+
// return arr.reduce((a, b) => a + b);
14+
// }
15+
//
16+
// multiplesOf3and5(1000);

freecodecamp/basic/factorialize.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@
33
// return num * factorialize(num-1);
44
// }
55
//
6-
// factorialize(5);
6+
// factorialize(5);
7+
8+
// function factorialize(num) {
9+
// var i, acc = 1;
10+
// for(i = num; i > 0; i -= 1) {
11+
// acc *= i;
12+
// }
13+
// return acc;
14+
// }
15+
//
16+
// console.log(factorialize(5));

freecodecamp/basic/sliceAndSplice.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// function frankenSplice(arr1, arr2, n) {
2+
// // It's alive. It's alive!
3+
// let localArray = arr2.slice();
4+
// for (let i = 0; i < arr1.length; i++) {
5+
// localArray.splice(n, 0, arr1[i]);
6+
// n++;
7+
// }
8+
// return localArray;
9+
// }
10+
//
11+
// frankenSplice([1, 2, 3], [4, 5, 6], 1);

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
<div id="content"></div>
1212

13-
<script src="others/promise_setTimeOut.js"></script>
13+
<script src="euler_project/even_fibonacci_numbers.js"></script>
1414
</body>
1515
</html>

rosetta_code/100_doors.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
3+
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors.
4+
The first time through, visit every door and 'toggle' the door (if the door is closed, open it; if it is open, close it).
5+
The second time, only visit every 2nd door (i.e., door #2, #4, #6, ...) and toggle it.
6+
The third time, visit every 3rd door (i.e., door #3, #6, #9, ...), etc., until you only visit the 100th door.
7+
Implement a function to determine the state of the doors after the last pass.
8+
Return the final result in an array, with only the door number included in the array if it is open.
9+
10+
*/
11+
12+
// var doors = [];
13+
//
14+
// function getFinalOpenedDoors(numDoors, step) {
15+
// var i, j;
16+
// if(step > numDoors) {
17+
// return doors.reduce((acc, curr, index) => {
18+
// curr && acc.push(index);
19+
// return acc;
20+
// }, []);
21+
// }
22+
//
23+
// if(step === 1) for(i = 0; i < numDoors + 1; i += 1) doors.push(true);
24+
// else for(j = 0; j <= doors.length; j += step) doors[j] = !doors[j];
25+
// return getFinalOpenedDoors(numDoors, step + 1);
26+
// }
27+
//
28+
// getFinalOpenedDoors(100, 1);

rosetta_code/24_game.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Implement a function that takes a string of four digits as its argument, w
3+
ith each digit from 1 ──► 9 (inclusive) with repetitions allowed,
4+
and returns an arithmetic expression that evaluates to the number 24.
5+
If no such solution exists, return "no solution exists."
6+
7+
Rules:
8+
9+
Only the following operators/functions are allowed: multiplication, division, addition, subtraction
10+
11+
Division should use floating point or rational arithmetic, etc, to preserve remainders.
12+
13+
Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong).
14+
15+
The order of the digits when given does not have to be preserved.
16+
17+
Example inputs:
18+
19+
solve24("4878");
20+
21+
solve24("1234");
22+
23+
solve24("6789");
24+
25+
solve24("1127");
26+
27+
Example outputs (strings):
28+
29+
(7-8/8)*4
30+
31+
3*1*4*2
32+
33+
(6*8)/(9-7)
34+
35+
(1+7)*(2+1)
36+
37+
*/
38+
39+
40+
function solve24(numStr) {
41+
var array = numStr.split('').map(Number), tf = 24, i;
42+
for(i = 0; i < array.length; i += 1) {
43+
if(array[i]) {
44+
array.splice(i, 1);
45+
}
46+
}
47+
console.log(array);
48+
}
49+
50+
solve24('4878');

0 commit comments

Comments
 (0)