Skip to content

Commit

Permalink
Varyx
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredkrinke committed Jan 11, 2025
1 parent 0f1370a commit 19cd566
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ This repository tracks a [misguided quest to write code in 100 different program
| 92 | [Square Digit Chains](https://projecteuler.net/problem=92) | [Mouse-83](http://mouse.davidgsimpson.com/mouse83/index.html) | [p92.mou](src/p92.mou) |
| 93 | [Arithmetic Expressions](https://projecteuler.net/problem=93) | [Cyber](https://cyberscript.dev/) | [p93.cy](src/p93.cy) |
| 94 | [Almost Equilateral Triangles](https://projecteuler.net/problem=94) | [Futhark](https://futhark-lang.org/) | [p94.fut](src/p94.fut) |
| 95 | [Amicable Chains](https://projecteuler.net/problem=95) | TBD | |
| 95 | [Amicable Chains](https://projecteuler.net/problem=95) | [Varyx](https://www.vcode.org/) | [p95.vx](src/p95.vx) |
| 96 | [Su Doku](https://projecteuler.net/problem=96) | [Prolog](https://en.wikipedia.org/wiki/Prolog) ([SWI-Prolog](https://www.swi-prolog.org/)) | [p96.pro](src/p96.pro) |
| 97 | [Large Non-Mersenne Prime](https://projecteuler.net/problem=97) | [8080 assembly](https://en.wikipedia.org/wiki/Intel_8080) ([Altair 8800](https://en.wikipedia.org/wiki/Altair_8800)) | [p97.asm](src/p97.asm) |
| 98 | [Anagramic Squares](https://projecteuler.net/problem=98) | TBD | |
Expand Down
80 changes: 80 additions & 0 deletions src/p95.vx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const max = 1000000

def contains(l, k)
{
for n in l do
{
if n == k then
{
return true
}
}
return false
}

def sum_divisors(n)
{
var sum = 1
var m = 2

# Note: There MUST be a line before "while" for it to work
while (m * m) <= n do
{
if (n % m) == 0 then
{
sum += m + (n / m)
}

m++
}

return sum
}

def compute_amicable_chain(m)
{
var n = m
var smallest = max
var chain_length = 1
var seen = []

while true do
{
seen <-- n
n = sum_divisors(n)

if n < smallest then
{
smallest = n
}

if n == m then
{
return chain_length, smallest
}

if (n > max) or (n < m) or contains(seen, n) then
{
return 0, max
}

chain_length++
}
}

# Entry point
var max_length = 0
var smallest_member = max
for n in 1 -> (max + 1) do
{
var (length, smallest) = compute_amicable_chain(n)
if length > max_length then
{
max_length = length
smallest_member = smallest
print smallest_member
}
}

print smallest_member

0 comments on commit 19cd566

Please sign in to comment.