1 | get("#356") -- num2hex |
2 | get("#485") -- containsColor |
3 | |
4 | -- Job: Distinguish two classes of images |
5 | -- Two images are supplied at once, one of each class. |
6 | -- Task is to find out if the two images are swapped or not. |
7 | -- |
8 | -- input variables: img1, img2, solution [to last pair] |
9 | -- output: a function returning: |
10 | -- nil if still learning |
11 | -- {"#executorid", varname1=value1, varname2=value2, ...} |
12 | |
13 | function selectColor(img) |
14 | local x, y = math.random(0, img.width-1), math.random(0, img.height-1) |
15 | color = img.getInt(x, y) |
16 | end |
17 | |
18 | return function() |
19 | -- select a new color when last guess was wrong |
20 | if solution ~= guess then color = nil end |
21 | |
22 | if color == nil then |
23 | if solution == nil then |
24 | lastimg1, lastimg2 = img1, img2 |
25 | return nil |
26 | end |
27 | selectColor(lastimg1) |
28 | class2sampled = solution |
29 | print("color of class "..(class2sampled and "2" or "1")..": ".. num2hex(color)) |
30 | end |
31 | |
32 | lastimg1, lastimg2 = img1, img2 |
33 | |
34 | flag1 = containsColor(img1, color) |
35 | flag2 = containsColor(img2, color) |
36 | if flag1 == flag2 then |
37 | color = nil |
38 | return nil |
39 | end |
40 | guess = flag1 == class2sampled |
41 | return {"#486", class2sampled=class2sampled, color=color} |
42 | end |
Began life as a copy of #484
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: | #487 |
Snippet name: | Image distinguisher by randomly selected color [learner part] |
Eternal ID of this version: | #487/1 |
Text MD5: | a76912bdb80b158dcacf700446cee68f |
Author: | stefan |
Category: | |
Type: | Lua code - Image distinction (learner) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-03-03 18:26:57 |
Source code size: | 1209 bytes / 42 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 635 / 176 |
Referenced in: | [show references] |