-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollatz.html
More file actions
80 lines (70 loc) · 2.57 KB
/
Copy pathcollatz.html
File metadata and controls
80 lines (70 loc) · 2.57 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="Explore the Collatz Conjecture: the 3n+1 problem visualized."
/>
<title>Collatz Conjecture – Fun With Math</title>
<link rel="stylesheet" href="../../css/style.css" />
<link rel="stylesheet" href="../../css/experiments-basic-collatz.css" />
</head>
<body>
<nav>
<a class="brand" href="../../index.html">∑ Fun With Math</a>
<a href="../../index.html">← All Experiments</a>
</nav>
<div class="page-header">
<h1>Collatz Conjecture</h1>
<p>Pick any positive integer. Apply the rule. Will you always reach 1?</p>
</div>
<div class="experiment-layout">
<div>
<div id="statsRow">
<span>Steps: <strong id="stepsEl">—</strong></span>
<span>Peak value: <strong id="peakEl">—</strong></span>
<span>Starting at: <strong id="startEl">—</strong></span>
</div>
<div class="canvas-wrapper">
<canvas id="canvas"></canvas>
</div>
<div class="info-box" style="margin-top: 1rem">
<h4>Sequence</h4>
<div id="resultBox">—</div>
</div>
</div>
<aside class="controls">
<h3>Controls</h3>
<label>
Starting Number
<input type="number" id="startInput" value="27" min="1" max="100000" />
</label>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap">
<button class="btn btn-primary" id="goBtn">▶ Compute</button>
<button class="btn btn-secondary" id="randomBtn">🎲 Random</button>
</div>
<label>
Compare Range: 2 – <span id="rangeLabel">50</span>
<input type="range" id="rangeSlider" min="10" max="500" step="10" value="50" />
</label>
<button class="btn btn-secondary" id="compareBtn">📊 Compare Range</button>
<div class="info-box">
<h4>The Rule</h4>
<p>
Given a positive integer <code>n</code>:<br />
• If <code>n</code> is even → <code>n / 2</code><br />
• If <code>n</code> is odd → <code>3n + 1</code><br />
Repeat until <code>n = 1</code>.
</p>
</div>
<div id="compareTable"></div>
</aside>
</div>
<footer>
<p><a href="../../index.html">← Back to all experiments</a></p>
</footer>
<script src="../../js/experiments-basic-collatz.js"></script>
</body>
</html>