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

Version Path
trackler-2.0.0.5 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.0.0.4 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.0.0.3 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.0.0.2 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.0.0.1 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.0.0.0 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.4.1 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.4.0 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.3.0 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.2.1 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.2.0 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.1.2 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.1.1 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.1.0 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.0.1 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-1.0.0 tracks/lua/exercises/pythagorean-triplet/example.lua