RosettaCodeData/Task/Hash-join/Pluto/hash-join.pluto
2026-04-30 12:34:36 -04:00

45 lines
921 B
Text

local fmt = require "fmt"
class A
function __construct(public age, public name)
end
end
class B
function __construct(public character, public nemesis)
end
end
local tableA = {
new A(27, "Jonah"), new A(18, "Alan"), new A(28, "Glory"),
new A(18, "Popeye"), new A(28, "Alan")
}
local tableB = {
new B("Jonah", "Whales"), new B("Jonah", "Spiders"), new B("Alan", "Ghosts"),
new B("Alan", "Zombies"), new B("Glory", "Buffy")
}
local h = {}
local i = 1
for tableA as a do
local n = h[a.name]
if n then
n:insert(i)
else
h[a.name] = {i}
end
i += 1
end
print("Age Name Character Nemesis")
print("--- ----- --------- -------")
for tableB as b do
local c = h[b.character]
if c then
for c as j do
local t = tableA[j]
fmt.print("%3d %-5s %-9s %s", t.age, t.name, b.character, b.nemesis)
end
end
end