Skip to content

Instantly share code, notes, and snippets.

@Akiyah
Last active September 7, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akiyah/78c497ce815eb618e0a1 to your computer and use it in GitHub Desktop.
Save Akiyah/78c497ce815eb618e0a1 to your computer and use it in GitHub Desktop.
とけたら天才!分裂する●を追い出せ!
●をクリックすると消えて右と下に分裂する。
左上6マスの白いブロックから●を追い出せ。
参考
バナッハ‐タルスキの密室: 『数学者シャーロック・ホームズ』増補・改題
http://www.amazon.co.jp/dp/4535787409
* {
margin: 0;
padding: 0;
border: 0;
}
body {
background: #fdf;
font: 20px sans-serif;
}
table {
margin: 10px;
border-spacing: 0px;
/* border-collapse: collapse; */
}
td {
background: silver;
border: solid 2px gray;
width: 20px;
height: 20px;
font: 20px sans-serif;
}
●をクリックすると消えて右と下に分裂する。<br/>
左上6マスの白いブロックから●を追い出せ。<br/>
<table>
</table>
var N = 10;
function position(td) {
var tr = td.parent();
var table = tr.parent();
var x = tr.find('td').index(td);
var y = table.find('tr').index(tr);
return [x, y];
}
function select(table, x, y) {
var tr = table.find('tr').eq(y);
var td = tr.find('td').eq(x);
return td;
}
for (var x = 0; x < N; x++) {
var tr = $('<tr>');
for (var y = 0; y < N; y++) {
var td = $('<td>');
td.click(function() {
var td = $(this);
var p = position($(this));
var x = p[0];
var y = p[1];
if (x + 1 >= N || y + 1 >= N) {
return;
}
var td1 = select($('table'), x + 1, y);
var td2 = select($('table'), x, y + 1);
if (td.text() == '●' && td1.text() != '●' && td2.text() != '●') {
td.text('');
td1.text('●');
td2.text('●');
}
});
td.mouseenter(function() {
$(this).css('border-color', 'yellow');
});
td.mouseleave(function() {
$(this).css('border-color', 'gray');
});
tr.append(td);
}
$('table').append(tr);
}
select($('table'), 0, 0).text('●');
select($('table'), 0, 0).css('background-color', 'white');
select($('table'), 0, 1).css('background-color', 'white');
select($('table'), 0, 2).css('background-color', 'white');
select($('table'), 1, 0).css('background-color', 'white');
select($('table'), 1, 1).css('background-color', 'white');
select($('table'), 2, 0).css('background-color', 'white');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment