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.159 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.158 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.157 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.156 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.155 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.154 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.153 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.152 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.151 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.150 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.149 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.148 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.147 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.146 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.145 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.144 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.143 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.142 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.141 tracks/lua/exercises/pythagorean-triplet/example.lua
trackler-2.2.1.140 tracks/lua/exercises/pythagorean-triplet/example.lua