Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Created July 11, 2021 08:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-wilkes/0c582c9a8d6d1553daef2027f8444a06 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/0c582c9a8d6d1553daef2027f8444a06 to your computer and use it in GitHub Desktop.
Prime Numbers with GDScript
extends Node2D
export var nmax = 300
func _ready():
# Find prime numbers
sieve_of_eratosthenes(nmax)
func sieve_of_eratosthenes(n: int):
var nums = range(n + 1)
for i in range(2, sqrt(n) + 1):
var j = i * i
while j <= n:
nums[j] = 0
j += i
var primes: Array
for p in nums:
if p > 1:
primes.append(p)
print(primes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment