-
Notifications
You must be signed in to change notification settings - Fork 0
/
numagram.lua
63 lines (56 loc) · 1.44 KB
/
numagram.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function get_name()
return "NUMAGRAM (HARD)"
end
function get_description()
return { "READ A NUMBER FROM IN.A AND IN.B", "CHECK WHETHER THE NUMBERS CONTAIN THE SAME DIGITS, NOT NECESSARILY IN THE SAME ORDER", "OUTPUT 1 IF THEY DO, ELSE 0" }
end
function get_streams()
local input = {}
local input2 = {}
local output = {}
for i = 1,39 do
local num1 = math.random(100, 999)
local num2 = math.random(100, 999)
input[i] = num1
input2[i] = num2
local num1Digits = digits(num1)
local tries = 0
local found = false
while tries < 100 and num2+tries < 1000 do
local num2Digits = digits(num2+tries)
if num1Digits[1] == num2Digits[1] and num1Digits[2] == num2Digits[2] and num1Digits[3] == num2Digits[3] then
input2[i] = num2+tries
output[i] = 1
found = true
break
end
tries = tries+7
end
if not found then
output[i] = 0
end
end
return {
{ STREAM_INPUT, "IN.A", 1, input },
{ STREAM_INPUT, "IN.B", 2, input2 },
{ STREAM_OUTPUT, "OUT", 2, output },
}
end
function digits(num)
local result = {}
while num > 0 do
local remainder = math.floor(num/10)
local lastDigit = num - remainder*10
table.insert(result, lastDigit)
num = remainder
end
table.sort(result)
return result
end
function get_layout()
return {
TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
}
end