-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollaztProblem.js
More file actions
55 lines (49 loc) · 1.51 KB
/
Copy pathcollaztProblem.js
File metadata and controls
55 lines (49 loc) · 1.51 KB
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
/*
function logDate(){
console.log(new Date());
}
logDate();
function square(n){
return n * n;
}
let n = 3;
console.log(square(n));
let nextChristmas = new Date('2024-12-25 00:00');
function updateParagraph(){
let now = new Date();
let seconds = (nextChristmas.getTime() - now.getTime()) / 1000;
document.getElementById('next-christmas').innerText =
'次のクリスマスまで後' + seconds + '秒。';
}
setInterval(updateParagraph, 50);
function areaOfCircle(r){
let area = r * r * 3.14;
return area;
}
document.write('<p>半径 5cm の円の面積は ' + areaOfCircle(5) + ' です。</p>');
document.write('<p>半径 10cm の円の面積は ' + areaOfCircle(10) + ' です。</p>');
document.write('<p>半径 15cm の円の面積は ' + areaOfCircle(15) + ' です。</p>');
*/
mainTask(317);
function mainTask(initialValue){
let collaztResults = {"trialCounter": 0,"resultValue" : initialValue};
resultDisplay(collaztResults);
for(i = 0 ; i < 100 ; i++){
if(collaztResults.resultValue!==1){
collatzFunction(collaztResults);
resultDisplay(collaztResults);
}
}
}
function resultDisplay(collaztResults){
document.write('Trial= '+collaztResults.trialCounter
+ ', Value= '+collaztResults.resultValue+'<br>');
}
function collatzFunction(collaztResults){
collaztResults.trialCounter++
if(collaztResults.resultValue % 2 === 0){
collaztResults.resultValue= collaztResults.resultValue / 2;
}else{
collaztResults.resultValue = collaztResults.resultValue * 3 + 1;
}
}