Created
March 12, 2022 09:53
-
-
Save andrew-wilkes/ec9e688a61924409d020fa8772429de0 to your computer and use it in GitHub Desktop.
Collatz conjecture 3n + 1 code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
# Has a Line2D child node to plot a curve using each number of the series that tends to 1 | |
const XSTEP = 10 | |
var x = 0 | |
func _ready(): | |
calc(211) | |
func calc(n: int): | |
add_point(n) | |
if n == 1 or x == 1920: return | |
if n % 2 == 0: | |
n /= 2 | |
else: | |
n = n * 3 + 1 | |
return calc(n) | |
func add_point(n): | |
x += XSTEP | |
$Line.add_point(Vector2(x, n)) |
Author
andrew-wilkes
commented
Mar 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment