get("#356") -- num2hex
get("#485") -- containsColor
-- Job: Distinguish two classes of images
-- Two images are supplied at once, one of each class.
-- Task is to find out if the two images are swapped or not.
--
-- input variables: img1, img2, solution [to last pair]
-- output: a function returning true or false (swapped or no)
function selectColor(img)
local x, y = math.random(0, img.width-1), math.random(0, img.height-1)
color = img.getInt(x, y)
end
return function()
-- select a new color when last guess was wrong
if solution ~= guess then color = nil end
if color == nil then
if solution == nil then
lastimg1, lastimg2 = img1, img2
return false -- just return something
end
selectColor(lastimg1)
class2sampled = solution
print("color of class "..(class2sampled and "2" or "1")..": ".. num2hex(color))
end
lastimg1, lastimg2 = img1, img2
flag1 = containsColor(img1, color)
flag2 = containsColor(img2, color)
if flag1 == flag2 then
color = nil
return false
end
guess = flag1 == class2sampled
return guess
endBegan life as a copy of #483
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #484 |
| Snippet name: | Image distinguisher by randomly selected color |
| Eternal ID of this version: | #484/1 |
| Text MD5: | 570216e2e5c9b9c845e8e558916f517e |
| Author: | stefan |
| Category: | |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-03-04 22:40:53 |
| Source code size: | 1133 bytes / 40 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1048 / 329 |
| Referenced in: | [show references] |