Post Reply 
Challenge - Keypad puzzle
02-14-2020, 12:00 AM
Post: #9
RE: Challenge - Keypad puzzle
Code:
function gcd(a, b)
    if b==0 then return a end
    return gcd(b, a%b)
end

function all_gcds()
    t = {{5,4,1,2},{5,2,3,6},{5,6,9,8},{5,8,7,4}}
    t_table = {__index = function(F,i) return F[1+(i-1)%4] end}
    for i=1,#t do
        local a = setmetatable(t[i], t_table)   -- allow wrap around
        for j=1,4 do                            -- 4 corners
            local d = 1000*a[j] + 10*a[j+2]
            local x = d + 100*a[j+1] + a[j+3]
            local y = d + 100*a[j+3] + a[j+1]
            print(x,y,gcd(x,y))
        end
    end
end

Above is my brute-force Lua code.
Only 16 cases, all of them included the "5", common prime factor = 11

lua> all_gcds()
5412     5214     66
4125     4521     33
1254     1452     66
2541     2145     33
5236     5632     44
2365     2563     11
3652     3256     44
6523     6325     11
5698     5896     22
6985     6589     11
9856     9658     22
8569     8965     11
5874     5478     66
8745     8547     33
7458     7854     66
4587     4785     33
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Challenge - Keypad puzzle - pinkman - 02-13-2020, 08:30 AM
RE: Challenge - Keypad puzzle - John Keith - 02-13-2020, 05:34 PM
RE: Challenge - Keypad puzzle - pinkman - 02-13-2020, 09:07 PM
RE: Challenge - Keypad puzzle - John Keith - 02-13-2020, 06:00 PM
RE: Challenge - Keypad puzzle - pinkman - 02-13-2020, 09:09 PM
RE: Challenge - Keypad puzzle - pinkman - 02-14-2020, 06:25 AM
RE: Challenge - Keypad puzzle - pinkman - 02-13-2020, 09:11 PM
RE: Challenge - Keypad puzzle - Albert Chan - 02-14-2020 12:00 AM
RE: Challenge - Keypad puzzle - pinkman - 02-14-2020, 06:45 AM
RE: Challenge - Keypad puzzle - pinkman - 02-14-2020, 12:07 PM
RE: Challenge - Keypad puzzle - pinkman - 02-14-2020, 12:17 PM
RE: Challenge - Keypad puzzle - John Keith - 02-14-2020, 09:12 PM
RE: Challenge - Keypad puzzle - pinkman - 02-14-2020, 10:55 PM
RE: Challenge - Keypad puzzle - John Keith - 02-15-2020, 06:38 PM



User(s) browsing this thread: 3 Guest(s)