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 end