Skip to content

Commit 3538a6a

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 3338fe1 + 97edeb2 commit 3538a6a

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

RandSum0/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class genSum{
2525
}
2626
}
2727
pickRandNum({min,max,negative = false}){
28-
let num = Math.floor(Math.random()* 100) + 0;
28+
let num = Math.floor(Math.random()* max) + min;
2929
if(negative) num *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
3030
return num;
3131
}

pigeons-challange/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Pigeons
2+
When I start to feed my pigeon, a minute later two more fly by. And a minute later another 3.
3+
Then 4, and so on. One portion of food lasts a pigeon for a minute.
4+
In case there’s not enough food for all the birds, the pigeons that came first, eat first. Pigeons are hungry animals and eat without stopping.
5+
How many pigeons I’d have to feed at least once if I have N portions wheat?
6+
7+
-------
8+
9+
**Enjoy**
10+

pigeons-challange/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Pigeons</title>
8+
</head>
9+
<body>
10+
<script src="pigeons.js"></script>
11+
</body>
12+
</html>

pigeons-challange/pigeons.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function feeding(totalWheat){
2+
let pigeonsTotal = 0;
3+
let nextPigeonGroup = 1;
4+
let currWheat = totalWheat;
5+
while(pigeonsTotal < currWheat) {
6+
if(pigeonsTotal+nextPigeonGroup>totalWheat) break;
7+
pigeonsTotal += nextPigeonGroup;
8+
currWheat -= pigeonsTotal;
9+
nextPigeonGroup++;
10+
}
11+
return console.log(`With ${totalWheat} wheat you can feed ${pigeonsTotal} pigeons - last group of pigeons is equal to ${nextPigeonGroup} `)
12+
}
13+
14+
15+
// 1 pigeon - 1 wheat
16+
// total wheat 10 - 1 = 9
17+
// 2 next pigeons group + 1 curr pigeon = 3 pigeons - 3 wheat
18+
// total wheat 9 - 3 = 6
19+
// 3 next pigeons group + 3 curr pigeons = 6 pigeons - 6 wheat
20+
// total wheat 6 - 6 = 0
21+
// total wheat < pigeonsTotal = break
22+
23+
feeding(10);

0 commit comments

Comments
 (0)