输出棋盘的所有白色或黑色方块


29

介绍

这就是棋盘的样子。

enter image description here

您可以看到这a1是一个黑色的正方形。但是,b1浅色正方形

任务

面临的挑战是,给定的darklight或者both,输出所有的所有正方形 的隔膜(如空白或换行)。所有正方形的顺序无关紧要

测试用例

Input: dark
Output: a1 a3 a5 a7 b2 b4 b6 b8 
        c1 c3 c5 c7 d2 d4 d6 d8 
        e1 e3 e5 e7 f2 f4 f6 f8 
        g1 g3 g5 g7 h2 h4 h6 h8

Input: light
Output: a2 a4 a6 a8 b1 b3 b5 b7 
        c2 c4 c6 c8 d1 d3 d5 d7 
        e2 e4 e6 e8 f1 f3 f5 f7 
        g2 g4 g6 g8 h1 h3 h5 h7

Input: both
Output: a1 a2 a3 a4 a5 a6 a7 a8
        b1 b2 b3 b4 b5 b6 b7 b8
        c1 c2 c3 c4 c5 c6 c7 c8
        d1 d2 d3 d4 d5 d6 d7 d8
        e1 e2 e3 e4 e5 e6 e7 e8
        f1 f2 f3 f4 f5 f6 f7 f8
        g1 g2 g3 g4 g5 g6 g7 g8
        h1 h2 h3 h4 h5 h6 h7 h8

注意:我已经美化了输出,但这不是必需的

这是,因此以最少的字节提交为准!


那么,类似的事情a2a4a6...会好吗?
科纳·奥布莱恩

@CᴏɴᴏʀO'Bʀɪᴇɴ它确实必须包含分隔符,例如空格或换行符,因此无效。
阿德南

我们可以输出原始的二维矩阵吗?即[[a2,a4,a6,a8],[...]...]
康纳尔奥布莱恩

@CᴏɴᴏʀO'Bʀɪᴇɴ是的,那是允许的
Adnan

lightdark并且both必须输入作为StringS或可以经由它们的任何数据类型来表示?
WKS

Answers:


15

Pyth,22 21字节

-1字节@ Sp3000

fn%Chz3%sCMT2sM*<G8S8

下的功能%Chz3dark散列到1,light0,和both为2。如果我们取一个棋正方形的ORDS的总和(即,奇偶校验a1- > [97, 33]- > (97 + 33)%2= 0,暗方形去0,和光1这使我们可以按不等式进行过滤。

fn%Chz3%sCMT2sM*<G8S8      implicit: z=input
               *           Cartesian product of
                <G8          first 8 letters in G (alphabet)
                   S8        with [1,...,8] implicitly stringified
             sM*<G8S8      ['a1','a2,...,'a8','b1'...'h8']
f          T               Filter that by gives truthy result to lambda T:
        sCMT                   The sum of the ords of the chars in T,
       %    2                  modulo 2
 n                            does not equal
   Chz                          ord of the first char in z,
  %   3                         modulo 3
                            Implicitly print the list.

在这里尝试。


21: fn%Chz3%sCMT2sM*<G8S8
Sp3000 '16

@ Sp3000谢谢!知道我使用6个字节来使其适应时,我应该尝试使用不同的哈希值。
lirtosiast

13

Bash + GNU实用工具,74

printf %s\\n {a..h}{1..9}|sed -n "`sed '/[db]/a1~2p
/t/a2~2p
c/9/d'<<<$1`"

{a..h}{1..9} 是bash括号扩展,可生成8x8电路板的所有坐标,外加一列 9。这很重要,因为它会使行长变得奇数,从而使棋盘效果更明显。

printf简单格式的每个坐标,每行一个。

然后x9,根据脚本输入,构建的sed表达式将删除所有坐标,然后打印偶数或奇数或两行输入。


11

JavaScript(SpiderMonkey 30+),90 85 83 82字节

x=>[for(d of"12345678")for(c of"abcdefgh")if(x>'l'^parseInt(c+=d,19)%2|x<'d')c]+''

返回以逗号分隔的正方形字符串。兼容版本为99字节:

x=>([..."12345678"].map(d=>[..."abcdefgh"].map(c=>c+d).filter(s=>x>'l'^parseInt(s,19)%2|x<'d')))+''

通过枚举所有64个平方名称,然后在基数19中解析它们,以查看它们是模2的亮还是暗,来工作。


好。这是ES7
edc65 '16

@ edc65啊,我不记得了。我认为我的第二个版本是“仅” ES6。
尼尔

现在,ES6击败ES7
edc65 '16

@ edc65你在说什么?
尼尔

4
@ edc65我不认为我们可以同意抽签吗?
尼尔

10

JavaScript(ES6),82 87 98

匿名函数返回空格分隔的正方形字符串。

i=>eval("for(o='',v=190;v<322;)v++%19<8&&i<'d'|v&1^i>'l'?o+=v.toString(19)+' ':o")

测试

f=i=>eval("for(o='',v=190;v<322;)v++%19<8&&i<'d'|v&1^i>'l'?o+=v.toString(19)+' ':o")

// less golfed

q=i=>{
  // loop over the range of number a0 (base 19) to h8 (base 19)
  for(o='',v=190;v<322;) 
  {
    if (v++ %19 < 8) // increment and execute the line below only if second digit in 1..8
      if (i<'d'|v&1^i>'l') // even == light, odd == dark, take both if input is 'both'
        o+=v.toString(19)+' '
  }
  return o
}

document.write('<hr>Both<br>'+f('both'))
document.write('<hr>Light<br>'+f('light'))
document.write('<hr>Dark<br>'+f('dark'))


1
哇...太疯狂了!我想知道ES6是否有可能变得更短……
ETHproductions 2016年

@ETHproductions是的!我已经准备好使用86,但是我仍在尝试做得更好(我-移动-目标是尼尔,他85岁,没有该死的83岁)
edc65

7

批次,192个字节

@set s=a1 a3 a5 a7
@set t=b2 b4 b6 b8
@if not %1==light call:b
@set s=a2 a4 a6 a8
@set t=b1 b3 b5 b7
@if %1==dark exit/b
:b
@echo %s% %s:a=c% %s:a=e% %s:a=g% %t% %t:b=d% %t:b=f% %t:b=h%

4

Pyth,48个 39字节

K*<G8S8Jfq%xGhT2%seT2K?qhz\bK?qhz\lJ-KJ

在这里尝试!

仍然比其他Pyth解决方案更长,但我认为我无法用我的算法击败它。

说明

首先,我们生成板上所有正方形的列表,并将其分配给Y。然后,我们过滤此列表,以便仅保留浅色正方形,并将此列表分配给J。之后,我们评估输入并打印:

  • Y 如果输入是 both
  • J 如果输入是 light
  • Y-J 如果输入是 dark

确定正方形是否为浅色的工作方式如下:

  • 将char映射到1-8之间的数字(a-> 1,b-> 2),得到18for a8,等等。
  • 检查这两个数字是否都是奇数或偶数(x%2 == y%2
  • 如果是,则正方形为浅色,否则为深色

K*<G8S8Jfq%xGhT2%seT2K?qhz\bK?qhz\lJ-KJ  # z=input

 *                                         # Cartesian product of
  <G8                                      # first 8 letters of the alphabet (a-h)
     S8                                    # 1-indexed range (1-8)
K                                          # K holds now all squares
       f             K                     # Filter K 
        q                                  # is equal
         %xGhT2                            # map [a-h] to a number [1-8] and take it modulo 2
               %seT2                       # Take modulo 2 from the row number
                      ?qhz\bK              # If input starts with 'b' print K
                             ?qhz\lJ       # If it starts with 'l' print J
                                    -KJ    # Otherwise print the difference of those 2

哦,天啊那是由一个长镜头比我短。
Addison Crump

4

Python 2,73 71 70字节

lambda s:[chr(x/8+97)+`x%8+1`for x in range(64)if x+x/8&1^ord(s[0])%3]

由于挑战提到了“分隔符”,我仍然对函数是否适合这个问题感到有些困惑,但是由于有很多其他函数提交,我也做了同样的事情。

Erwan的答案相似,但有很多位更Python 2里的烦躁。

(-2个字节感谢@xnor)


大声笑我什至没有测试之间s=="dark"s[0]=="d"但为了我的防守,我真正的第一次尝试是使用s,*_=s4cmp
Erwan

1
我觉得应该像ord(s[_])&_或短一些ord(s[_])/_
xnor

@xnor确实,有%:)谢谢!
Sp3000 '16

4

PHP,132个 126 120 108 106字节

for($s=strtr($argv[1],bdl,210);$c<8;$c++)for($r=0;$r<8;)if((++$r+$c)%2==$s||$s>1)echo"abcdefgh"[$c]."$r ";

它遍历列(0-7)和行(1-8),并检查两者的总和是否为奇/偶。

使用PHP 5.6.4测试,运行它: php -d error_reporting=30709 -r '<CODE>' {dark|light|both}


1
欢迎来到PPCG!这是一个很好的答案,但是如果您添加说明,将会获得更多投票。
lirtosiast

我认为您可以替换$s==2$s-1。如果$ s = 2,并且为-1,则为1,这是真实的,并且将持续下去
Martijn

而且我认为$c=0可以$c,它会发出很多通知,但至少在黑暗时效果还不错
Martijn 2016年

谢谢,马丁!我也忘记了删除括号,现在为-6个字节。而且我不知道为什么,但是$s-1不起作用,但是应该。感谢这个好主意!我稍后再调试。
killerbees16年

我是这个网站的新手,但是由于未定义$c变量而导致的错误消息?这听起来有些奇怪且无效。或不?
killerbees16 '16

3

Vitsy90 82字节

'`'8\[1+8\:]Yy1-\?8\['1'v8\[vD1+vr?]vX]i'h'-)[88*\[Z?aO]]i'r'-)[?1m]1m
84*\[Z??aO]

第一行的说明:

'`'8\[1+8\:]Yy1-\?8\['1'v8\[vD1+vr?]vX]i'h'-)[88*\[Z?aO]]i'r'-)[?1m]i'g'-)[1m]
'`'                     Push ` to the stack. (this is 1 less than a in ASCII)
   8\[     ]            Do the stuff in brackets 8 times.
      1+                Add one on every recursion (this gets a, b, c, d...)
        8\:             Clone the stack 8 times. (This gets 8 of each a, b, c...)
Y                       Remove the current stack.
 y1-\?                  Go one stack to the left (I really need to builtin this)
8\[                 ]   Do the stuff in brackets 8 times.
   '1'                  Push character literal 1 to the stack.
      v                 Save it as a temporary variable.
       8\[       ]      Do the stuff in brackets 8 times.
          v             Push the temporary variable to the stack.
           D            Duplicate the top item of the stack.
            1+          Add one to it (this gives us 1, 2, 3, 4...)
              v         Capture the top item of the stack as a temporary variable.
               r        Reverse the stack.
                ?       Go a stack to the right.
                  vX    Clear the temporary variable slot.
i'h')[          ]       If the last character of the input is 'h', do the stuff in brackets
      88*\[    ]        Do the stuff in brackets 64 times.
           Z            Output everything in the stack as a character.
            ?           Rotate right a stack.
             aO         Output a newline.
i'r')[?1m]              If the penultimate character of the input is 'r', rotate over a 
                        stack, then execute the first index of lines of code.
1m                      Execute the first index of lines of code.

第二行的说明:

84*\[Z??aO]
84*\[     ]   Do the stuff in brackets 32 times.
     Z        Output everything in the stack as a char.
      ??      Rotate two stacks over.
        aO    Output a newline.

“ dark”和“ both”都有尾随换行符。要求仅输入“暗”,“两者”或“亮”。

在线尝试!


3

PowerShell的V3 +,142个 129字节

param($a)$d=$a[0]-in('d','b');$l=$a[0]-in('l','b')
97..104|%{$i=[char]$_;1..8|%{if((($q=($_+$i)%2)-eq$l)-or($q+1-eq$d)){"$i$_"}}}

接受输入$a并为要基于输入的第一个字母输出方格$d$l方格设置两个变量。

然后,我们遍历a-h1-8并使用与确定棋盘正方形的颜色相同的技巧来分析是浅色正方形还是深色正方形(设置辅助变量$q在第一个测试中),并在适当时将该正方形添加到管道中。执行后,流水线上的元素每行输出一个。

需要v3或更高版本的-in运营商。

编辑-通过消除switch和更改相等性测试顺序来节省13个字节


3

Jolf,48个字节

Ζ-ώ~1tΜ fΜZAQ8ΨΖ+ζ|<%ζγwώt8ώ6d|<i'd!x%H2>i'ldbHγ

对我来说,这一切都是希腊的。

Ζ-ώ~1t
Ζ        set ζ to 
  ώ~1     100 * 2
 -   t    minus 10 (=190)

ΜZAQ8ΨΖ+ζ|<%ζγwώt8+2t
 ZAQ8                 A zero array of length Q8 (8*8 = 64)
Μ    Ψ                map that
      Ζ+ζ             ζ += 
           %ζγwώt       ζ % (γ = 19)
          <      8      < 8
         |        ώ6  || 12

Μ f■above thing■d|<i'd!x%H2>i'ldbHγ
 _f■above thing■d                    filter the above thing
                 |<i'd!x%H2>i'l      removing all the bad stuff (i<'d'|v%2^i>'l')
Μ                              dbHγ  map each character to base 19

3

Perl,69 + 3 = 72字节

$b=/b/;$i=/l/;$_="@{[grep{$i=!$i||$b}map{$l=$_;map{$l.$_}1..8}a..h]}"

要与一起运行perl -p,为此我添加了3个字节。

高尔夫版本较少(略有不同,因为babycart运算符很难很好地格式化):

$b=/b/;                       # flag for input containing b
$i=/l/;                       # start $i as true if input contains 'l'

@a = grep {
    $i = !$i||$b                # alternate unless $b is true
} map {
    $l = $_;                    # save letter
    map {
        $l.$_                   # join letter and number
    } 1..8                      # generate number sequence
} a..h;                         # generate letter sequence

# golfed version uses babycart operator around array expr to save one byte
$_ = "@a"                       # write array, separated

高尔夫球版本使用"@{[]}"; 使用注释版本,@a=...; "@"以便注释代码仍可运行。


map$l.$_,1..8-1
choroba

和grep相同的技巧:grep$i=!$i||$b,map再次-1
choroba

3

C ++,132字节

通过命令行进行输入。使用指针/模数巫毒符作为打印条件。

#include<stdio.h>
int main(int i,char**v){for(int n=0;n<64;n++)if((n+(i=n/8))%2-*v[1]%3){putchar(i+97);putchar(n%8+49);putchar(32);}}

我认为n-loop不是必需的。我觉得嵌套的for循环ij将修整几个字节关闭。这种(i+j)%2方法真的很聪明。我没想到。
WKS

我只是注意到这(i//8+i%8)%2是一样的,(i//8+i)%2因此,如果您删除j=n%8
Erwan

3

爪哇143

class H{public static void main(String[]a){for(char
c=96;++c<'i';)for(int
i=0;++i<9;)if((i+c)%2!=a[0].charAt(0)%3)System.out.println(c+""+i);}}

嘿,这不是最长的答案:)

输入被当作命令行参数。


3

PHP,99 82 79 76 74 73字节

使用ISO 8859-1编码。

for($z=$argv[1];++$x<72;)$x%9&&$z<c|$z>k^$x&1&&print~ß.chr($x/9+97).$x%9;

像这样运行(-d仅出于美观目的而添加):

php -d error_reporting=30709 -r 'for($z=$argv[1];++$x<72;)$x%9&&$z<c|$z>k^$x&1&&print~ß.chr($x/9+97).$x%9; echo"\n";' dark

它的工作原理是:变量$x从1递增到71,数字对应于如下所示的单元格。

r\c 1  2  3  4  5  6  7  8  [invalid column]
A   1  2  3  4  5  6  7  8  9
B  10 11 12 13 14 15 16 17 18
C  19 20 21 22 23 24 25 26 27
D  28 29 30 31 32 33 34 35 36
E  37 38 39 40 41 42 43 44 45
F  46 47 48 49 50 51 52 53 54
G  55 56 57 58 59 60 61 62 63
H  64 65 66 67 68 69 70 71 72

因此,$x modulo 9产生列号并$x / 9产生行号,我使用将其转换为字母chr。该代码$z<c|$z>k^$x&1的产量true为输入both$z<c)和在的情况下lightdark分别只对偶数或奇数细胞($z>k ^ $x&1)。该表达式的结果确定是否将打印单元格坐标。最后,如果$x modulo 9结果为0,则跳过该不存在的单元格。

  • 通过只有1个循环,将数字转换为char而不是相反的方式,节省了18 17个字节(已修复错误)
  • 通过将暗和亮条件与 xor
  • 通过与完整输入(而不是第一个字符)进行比较节省了3个字节
  • Saved 2 bytes because no longer need to subtract .125 in the expression $x/9+69.9 to get the correct row number before converting to a char
  • Saved a byte by using to yield a space

2

JavaScript ES6, 187 160 159 bytes

I'm probably missing something painfully obvious. Oh well. Not having to flatten the array helps.

l=s=>(E=[2,4,6,8],O=[1,3,5,7],h=(z=s[0]=="d")?O:E,d=z?E:O,[...h.map(t=>[..."aceg"].map(e=>e+t)),...(d.map(t=>[..."bdfh"].map(e=>e+t))),...(s[0]=="b"?l`d`:[])])

Returns a 2D array.


Try it here:


2

Ruby, 85

I think there are shorter ways about this, but this is a cute use of .upto.

gets;'a1'.upto('h8'){|e|puts e if e[/[1-8]/]&&(~/b/||((e.ord%2!=e[1].ord%2)^! ~/l/))}

2

R, 129 94 bytes

I knew I could generate the board better :). Essentially this builds an inverted board, filtering out grid references where the shade does not match the input. Output is space separated.

a=which(array(c('light','dark'),c(9,9))[-9,-9]!=scan(,''),T);cat(paste0(letters[a[,1]],a[,2]))

Ungolfed

a=which(                           # Get the indexes of
  array(c('light','dark'),c(9,9))  # an array of light dark
    [-9,-9]                        # except for the ninth row and column
      !=scan(,'')                  # where the value doesn't equal the input
    ,T                             # return array index not vector
  );
cat(paste0(letters[a[,1]],a[,2]))  # using letters for col

Test

> a=which(array(c('light','dark'),c(9,9))[-9,-9]!=scan(,''),T);cat(paste0(letters[a[,1]],a[,2]))
1: dark
2: 
Read 1 item
a1 c1 e1 g1 b2 d2 f2 h2 a3 c3 e3 g3 b4 d4 f4 h4 a5 c5 e5 g5 b6 d6 f6 h6 a7 c7 e7 g7 b8 d8 f8 h8
> a=which(array(c('light','dark'),c(9,9))[-9,-9]!=scan(,''),T);cat(paste0(letters[a[,1]],a[,2]))
1: light
2: 
Read 1 item
b1 d1 f1 h1 a2 c2 e2 g2 b3 d3 f3 h3 a4 c4 e4 g4 b5 d5 f5 h5 a6 c6 e6 g6 b7 d7 f7 h7 a8 c8 e8 g8
> a=which(array(c('light','dark'),c(9,9))[-9,-9]!=scan(,''),T);cat(paste0(letters[a[,1]],a[,2]))
1: both
2: 
Read 1 item
a1 b1 c1 d1 e1 f1 g1 h1 a2 b2 c2 d2 e2 f2 g2 h2 a3 b3 c3 d3 e3 f3 g3 h3 a4 b4 c4 d4 e4 f4 g4 h4 a5 b5 c5 d5 e5 f5 g5 h5 a6 b6 c6 d6 e6 f6 g6 h6 a7 b7 c7 d7 e7 f7 g7 h7 a8 b8 c8 d8 e8 f8 g8 h8
>

2

Oracle SQL 11.2, 192 180 bytes

SELECT CHR(64+x),DECODE(y,0,8,y)FROM(SELECT CEIL(LEVEL/8)x,MOD(LEVEL,8)y FROM DUAL CONNECT BY LEVEL<=64)WHERE(:1='dark'AND MOD(x+y,2)=0)OR(:1='light'AND MOD(x+y,2)=1)OR(:1='both');

Un-golfed

WITH v AS
(
  SELECT CEIL(LEVEL/8)x, DECODE(MOD(LEVEL,8),0,8,MOD(LEVEL,8))y  
  FROM DUAL CONNECT BY LEVEL<=64
)
SELECT CHR(64+x),y
FROM   v
WHERE  (:1='dark' AND MOD(x+y,2)=0)OR(:1='light' AND MOD(x+y,2)=1)OR(:1='both');

The v view generate the coordinates of each square. If the sum of the coordinates is even then the square is black, else it's white.


2

Rust, 263 259 244 Bytes

use std::char;use std::env;fn main(){let n=env::args().nth(1).unwrap();for i in 0..8{for j in 0..8{if n=="both"||(n=="dark"&&(i+j)%2==0)||(n== "light"&&(i+j)%2!=0){println!("{}{}",char::from_u32(i+97).unwrap(),char::from_u32(j+49).unwrap())}}}}

Expanded Form:

fn main() {
    let input = env::args().nth(1).unwrap();
    for i in 0..8{
            for j in 0..8{
                if input == "both"
                || (input == "dark" && (i+j)%2==0)
                || (input == "light" && (i+j)%2!=0){
                    println!("{}{}",char::from_u32(i+97).unwrap(),char::from_u32(j+49).unwrap());
            }
        }
    }
}

1
Rather than hard-coding your input, is it not possible to read it from the terminal or the command line or as a function parameter?
Neil

2

MATL, 31 bytes

1)t3\8:t!++w4\~?H\]2#f2Y2!w)wVh

Try it online!


This one doesn't seem to give the correct squares. "dark" is giving x1,x3,x5,x7 for every letter x, but that corresponds to 4 columns, not the black squares.
Esteemator

@Esteemator Sorry, my mistake. Corrected
Luis Mendo

2

CJam, 29

qci3%:X;8Ym*{~+2%X-},"a1 "f.+

Just a quick and dirty solution :p
Try it online

Explanation:

q           read the input
ci          convert to (first) character then to integer
3%          modulo 3; results for d(ark), l(ight) and b(oth) are 1, 0, 2
:X;         store in X and pop
8Ym*        generate all pairs (Y=2) of numbers from 0 to 7
{…},        filter using the condition block
  ~         dump the current pair on the stack
  +2%       calculate the sum modulo 2
  X-        subtract X; if the result is not 0, the pair is kept
"a1 "f.+    vectorized-add "a1 " to each remaining pair
             this means the character 'a' is added to the first number,
             the character '1' is added to the second number,
             and then the space character is appended
            the contents of the stack are automatically printed at the end

2

Haskell, 133 116 105 100 98 91 bytes

f r=[["abcdefgh"!!x,"12345678"!!y]|x<-l,y<-l,odd(x+y)||r<"l",even(x+y)||r!!0/='d']
l=[0..7]

This is my first attempt at golfing Haskell.

With some help from Michael Klein, we managed to get it under 100 chars!


1
How about c>0 for c==1 and c<1 for c==0? Saves two bytes.
Michael Klein

Fantastic, we got it under 100! Thank you Michael.
joeytwiddle

1
You're welcome. I got a bit sucked in and got it down to 86 bytes by refactoring a bit: f r=[[[a,b]|a<-['a'..'h'],b<-['1'..'8']]!!i|i<-[0..63],even i||r<"l",odd i||r!!0/='d']
Michael Klein

1
That's very nice, a rethought approach. Although I'm sorry to say that odd and even i do not give us diagonal stripes. Some solve this with i+i`div`8 (like x+y). Others start with ['1'..'9'] and [0..71] and then retain only the i`mod`9<8 results later, for 96 bytes. However, this hybrid of our two approaches does well at 91 bytes: l=[0..7];f r=[["abcdefgh"!!x,"12345678"!!y]|x<-l,y<-l,odd(x+y)||r<"l",even(x+y)||r!!0/='d']
joeytwiddle

Ah, well that's still a good bit better
Michael Klein

1

Mathematica 133 bytes

Method 1: 108 bytes. This constructs the board as a table, with labels in each cell, and returns light or dark diagonals or bands as required.

Table[Table[{i,j},{i,{h,g,f,e,d,c,b,a}},{j,Range@8}]~Diagonal~k,{k,If[#=="light",-6,-7],7,If[#=="both",1,2]}]&

%["light"]   (*where % repeats the preceding line *)

{{{b, 1}, {a, 2}}, {{d, 1}, {c, 2}, {b, 3}, {a, 4}}, {{f, 1}, {e, 2}, {d, 3}, {c, 4}, {b, 5}, {a, 6}}, {{h, 1}, {g, 2}, {f, 3}, {e, 4}, {d, 5}, {c, 6}, {b, 7}, {a, 8}}, {{h, 3}, {g, 4}, {f, 5}, {e, 6}, {d, 7}, {c, 8}}, {{h, 5}, {g, 6}, {f, 7}, {e, 8}}, {{h, 7}, {g, 8}}}


Method 2: 133 bytes. Creates an array and selects according to the even-odd nature of the sum of the row number + column number of each cell.

Position[Array[Boole@OddQ[#+#2] &,{8,8}],Switch[#,"dark",0,"light",1,"both",0|1]]/.
{j_,k_}:>{j/.Thread[Range@8->{a,b,c,d,e,f,g,h}],k}&


1

JS, 197 bytes

b=[];d=[];l=[];for(i=1;i<9;i++){for(j=1;j<9;j++){a=String.fromCharCode(96+i*1)+j;b.push(a);if((i+j)%2<1){d.push(a)}else{l.push(a)}}}m=[0,"both",b,"dark",d,"light",l];alert(m[m.indexOf(prompt())+1])

1

Python (3.5), 106 100 96 92 bytes

use the trick of MegaTom (i+j)%2 to win 6 bytes

f=lambda s:[chr(97+i//8)+str(1+i%8)for i in range(64)if s[0]=='b'or(i//8+i)%2==(s[0]=='l')]

Try it on repl.it

Results

>>> f('light')
['a2', 'a4', 'a6', 'a8', 'b1', 'b3', 'b5', 'b7', 'c2', 'c4', 'c6', 'c8', 'd1', 'd3', 'd5', 'd7', 'e2', 'e4', 'e6', 'e8', 'f1', 'f3', 'f5', 'f7', 'g2', 'g4', 'g6', 'g8', 'h1', 'h3', 'h5', 'h7']
>>> f('dark')
['a1', 'a3', 'a5', 'a7', 'b2', 'b4', 'b6', 'b8', 'c1', 'c3', 'c5', 'c7', 'd2', 'd4', 'd6', 'd8', 'e1', 'e3', 'e5', 'e7', 'f2', 'f4', 'f6', 'f8', 'g1', 'g3', 'g5', 'g7', 'h2', 'h4', 'h6', 'h8']
>>> f('both')
['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8']

Previous version

f=lambda s:[i for i in[i+j for i in'abcdefgh'for j in'123456780'][s[0]=='l'::2-(s[0]=='b')]if'0'not in i]

1

C++, 119 Bytes

Based on MegaTom's trick.

#include <stdio.h>
int main(int n,char**v){for(n=0;n<64;++n){if((n+n/8)%2-**(v+1)%3){printf("%c%c ",n/8+97,n%8+49);}}}

0

C (gcc), 112 bytes

f(char*s){for(int m=*s^'d'?*s^'l'?3:2:1,l=64,x;l--;m&1&!x|(m&2&&x)&&printf("%c%d ",l%8+97,l/8+1))x=l%8%2^l/8%2;}

Try it online!

If a == 1, then a square will always be black if the "oddness" of row and column is the same, i.e. both are odd or both are even. The opposite is true for white squares, where row and column will always differ in oddness.

After that, it's just a matter of combining row and column loops, as well as consulting a table of operator precedence until a sufficient level of incomprehensibility has been reached.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.