Skip to content

Instantly share code, notes, and snippets.

@hanachin
Created June 6, 2010 15:45
Show Gist options
  • Save hanachin/427665 to your computer and use it in GitHub Desktop.
Save hanachin/427665 to your computer and use it in GitHub Desktop.
// 9x9, 奇数に使えるパターン 55 byte, 53 chars
for(i=81;i--;document.write("■□"[i&1],i%9?"":"<br>"));
// 10x10, 偶数に使えるパターン 54 byte, 52 chars
for(i=110;i--;document.write(i%11?"□■"[i&1]:"<br>"));
var N = 10;
var pat = "■□■";
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
document.write(pat[(j & 1) + (i & 1)]);
}
document.write("<br>");
}
var N = 10;
var pat = [["■","□"], ["□","■"]];
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
document.write(pat[i&1][j&1]);
}
document.write("<br />");
}
var N = 10;
var f, s = "■□";
for (var i = 0; i < N; ++i) {
f = 1 & i;
for (var j = 0; j < N; ++j) {
document.write(s[f]);
f ^= 1;
}
document.write("<br />");
}
var N = 10;
for (i = 0; i < N; i++) {
if (i & 1) {
document.write("□■□■□■□■□■<br />");
} else {
document.write("■□■□■□■□■□<br />");
}
}
var N = 10;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (i & 1) {
if (j & 1) {
document.write("■");
} else {
document.write("□");
}
} else {
if (j & 1) {
document.write("□");
} else {
document.write("■");
}
}
}
document.write("<br />");
}
const WHITE = 1, BLACK = 0;
function getColor(x, y) {
if (x & 1) {
if (y & 1) {
return BLACK;
} else {
return WHITE;
}
} else {
if (y & 1) {
return WHITE;
} else {
return BLACK;
}
}
}
var N = 10;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
var color = getColor(j, i);
if (WHITE == color) {
document.write("□");
} else if (BLACK == color){
document.write("■");
} else {
document.write("?");
}
}
document.write("<br>");
}
/* 以下ショートコーディング過程の失敗など */
//for(i=0;document.write(++i%11?"□■"[i&1]:"<br>"),i<109;);
//for(i=0;i<109;document.write(++i%11?"□■"[i&1]:"<br>"));
//for(i=0;i<109;document.write(++i%11?"□■"[i&1]:"<br>"));
//for(i=110;i--;document.write(i%11?"□■"[i&1]:"<br>"));
//for(j=i=100;i--;document.write("□■"[j^i&1]+(i%10?"":(j=!j,"<br>"))));
//for(i=81;i--;document.write("■□"[i&1]+(i%9?"":"<br>")));
//for(i=81;i--;document.write("■□"[i&1],i%9?"":"<br>"));
//for(i=110;i--;document.write(i%11?"□■"[i&1]:"<br>"));
//for(i=81;i--;document.write("■□"[i&1]+(i%9?"":"<br>")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment