Skip to content

Instantly share code, notes, and snippets.

@Dombo
Created October 13, 2015 18:34
Show Gist options
  • Select an option

  • Save Dombo/016b7d0d0ffa4093f8e9 to your computer and use it in GitHub Desktop.

Select an option

Save Dombo/016b7d0d0ffa4093f8e9 to your computer and use it in GitHub Desktop.
An interesting homework problem I got - algorithms from the 19th & 3rd century in pseudocode
Pyth-seudocode time!
erasto(n): // circa 240 BC haha
a[1] := 0
for i := 2 to n do a[i] := 1
p := 2
while p^2 < n do
j := p^2
while (j < n) do
a[j] := 0
j := j+p
repeat p := p+1 until a[p] = 1
return(a)
encode(list_numbers): // Encoding
prime := 2
summate := 0
length := count(list_numbers) //how many numbers we working with?
primes := find_n_primes(length) //get me some primes son
for i in list_numbers:
summate += i^(prime) //character to the power of the relevant prime
prime := erasto(prime)
i++
return summate
decode(n, sequence = [], prime = 2): // Decoding
count := 0
while (n % prime) == 0 // Primality check
n /= prime
count++
sequence.add(count) // One value decoded
prime := erasto(prime)
decode(n, sequence, prime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment