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.2.1.180 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.179 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.178 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.177 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.176 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.175 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.174 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.173 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.172 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.171 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.170 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.169 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.167 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.166 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.165 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.164 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.163 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.162 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.161 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.160 tracks/lua/exercises/pythagorean-triplet/example.lua