Skip to content

Instantly share code, notes, and snippets.

View martian0x80's full-sized avatar
🐲
On vacation

Vedant Arya martian0x80

🐲
On vacation
View GitHub Profile
@martian0x80
martian0x80 / partitions.jl
Created October 27, 2022 11:49
Partition function, coin-change problem, generating integer partitions in (anti-)/lexicographic order.
using DataStructures
using DSP
#=
ZS1 and ZS2 based on ALGORITHMS explained in :
FAST ALGORITHMS FOR GENERATING
INTEGER PARTITIONS
ANTOINE ZOGHBIU and IVAN STOJMENOVIC*
Bell Northern Research, P.O . Box 35 I I , Station C , Mail Stop 091 ,
Ottawa, Ontario KIY 4H7, Canada;
Computer Science Department, SITE, University of Ottawa,
@martian0x80
martian0x80 / BerggrensTree.jl
Created October 26, 2022 17:36
Berggrens Tree to generate primitive triples. Some inefficient way to generate millions of triples. :)
function primitive_triples(depth::Int64, max_sum::Int64 = 0, list::Bool = false)
#=
depth : tree depth
each depth adds 3^i new triples each depth.
total triples with depth 'd' : ∑_(i=0;d) 3^i
max_sum : maximum perimeter of the right triangle formed by the triples, breaks if the limit (max_sum) is reached, but includes the last 3 triples one of which exceed the limit.
0 is the default value, to ignore any restrictions.
list : return a flat array of the triples
=#