Created
September 18, 2011 03:06
-
-
Save clairvy/1224670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = 'http://gdd-2011-quiz-japan.appspot.com/webgame/problem'; | |
$.get(url, {}, function(data) { | |
var comment; | |
if (data.match(/(\[[^\]]+\])/)) { | |
comment = RegExp.$1; | |
} | |
var list = eval(comment); | |
var pos = {}; | |
for (var i = 0; i < list.length; i += 1) { | |
var key = list[i]; | |
if (pos[key] == undefined) { | |
pos[key] = []; | |
} | |
if (pos[key].length > 1) { | |
alert(key + ' has too many pos ' + pos[key] + ', ' + i); | |
} | |
pos[key].push(i); | |
} | |
solve(pos); | |
}); | |
function solve(pos) { | |
for (var key in pos) { | |
var p = pos[key]; | |
if (p.length < 2) { | |
alert('pos too short : ' + p + ' for key: ' + key); | |
} | |
var h = p.shift(); | |
var t = p.shift(); | |
show(h); | |
show(t); | |
while (p.length >= 2) { | |
h = p.shift(); | |
t = p.shift(); | |
show(h); | |
show(t); | |
} | |
} | |
} | |
function show(n) { | |
var element = document.getElementById('card' + n); | |
var myevent = document.createEvent('MouseEvents'); | |
myevent.initEvent('click', false, true); | |
element.dispatchEvent(myevent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment