Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Created March 12, 2022 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-wilkes/ec9e688a61924409d020fa8772429de0 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/ec9e688a61924409d020fa8772429de0 to your computer and use it in GitHub Desktop.
Collatz conjecture 3n + 1 code
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))
@andrew-wilkes
Copy link
Author

collatz-conjecture-godot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment