Sha256: 8dee225578406d4609fb6761cf39667d61e94b8843344e0e1874f2c81da05b4c
Contents?: true
Size: 689 Bytes
Versions: 396
Compression:
Stored size: 689 Bytes
Contents
local function is_triplet(...) local t = table.pack(...) table.sort(t) return t[1] ^ 2 + t[2] ^ 2 == t[3] ^2 end local function triplets_with(options) local function matching_triplet(a, b, c) if is_triplet(a, b, c) then return not options.sum or (options.sum == (a + b + c)) end end local triplets = {} for a = options.min_factor or 1, options.max_factor do for b = a + 1, options.max_factor do for c = b + 1, options.max_factor do if matching_triplet(a, b, c) then table.insert(triplets, { a, b, c }) end end end end return triplets end return { is_triplet = is_triplet, triplets_with = triplets_with }
Version data entries
396 entries across 396 versions & 1 rubygems