Determine the color of a chess square

60

6

Your challenge is to write a program that outputs the color of a given square from the chessboard. This is how a chessboard looks:

enter image description here

You can see that the square a1 is dark, and h1 is a light square. Your program needs to output dark or light, when given a square. Some examples:

STDIN:  b1
STDOUT: light

STDIN:  g6
STDOUT: light

STDIN:  d4
STDOUT: dark

The rules:

  • You need to provide a full program that uses STDIN and uses STDOUT to output dark or light.
  • Assume that the input is always valid ([a-h][1-8])
  • This is , so shortest amount of bytes wins!

Scoreboard

var QUESTION_ID=63772,OVERRIDE_USER=8478;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

Adnan

Posted 2015-11-13T22:11:10.897

Reputation: 41 965

1Why hasn't anyone tried <>^Fish? – ghosts_in_the_code – 2015-11-14T16:34:37.143

Answers

47

GS2, 17 15 bytes

de♦dark•light♠5

The source code uses the CP437 encoding. Try it online!

Verification

$ xxd -r -ps <<< 6465046461726b076c696768740635 > chess.gs2
$ wc -c chess.gs2 
15 chess.gs2
$ gs2 chess.gs2 <<< b1
light

How it works

d               Add the code points of the input characters.
 e              Compute the sum's parity.
  ♦             Begin a string literal.
   dark
       •        String separator.
        light
             ♠  End the string literal; push as an array of strings.
              5 Select the element that corresponds to the parity.

Dennis

Posted 2015-11-13T22:11:10.897

Reputation: 196 637

8That's amazing! With 9 unavoidable bytes, 3 byte outgolfing Pyth and CJam is amazing. – isaacg – 2015-11-13T23:30:12.917

29Holy cow, guys, GS2 is the new Pyth! Somebody figure it out how to use it well before Denni...never mind. – ETHproductions – 2015-11-14T05:16:16.337

58

Python 2, 41 38 bytes

print'ldiagrhkt'[int(input(),35)%2::2]

3 bytes thanks to Mego for string interlacing

Takes input like "g6". That's light and dark intertwined.

isaacg

Posted 2015-11-13T22:11:10.897

Reputation: 39 268

That's just gorgeous with the string interlacing. – Wayne Werner – 2015-11-16T20:08:01.640

7I'd actually say that int(input(),35) is the brilliant part. I thought of the string interlacing, but your input method saves the most bytes. – mbomb007 – 2015-11-17T01:29:04.543

27

Hexagony, 34 32 bytes

,},";h;g;;d/;k;-'2{=%<i;\@;trl;a

Unfolded and with annotated execution paths:

enter image description here
Diagram generated with Timwi's amazing HexagonyColorer.

The purple path is the initial path which reads two characters, computes their difference and takes it modulo 2. The < then acts as a branch, where the dark grey path (result 1) prints dark and light grey path (result 0) prints light.

As for how I compute the difference and modulo, here is a diagram of the memory grid (with values taken for the input a1):

enter image description here
Diagram generated with Timwi's even more amazing Esoteric IDE (which has a visual debugger for Hexagony).

The memory pointer starts on the edge labelled row, where we read the character. } moves to the edge labelled col, where we read the digit. " moves to the edge labelled diff where - computes the difference of the two. ' moves to the unlabelled cell where we put the 2, and {= moves to the cell labelled mod where we compute the modulo with %.

This might be golfable by a few bytes by reusing some of the ;, but I doubt it can be golfed by much, certainly not down to side-length 3.

Martin Ender

Posted 2015-11-13T22:11:10.897

Reputation: 184 808

7Ooh, pretty colors! – Celeo – 2015-11-13T23:39:43.923

1This language is new to me but I am amazed at your ability to come up with something more contrived than I thought possible – qwr – 2015-11-14T00:53:25.487

18I really don't get all these golf languages. – juniorRubyist – 2015-11-14T06:35:01.963

4

@codeSwift4Life Hexagony is far from being a golfing language. For trivial tasks like this it might be reasonably competitive, because it has single-character commands, but that is more a necessity shared by many other 2D languages, including Befunge, Piet, ><>. Any nontrivial task will require very large amounts of code and complicated programs, due to Hexagony's weird memory model. It is in no way meant to be a concise language, but rather an exotic and weird one, exploring programming on hexagonal grids.

– Martin Ender – 2015-11-14T10:03:50.940

4@qwr I thought being contrived was the point of esolangs. ;) – Martin Ender – 2015-11-15T10:45:02.357

1Wow...I never bothered trying to figure out how the hexagonal memory model worked, but your example (paired with the diagram) just snapped into place in my brain. Wish there were somewhere I could +1 the language! – ETHproductions – 2015-11-17T15:52:22.400

@ETHproductions Well, there's this meta post and you can star it on GitHub if you want. :P

– Martin Ender – 2015-11-17T16:04:23.197

21

CJam, 18 bytes

r:-)"lightdark"5/=

Online demo

Dissection

r               e# Read a token of input
:-              e# Fold -, giving the difference between the two codepoints
)               e# Increment, changing the parity so that a1 is odd
"lightdark"5/   e# Split the string to get an array ["light" "dark"]
=               e# Index with wrapping, so even => "light" and odd => "dark"

Peter Taylor

Posted 2015-11-13T22:11:10.897

Reputation: 41 901

34your code is smiling :-) – Doorknob – 2015-11-13T22:23:39.660

8I did consider the equally effective :^) – Peter Taylor – 2015-11-14T07:29:43.567

2Please can you explain how this works. – Fogmeister – 2015-11-14T11:16:21.070

@Fogmeister, added explanation. – Peter Taylor – 2015-11-14T17:52:19.677

17

sed, 37

s/[1357aceg]//g
/^.$/{clight
q}
cdark

Explanation

s/[1357aceg]//g removes all odd-indexed coordinates. The resulting pattern buffer then has length of 1 for "light" or length of 0 or 2 for "dark". /^.$/ matches the 1-length patterns, changes the pattern to "light" and quits. Otherwise the pattern is changed to "dark".

Digital Trauma

Posted 2015-11-13T22:11:10.897

Reputation: 64 644

The q is redundant, and you can check for dark first instead with /../, https://tio.run/##K05N@f@/WD/a0NjUPDE5NT1WXz@dS19PTz85JbEomys5JzM9o@T//yRDrnQzrhQTAA

– user41805 – 2018-12-24T11:22:10.357

14

Pyth, 18 bytes

@c2"lightdark"iz35

Interpret the input as a base 35 number, chop lightdark in half, print.

isaacg

Posted 2015-11-13T22:11:10.897

Reputation: 39 268

13

Python 2, 45 bytes

print'dlairgkh t'[sum(map(ord,input()))%2::2]

Takes input like "a1". Try it online

Mego

Posted 2015-11-13T22:11:10.897

Reputation: 32 998

This wouldn't work in Python 3 due to the lack of parens for the print. – isaacg – 2015-11-13T22:29:35.233

Can't test right now but something like "ldiagrhgt"[expression::2] should work while saving a byte or two – FryAmTheEggman – 2015-11-13T22:47:20.017

13

ShadyAsFuck, 91 bytes / BrainFuck, 181 bytes

My first real BrainFuck program, thank Mego for the help and for pointing me to the algorithm archive. (That means I didn't really do it on my own, but copied some existing algorithms. Still an experience=)

NKnmWs3mzhe5aAh=heLLp5uR3WPPPPagPPPPsuYnRsuYgGWRzPPPPlMlk_PPPPPP4LS5uBYR2MkPPPPPPPP_MMMkLG]

This is of course the translation from my brainfuck answers:

,>,[<+>-]++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[-]++++++++++[>++++++++++<-]<[<+>>+<-]<[>+<-]+>>[>++++++++.---.--.+.++++++++++++.<<<->>[-]]<<[>>>.---.+++++++++++++++++.-------.<<<-]

Developed using this interpreter/debugger.

I stole two code snippets for divmod and if/else from here. (Thanks to @Mego!)

,>,               read input
[<+>-]            add
++<               set second cell to 2 

Now we have the cells config >sum 2 we now perform the divmod algorithm:

[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>
[-]>

The output of the divmod looks like this 0 d-n%d >n%d n/d but we zeroed the d-n%d and are zeroing the next cell too:

>[-]

Fill one cell up to the value 100 for easier outputting:

++++++++++[>++++++++++<-]< 

Now the configuration is >cond 0 100 and for applying the if/else algorithm we need two temp variables, so we choose the configuration temp0 >c temp1 100

c[<temp0+>>temp1+<c-]<temp0[>c+<temp0-]+
>>temp1[
 #>++++++++.---.--.+.++++++++++++.<         outputs light
 <<temp0-
>>temp1[-]]
<<temp0[
 #>>>.---.+++++++++++++++++.-------.<<<     outputs dark
temp0-]

flawr

Posted 2015-11-13T22:11:10.897

Reputation: 40 560

12

Seriously, 19 bytes

"dark""light"2,O+%I

Takes input like "a1"

Try it online (you will have to manually enter the input; the permalinks don't like quotes)

Mego

Posted 2015-11-13T22:11:10.897

Reputation: 32 998

2Online link ded.. – CalculatorFeline – 2016-04-02T21:57:57.513

10

JavaScript (ES6), 45 bytes

alert(parseInt(prompt(),35)%2?"dark":"light")

Downgoat

Posted 2015-11-13T22:11:10.897

Reputation: 27 116

way to go to use a radix! +1 FTW... – WallyWest – 2017-10-05T20:59:46.593

10

Turing Machine Code, 235 bytes

Using the rule table syntax defined here.

0 a _ r 1
0 c _ r 1
0 e _ r 1
0 g _ r 1
0 * _ r 2
1 2 _ r 3
1 4 _ r 3
1 6 _ r 3
1 8 _ r 3
2 1 _ r 3
2 3 _ r 3
2 5 _ r 3
2 7 _ r 3
* * _ r 4
3 _ l r A
A _ i r B
B _ g r C
C _ h r D
D _ t r halt
4 _ d r E
E _ a r F
F _ r r G
G _ k r halt

SuperJedi224

Posted 2015-11-13T22:11:10.897

Reputation: 11 342

1This is possibly the most amazing thing I have ever seen lol – Lucas – 2015-11-29T23:09:37.060

9

Befunge-93, 39 37 33 31 bytes

All credit to Linus who suggested this 31-byte solution:

<>:#,_@  v%2-~~
"^"light"_"krad

Test it using this interpreter.

Explanation

<        v%2-~~

The < at the beginning sends the instruction pointer to the left, where it wraps around to the right. It then reads in two characters from input as ASCII, subtracts them, and does a modulo by 2. As a and 1 are both odd (in terms of ASCII code), this works. The v redirects the instruction pointer downward...

"^"light"_"krad

...onto the _, which sends the instruction pointer to the left if the top of stack is 0 and to the right otherwise. The characters of "light" or "dark", respectively, are pushed onto the stack in reverse order. Both paths hit the ^ at the left, which sends the instruction pointer upward...

 >:#,_@

...to the output segment. : duplicates the top of stack, # jumps over the , and onto the _, which sends the instruction pointer to the right if the top of stack is 0 and left otherwise. When the stack is empty, the top of stack (after :) is 0, so the instruction pointer hits the @ which stops execution. Otherwise, it hits the ,, which outputs the top of stack as a character, and then the # jumps it over the : and onto the >, which starts the process again.

El'endia Starman

Posted 2015-11-13T22:11:10.897

Reputation: 14 504

save a byte using rad"v>"k without a space? – Linus – 2015-11-15T02:43:22.483

@Linus: "The space is necessary because otherwise the output would be dar k." Try it in the linked online interpreter. – El'endia Starman – 2015-11-15T02:49:17.053

1Your right. Anyway, I was going to do this in befunge but I can only get 2 bytes under you... <>:#,_@ v%2-~~\n"^"light"_"krad, fix the newline. – Linus – 2015-11-15T03:29:15.213

@Linus: That's brilliant. Thanks! – El'endia Starman – 2015-11-15T03:38:18.393

@JamesHolderness, No hard feelings. You're right to point out this doesn't work in the original Befunge-93 interpreter, the actual spec is for an 80x25 torus. You might want to post your version as it's own answer and explain the difference. I think at least that would be more practical than debating year-old hobby code with me.

– Linus – 2017-02-13T19:12:30.180

9

TI-BASIC, 66 bytes

Tested on a TI-84+ calculator.

Input Str1
"light
If inString("bdfh",sub(Str1,1,1)) xor fPart(.5expr(sub(Str1,2,1
"dark
Ans

Here's a more interesting variation on the third line, which sadly is exactly the same size:

Input Str1
"dark
If variance(not(seq(inString("bdfh2468",sub(Str1,X,1)),X,1,2
"light
Ans

You'd think TI-BASIC would be decent at this challenge, since it involves modulo 2. It's not; these solutions seem to be the shortest possible.

We spend a lot of bytes to get both characters in the string, but what really costs is the thirteen two-byte lowercase letters.

lirtosiast

Posted 2015-11-13T22:11:10.897

Reputation: 20 331

8

Java, 157 127 124 bytes

interface L{static void main(String[]a){System.out.print(new java.util.Scanner(System.in).nextInt(35)%2>0?"dark":"light");}}

SuperJedi224

Posted 2015-11-13T22:11:10.897

Reputation: 11 342

You could use an interface like this : interface i{static void main since the everything in an interface is public by default – Yassin Hajaj – 2015-12-04T10:49:17.673

8

Japt, 23 22 bytes

Japt is a shortened version of JavaScript. Interpreter

Un19 %2?"dark":"light"

How it works

          // Implicit: U = input string
Un19      // Convert U from a base 19 number to decimal.
%2        // Take its modulo by 2.
?"dark"   // If this is 1, return "dark".
:"light"  // Else, return "light".
          // Implicit: output last expression

Using the new version 0.1.3 (released Nov 22), this becomes 17 bytes, shorter than all but GS2:

Un19 %2?`»rk:¦ght

Or, alternatively, a magic formula: (26 bytes)

Un19 %2*22189769+437108 sH
Un19 %2                    // Convert input to base 19 and modulo by 2.
       *22189769+437108    // Where the magic happens (top secret)
                        sH // Convert to a base 32 string.

ETHproductions

Posted 2015-11-13T22:11:10.897

Reputation: 47 880

7

C, 55 bytes

s;main(){puts(strtol(gets(&s),0,19)&1?"light":"dark");}

Try it online

Thanks DigitalTrauma for lots of golfing tips

Mego

Posted 2015-11-13T22:11:10.897

Reputation: 32 998

I think you have an extra ( after puts – Level River St – 2015-11-13T23:41:55.633

This for 55: s;main(){puts(strtol(gets(&s),0,19)&1?"light":"dark");}. Assumes that the integer width is big enough to hold 3 chars of string. You should also be able to do main(s){puts(strtol(gets(&s),0,19)&1?"light":"dark");} for 54, though for some reason gets() is returning garbage is s if not global, so it segfaults. – Digital Trauma – 2015-11-14T02:32:00.933

oh wow, base-19. clever. – fluffy – 2015-11-15T07:41:40.310

7

TeaScript, 23 bytes

®x,35)%2?"dark":"light"

Unfortunately the strings dark and light can't be compressed.

Downgoat

Posted 2015-11-13T22:11:10.897

Reputation: 27 116

Hehe, Japt is shorter for once ;) +1 though, the JS compression techniques are great! I may add them into Japt after revamping the interpreter.

– ETHproductions – 2015-11-13T23:57:20.563

7

BotEngine, 165 14x11=154

v acegbdfh
>ISSSSSSSS
 v<<<<>v<<P
vS1   vS2ke
vS3   vS4re
vS5   vS6ae
vS7   vS8de
>     >   ^
>     >  v
^S2   ^S1el
^S4   ^S3ei
^S6  P^S5eg
^S8 te^S7eh
     ^   <

Here it is with the different path segments highlighted:

enter image description here

(Any non-space characters not highlighted serve as arguments for the e and S instructions- each of these instructions uses the symbol to the left (relative to the bot's direction of travel) as its argument)

SuperJedi224

Posted 2015-11-13T22:11:10.897

Reputation: 11 342

7

Ruby, striked out 44 36 bytes

puts %w[light dark][gets.to_i(19)%2]

daniero

Posted 2015-11-13T22:11:10.897

Reputation: 17 193

You can save a byte by replacing puts with $><< (no space). – Lynn – 2015-11-15T15:48:43.717

@Mauris I know, but i like my terminating newline – daniero – 2015-11-18T10:00:34.517

You can save 3 bytes by changing puts for p – Cyoce – 2016-04-02T21:13:16.047

7

C, 49 bytes

main(c){gets(&c);puts(c+c/256&1?"light":"dark");}

xsot

Posted 2015-11-13T22:11:10.897

Reputation: 5 069

No, that doesn't compile. – xsot – 2015-11-16T01:45:47.830

Oh, my bad, I had fiddled with something else. The output is wrong, though. I think you meant to do gets(&c)%256+c/256?

– Lynn – 2015-11-16T01:51:07.900

Oh, good catch. Though at this point, my solution is strictly worse than yours as we're using the same technique. Looks like I have plenty to learn. – xsot – 2015-11-16T01:59:41.273

It turns out that the wrong output was caused by the return value of gets(&c). I have updated my submission accordingly. – xsot – 2015-11-16T02:16:13.547

7

, 26 chars / 34 bytes

ô(שǀ(ï,ḣ)%2?`dark`:`light”

Try it here (Firefox only).

Mama Fun Roll

Posted 2015-11-13T22:11:10.897

Reputation: 7 234

1I wouldn't call it "compression" if it takes more bytes :P – lirtosiast – 2015-11-14T02:55:20.770

1I'm more worried about chars than bytes at this point. I've entirely given up on trying to golf down byte count in ... – Mama Fun Roll – 2015-11-14T02:56:23.287

1We always score by bytes, and while it's often interesting to optimize for a secondary objective, remember that the fewest bytes always wins. – lirtosiast – 2015-11-14T03:50:46.517

Yeah, I understand that. I'm not really aiming for winning as much though. – Mama Fun Roll – 2015-11-14T04:05:25.407

7

Clojure, 63 bytes

(pr (['light 'dark] (mod (Integer/parseInt (read-line) 35) 2)))
  • We read in a line from stdin with (read-line)
  • Then parse the string into an integer value in base 35 using a call to a JVM method
  • Taking mod of the result 2 tells us if it is even or odd
  • Use the result returned from the modulo function as an index to the sequence and print it

I save a worthy 2 bytes by quoting out "light" and "dark" with a single quote so that Clojure takes it as a literal, as opposed to wrapping each word in a pair of quotation marks. I also save a few bytes by using pr rather than println.

Some info on quoting in Clojure

MONODA43

Posted 2015-11-13T22:11:10.897

Reputation: 131

Welcome to Programming Puzzles and Code Golf! This is a nice first answer. :) I'm not too familiar with Clojure; would you mind adding an explanation? – Alex A. – 2015-11-17T05:30:21.547

Absolutely! There you go. Let me know if you have any questions! – MONODA43 – 2015-11-17T05:45:51.177

5

Minkolang 0.12, 28 24 bytes

on+2%t"dark"t"light"t$O.

Try it here.

Explanation

o                   Take character from input
n                   Take integer from input
+                   Add
2%                  Modulo by 2
t      t       t    Ternary; runs first half if top of stack is 0, second half otherwise
 "dark" "light"     Pushes the string "dark" or "light", depending.
$O.                 Output the whole stack as characters and stop.

El'endia Starman

Posted 2015-11-13T22:11:10.897

Reputation: 14 504

5

Labyrinth, 48 46 45 42 bytes

Thanks to Sp3000 for saving two bytes.

-,"
#
%0:::8.5.3.4.116.@
1
00.97.114.107.@

Try it online!

Explanation

The beginning of the code is a funny dead end. Remember that Labyrinth assumes an infinite number of zeroes when it requires operands at the bottom of the stack. The code starts one the - going right, which tries to subtract two numbers, so the stack becomes:

[ ... 0 ]

Then , reads the first character, a say:

[ ... 0 97 ]

The " is a no-op, but this is also a dead-end so the instruction pointer turns around and starts going to the left. Then ` reads the other character, 2 say:

[ ... 0 97 50 ]

This time, - subtracts those two numbers:

[ ... 0 47 ]

The IP now follows the bend of the "corridor". The # gets the stack depth, ignoring the implicit zeroes, which conveniently happens to be 2:

[ ... 0 47 2 ]

And % computes the modulo:

[ ... 0 1 ]

At this point, the IP is at a junction. If the top of the stack is zero, it will move straight ahead, where 100.97.114.107.@ prints dark. But if the top of the stack is non-zero (specifically, 1), it will move to the right, where 0:::8.5.3.4.116.@ prints light (note that we can omit the leading 1, because there is already a 1 on the stack, and we can save on the repeated 10 in 108, 105, 103, 104 by making a few copies of the 10 when we first get there).

Martin Ender

Posted 2015-11-13T22:11:10.897

Reputation: 184 808

5

C, 46 bytes

main(c){gets(&c);puts(c%37%2?"light":"dark");}

Expects an environment where ints are stored little-endian, and are at least two bytes.

Explanation

c is argc, so initially it contains 01 00 00 00. gets will read two chars, say a (0x61) and 1 (0x31), and store them in c, which is now

61 31 00 00

representing the number 0x3161, or 12641.

Essentially, in this problem, given c = x + 256*y, we want to compute (x + y) mod 2, and print a string accordingly. To do this, I could have written c % 255 % 2, as then

  (x + 256 * y) % 255 % 2
= (x % 255 + y % 255) % 2      since 256 ≡ 1 (mod 255)
= (x + y) % 2                  since 0 < x, y < 255

However, 37 also works:

  (x + 256 * y) % 37 % 2
= (x % 37 - 3 * (y % 37)) % 2  since 256 ≡ -3 (mod 37)

x is in the range 49-57 inclusive (digits 1-8), so x % 37 == x - 37.

y is in the range 97-104 inclusive (lowercase a-h), so y % 37 == y - 74.

This means we can simplify to

= (x - 3 * y + 185) % 2
= (x + y + 1) % 2              since -3 ≡ 185 ≡ 1 (mod 2)

and simply flip the strings to correct for the parity.

Lynn

Posted 2015-11-13T22:11:10.897

Reputation: 55 648

5

Beam, 127 bytes

rSr>`+v
   ^  )
n(`)nS<
    >L'''''>`+++++)S>`+++)@---@'''>`+++++)++@-------@H
>L'''''>`+++)S>`++++++)+++@---@--@+@'''>`++++)@H

An explanation enter image description here Light blue - read a character from input into beam, save the beam value into the store, read a character from input into beam.

Dark blue - Adds store to beam by decrementing store to 0 while incrementing the beam

Light green - An even odd testing construct. The loop will exit to the left if the beam is even or the right if odd.

Dark green - Outputs dark

Tan - Outputs light

MickyT

Posted 2015-11-13T22:11:10.897

Reputation: 11 735

5

O, 22 17 bytes

i#2%"light'dark"?

This does what it is required to do, with no additional benefits.

phase

Posted 2015-11-13T22:11:10.897

Reputation: 2 540

4

Matlab, 51 bytes

I do not think this needs any explanation=)

a={'light','dark'};disp(a(2-mod(sum(input('')),2)))

flawr

Posted 2015-11-13T22:11:10.897

Reputation: 40 560

4

><>, 31 bytes

ii+2%?\"krad"oooo;
l"oc0.\"thgi

Here I'm thinking "there's got to be a better way..."

Sp3000

Posted 2015-11-13T22:11:10.897

Reputation: 58 729

4

Perl, 29 27 bytes

$_=/./&($'+ord)?light:dark

This code requires the -p switch, which I have counted as 1 byte.

Try it online on Ideone.

How it works

  • Because of the -p switch, Perl reads one line of input and stores it in $_.

  • /./ is a regular expression that matches one character. This has two implications:

    • Since the match is successful, /./ returns 1.

    • The post-match (second input character) is stored in $'.

  • $'+ord adds the integer the second input character represents to the code point (ord) of the first character of the implicit variable $_.

  • & takes the bitwise AND of the return value of /./ and the sum $'+ord, returning 1 is the sum if odd, 0 if it is even.

  • ?light:dark returns light if the previous expression returned 1 and dark otherwise.

  • Finally $_= assigns the result to $_, which Perl prints automatically, because of the -p switch.

Dennis

Posted 2015-11-13T22:11:10.897

Reputation: 196 637

4

Brian & Chuck, 66 bytes

,>,_{->-?+{-_?>}<?light{-_?>}>>?dark?
II{<?}<<<?{<{<<<?_>.>.>.>.>.

Probably still golfable, but I think I'd need another approach.

Explanation

,>, reads input into Chuck, replacing the two Is. Next is the following part of the code:

   _{->-?
  {<?

which decrements both input elements until the latter (i.e. the digit) reaches zero. This stops Brian's ? from passing control to Chuck, continuing on.

The next + increments the zeroed digit to a 1 so that following uses of { don't get caught on it. At this point, the first cell of Chuck's tape has the difference of the two code points, so now we need to take the code point modulo 2. This is done with the following parts:

          A            B            C
          {-_?>}<?     {-_?>}>>?    ?
     }<<<?{<{<<<?

I've labelled the three parts on Brian's tape to make things easier to explain. The {- in parts A and B decrement the first cell on Chuck's tape, and the following ? checks if it's zero. If it's not, then control is passed, and we execute }<<<?. For part A, this moves us to part B. For part B, this moves us to part C, which immediately passes control and we execute {<{<<<?, sending us back to part A. Thus the effect is that we alternate between parts A and B, in a state machine-like way.

Now whether the first cell was zeroed while we were in part A or part B determines what we print. For A, we have:

             ?>}<?light
_               ?_>.>.>.>.>.

which executes >}< to position us on the last ? in Chuck's tape, and then runs >. five times to print "light".

On the other hand, for part B, we have:

                          ?>}>>?dark?
_                _>.>.>.>.>.

which executes >}>> to position us on the first . in Chuck's tape, and then runs >. four times to print "dark".

Sp3000

Posted 2015-11-13T22:11:10.897

Reputation: 58 729

4

Brainfuck, 132 bytes

>,>,[<->-]<[->+<[->-]<[<]>]<++++++++++[->++++++++++<]>>[<++++++++.---.--.+.++++++++++++.>->+<]>-[<<.---.+++++++++++++++++.-------.<]

I tried coming up with my own mod 2 algorithm, which is the [->+<[->-]<[<]>].

Sp3000

Posted 2015-11-13T22:11:10.897

Reputation: 58 729

4

Batch, 248 223 207 bytes

Because Batch lacks disjunctional conditionals. -18 bytes thanks to @dohaqatar7, and more due to his idea.

@ECHO OFF
SET S=SET 
%S%/P I=
%S%L=%I:~0,1%
%S%I=IF %L%==
%S%N=%I:~-1%
%S%A= %S%L=
%I%a%A%0
%I%b%A%1
%I%c%A%0
%I%d%A%1
%I%e%A%0
%I%f%A%1
%I%g%A%0
%I%h%A%1
%S%/A R=N%%2
IF %R%%L% (ECHO light) ELSE (ECHO dark)

Conor O'Brien

Posted 2015-11-13T22:11:10.897

Reputation: 36 228

2I'm not on a windows machine so I can't test right now but, you should be able to save some bytes by abusing variable expansion. Put set a=" set L=" at the top then replace every occurrence of set L= with %a%. – ankh-morpork – 2015-11-16T23:09:24.680

@dohaqatar7 Oh right you can do that. Thanks! – Conor O'Brien – 2015-11-16T23:18:31.270

4

Batch, 147 127 126 bytes

@set/pi=
@set/aj=%i:~1%%%2
@goto %i:~,1%
:a
:c
:e
:g
@set/aj=1-j
:b
:d
:f
:h
@if %j%==0 (echo dark)else echo light

Uses goto as a form of switch to increment the row number on alternate columns.

Edit: Saved 15 bytes by reducing the column modulo two up front and then using 1-j to flip between dark and light on alternate columns. Saved 2 bytes by removing some unnecessary ()s. Saved 3 4 bytes by removing some unnecessary spaces.

Neil

Posted 2015-11-13T22:11:10.897

Reputation: 95 035

4

Bash, 40 bytes

read x;y=(light dark);echo ${y[19#$x%2]}

Not using any coreutils.

Neil

Posted 2015-11-13T22:11:10.897

Reputation: 95 035

3

Bash + coreutils, 34 36

Using the same base conversion technique as other answers, but I chose base 19. I think it should work for any odd base between 19 and 35.

x=(light dark)
echo ${x[19#`cat`%2]}

Digital Trauma

Posted 2015-11-13T22:11:10.897

Reputation: 64 644

Looks like your code reverses the colors. 1 character shorter: x=(light dark);echo ${x[19#\cat`%2]}` – manatwork – 2015-11-14T15:16:07.573

@manatwork Thanks. When I tried the array indexing trick before it turned out longer - not sure what I got wrong. Thanks! – Digital Trauma – 2015-11-14T21:01:47.563

3

PHP, 40 42 bytes

PHP is doing OK this time:

<?=intval(fgets(STDIN),35)%2?dark:light;

Edits

  • Saved 2 bytes by using <?= instead of echo. Thanks to Martijn.

insertusernamehere

Posted 2015-11-13T22:11:10.897

Reputation: 4 551

240 chars: <?=intval(fgets(STDIN),35)%2?dark:light; – Martijn – 2015-11-16T15:20:42.820

2@Martijn Sometimes you can't see the simplest things. Thanks a lot. – insertusernamehere – 2015-11-16T15:42:58.717

3

CMD.EXE, 15 + 15 + 10 + 63 = 103 bytes

a1.cmd:

echo dark
exit

a2.cmd:

echo light
exit

Then create hard links for all the remaining 62 squares. Invoke using cmd /k echo off.

Neil

Posted 2015-11-13T22:11:10.897

Reputation: 95 035

2It's customary to count each additional file as one byte. That should apply to hard links too. – Dennis – 2015-11-14T01:37:30.457

I think the consensus is that each additional file after the 1st costs you an extra point. I would argue that hard links count as files for this purpose. – Digital Trauma – 2015-11-14T01:38:05.090

@Dennis you beat me to it by 35 seconds. Business as usual ;-) – Digital Trauma – 2015-11-14T01:39:21.070

3

Gol><>, 22 bytes

ii+2%Q"thgil"H|"krad"H

Explanation

ii             Read two chars
+2%            Add code points mod 2
Q        |     If top of stack is truthy...
 "thgil"H        Push "light" and halt, outputting stack
"krad"H        Push "dark" and halt, outputting stack

Sp3000

Posted 2015-11-13T22:11:10.897

Reputation: 58 729

3

Haskell, 61 56 Bytes

-5 bytes thanks to Mauris


As always, Haskell's interact function comes through with some byte saving on a challenge with IO.

The program assumes that a STDIN consists of only the row and the column, anything else can throw off the results; although, a trailing newline will not effect the outcome.

main=interact$(cycle["dark","light"]!!).sum.map fromEnum

ankh-morpork

Posted 2015-11-13T22:11:10.897

Reputation: 1 350

main=interact$(cycle["dark","light"]!!).sum.map fromEnum for 56 bytes. – Lynn – 2015-11-15T15:38:28.317

3

Vitsy, 23 22 21 Bytes

Thanks to @El'endiaStarman for shaving off a byte!

New Method (using fancy stack mechanics):

"krad"&"thgil"z+2M(?Z

Explanation:

"krad"&"thgil"z+2M(?Z
"krad"                 Push "dark" (backwards) to the stack.
      &                Generate a new stack.
       "thgil"         Push "light" (backwards) to the stack.
              z        Grab all input as string.
               +       Add up the input's ASCII values.
                2M     Modulate by 2.
                  (    If the result is not zero, do the next item.
                   ?   Rotate over a stack.
                    Z  Output everything in the current stack.

Original Method (using fancy line-specific execution mechanics):

z+2M1+mZ
"krad"
"thgil"

How it works:

z+2M1+mZ
z        Grab all input as string.
 +       Add it together.
  2M     Modulo by 2.
    1+   Add 1
      m  Go to the line specified by the top item of the stack - if it's one,
         it'll push "light" to the stack. If 2, "dark".
       Z Output everything in the stack.

Addison Crump

Posted 2015-11-13T22:11:10.897

Reputation: 10 763

3

JavaScript ES6, 59 56

s=prompt()
alert((s.charCodeAt()^s[1])%2?"light":"dark")

Extracts the number and the ASCII code of the letter, adds them and checks if even/odd. This can accept input in the form a1 and A1

3 bytes saved thanks to Neil!

Cyoce

Posted 2015-11-13T22:11:10.897

Reputation: 2 690

Requires input from STDIN, not a function. – Conor O'Brien – 2015-11-16T00:59:27.827

I didn't see that part. Edited – Cyoce – 2015-11-16T06:21:14.857

You can save a couple of bytes by using ^ instead of - - and the 0 is unnecessary. – Neil – 2015-11-18T00:31:52.247

3

Python 2 - 75 bytes

import sys
l,n=sys.stdin.read()
print 'light'if ord(l)&1^int(n)&1 else'dark'

Zac Crites

Posted 2015-11-13T22:11:10.897

Reputation: 201

3

Go, 100 bytes

package main;import."os";func main(){t:=Args[1];k,d:=t[0]+t[1],"light";if k%2==0{d="dark"};print(d)}

Ungolfed:

package main

import . "os" // Import os defines into current namespace

func main() {
    t := Args[1] // Grab the first argument
    // Define k as the sum of the 2 
    // first characters of the first argument, then define d as "light"
    k, d := t[0]+t[1], "light"
    // The sum aligns up nicely with the color of the square        
    if k%2 == 0 {
        d = "dark"
    }
    print(d)
}

Kristoffer Sall-Storgaard

Posted 2015-11-13T22:11:10.897

Reputation: 489

You can save a byte using !k%2 (unless I'm mistaken about precedence) – cat – 2016-05-18T01:04:15.543

@cat Go does not support boolean operators on ints – Kristoffer Sall-Storgaard – 2016-05-18T12:49:13.547

Uhh... oh. I forgot about that. Go gets a little lamer every time I come back to it. – cat – 2016-05-18T13:00:19.800

3

PowerShell, 52 46 45 bytes

("dark","light")[(+($a="$input")[0]+$a[1])%2]

Pretty ugly due to how we have to parse the STDIN input (which, in PowerShell, is weird). The special variable $input is present only if items get piped in, we encapsulate that into a string, and save it into $a. Then, we use the same math trick as other answers to calculate out whether the input is even or odd, and use that to index into our "dark" or "light" output array.

Edit -- saved 6 bytes by using + to cast $a[0] instead of [int]. Saved an additional byte by changing where $a is created by using a code block.

AdmBorkBork

Posted 2015-11-13T22:11:10.897

Reputation: 41 581

You can drop 3 bytes by replacing [int] with 1* – Rynant – 2015-11-17T19:28:21.307

@Rynant Or, use + and drop the parens to save 6. ;-) – AdmBorkBork – 2015-11-17T19:36:06.720

Even better; nice! – Rynant – 2015-11-17T19:48:13.423

3

Common Lisp, 90 bytes

Not a winner, but makes nice use of ability to read in base 18 and then do arithmetic with that number.

(let((*read-base* 18))(if(evenp(multiple-value-call'logxor(floor(read)18)))"light""dark"))

Joshua Taylor

Posted 2015-11-13T22:11:10.897

Reputation: 660

3

Marbelous, 86 bytes

..00
..]]//
&0/\]]//
..&0//
..//
^0
=0&1
&2\/
\/
'l'i'g'h't'd'a'r'k
&1&1&1&1&1&2&2&2&2

]]// loops wait for two bytes of input, then add them together and use ^0 and =0 to check the LSB and drop "light" or "dark" to stdout.

Sparr

Posted 2015-11-13T22:11:10.897

Reputation: 5 758

3

Bash, 69 Bytes

sed 's/^./(&+/;s/$/)%2/'|tr [a-h] [1-8]|bc|sed s/1/light/\;s/0/dark/

Probably could be optimized a bit more.

  • The first sed formats the input to be from the form a5 to (a+5)%2
  • tr takes the letters a-h and converts them to 1-8 respectively
  • bc performs the addition and modulo
  • the final sed then takes the result and formats it as a string.

Tyzoid

Posted 2015-11-13T22:11:10.897

Reputation: 692

3

MATL, 20 bytes

js2\?'light'}'dark']

Explanation

j              % input string
s              % sum  
2              % push 2
\              % mod(sum(inputstring),2)
?              % if this value is 1
  'light'      % return 'light'
}              % else  
  'dark'       % return 'dark'
]              % end   

flawr

Posted 2015-11-13T22:11:10.897

Reputation: 40 560

Was MATL written before this challenge? – lirtosiast – 2015-12-18T21:33:29.090

Oh, I forgot about that. The first version was published in october as far as I know, but I am not sure whether this is valid code in the first version. – flawr – 2015-12-18T21:43:02.820

Yes, the language was in draft in October with a preliminary version of the interpreter also available. The esolangs.org page was also created at that time... so I think you're good here flawr. – rayryeng - Reinstate Monica – 2015-12-18T22:17:22.623

Vert nice use of mod! – Luis Mendo – 2015-12-18T23:08:35.400

Well I basically just translated my matlab answer=) – flawr – 2015-12-18T23:48:05.013

2

SmileBASIC, 66 bytes

INPUT L$N=INSTR(@bdfh,L$)<0!=VAL(POP(L$))MOD 2?"light"*N;"dark"*!N

explanation:

INSTR(@bdfh,L$)<0 'Checks if L$ is b,d,f,h. @bdfh is a label, equivalent to the string "@bdfh"
!= 'used as a logical XOR, which SB doesn't have.
VAL(POP(L$))MOD 2 'Checks if the row is odd. Also removes the second character of L$, 
                   'which makes the first check shorter since SB evaluates right to left.
?"light"*N;"dark"*!N 'this turned out to be shorter than using IF/THEN/ELSE.

12Me21

Posted 2015-11-13T22:11:10.897

Reputation: 6 110

2

Microscript, 25 bytes

Because Microscript II really doesn't have much in terms of character manipulation yet.

2sI++%{"thgil"ah}"krad"ah

SuperJedi224

Posted 2015-11-13T22:11:10.897

Reputation: 11 342

2

ShapeScript, 57 56 bytes

0'1+@"%c"2?862**+%$"%d"2?%~@'8*!#!+"dark"@"light"@'@'*!#

Try it online!

How it works

0         Push 0 (accumulator).
'         Push a string that, when evaluated, does the following:
  1+        Increment the accumulator.
  @         Swap it with the input.
  "%c"      Push that formatting string.
  2?        Copy the accumulator.
  862**+    Add 8 * 6 * 2 = 96 to it.
  %         Apply the string formatting: 1 ... 8 -> 'a' ... 'h'
  $         Split the input at occurrences of that character.
  "%d"      Push that formatting string.
  2?        Copy the accumulator.
  %         Apply the string formatting: 1 ... 8 -> '1' ... '8'
  ~         Join the split input, using that character as separator.
  @         Swap the result with the accumulator.
'
8*        Repeat the string eight times.
!         Evaluate.
#         Discard the accumulator.
!         Evaluate the modified input. Pushes two integers.
+         Add the integers.
"dark"@   Swap the sum with that string.
"light"@  Ditto.
'@'*!     Repeat the at sign (swap) that many times and evaluate the result.
          An odd number of swaps brings "dark" on the top of the stack.
#         Discard the topmost string.

Dennis

Posted 2015-11-13T22:11:10.897

Reputation: 196 637

2

Mouse, 25 bytes

?'?'+2\["light"$]"dark"$

Explanation:

?'?'                       ~ Read two characters from STDIN and put their ASCII
                           ~ codes on the stack
    +2\                    ~ Get the sum of the codes modulo 2
       ["light"$]          ~ If the result is 1, print light to STDOUT and exit
                 "dark"$   ~ Print dark to STDOUT and exit

Alex A.

Posted 2015-11-13T22:11:10.897

Reputation: 23 761

2

SpecBAS - 59 bytes

My original version (before looking at any other answers) was 117 bytes and probably reflects the way I come at a problem. Then I saw everyone using base 19 or 35, which wouldn't have sprung to my mind at all.

So, with thanks to everyone else for getting this down to 59.

1 INPUT s$: PRINT IIF$(DECIMAL(s$,19) MOD 2,"Dark","Light")

Prints "Dark" if converted number mod 2 is 1/True and "Light" otherwise, using the inline if statement.

Brian

Posted 2015-11-13T22:11:10.897

Reputation: 1 209

2

R, 163 bytes

Thanks to Alex A. for helping me with this answer.

n<-toupper(unlist(strsplit(scan(,""),"")));cat(matrix(rep(c(rep(c("light","dark"),4),rep(c("dark","light"),4)),4),8,8,dimname=(list(8:1,LETTERS[1:8])))[n[2],n[1]])

Example usage

1: b1
2: 
Read 1 item
light

1: d4
2: 
Read 1 item
dark

There's surely a better way to do this. I just made a matrix filled with the string "light" or "dark" to match the chessboard and then used subscripts taken from the input to return the color of the square.

syntonicC

Posted 2015-11-13T22:11:10.897

Reputation: 329

Alright, I took your suggestions and fixed it. Thanks for your help! – syntonicC – 2015-11-16T00:52:25.987

3

Here's some tips for golfing in R. Couple of things that stand out. Replace <- with =. toupper isn't required, but you'll need to use letters rather than LETTERS. You could create a 9 x 9 matrix using matrix(c('dark','light'),9,9). It will throw a warning, but I don't think that's a problem. You could also play around with charToRaw. So keeping the same sort of logic you could reduce it to something like cat(matrix(c('dark','light'),9,9)[(n=as.integer(charToRaw(scan(,'')))-c(96,48))[1],n[2]])

– MickyT – 2015-11-16T01:50:24.600

2

R, 65 bytes

cat(c("dark","light")[1+sum(strtoi(charToRaw(scan(,"")),16))%%2])

Ungolfed:

# Get the ASCII codes from the input string
a <- strtoi(charToRaw(scan(, "")), 16L)

# Compute the sum modulo 2
s <- sum(a) %% 2

# Use the sum as an index for the output
cat(c("dark", "light")[s + 1])

Alex A.

Posted 2015-11-13T22:11:10.897

Reputation: 23 761

154 bytes – Giuseppe – 2017-10-05T20:58:25.827

2

Scala, 65 53 49 bytes

It's quite clear without ungolfing.

print(Seq("dark","light")(readLine.sum.toInt%2))

V.G.

Posted 2015-11-13T22:11:10.897

Reputation: 161

2

C# (Visual C# Interactive Compiler) - 122 42

Write((Read()+Read())%2<1?"dark":"light");
  • Reads from STDIN
  • Format is simply a1

Thanks to @dana for the change from C# to the current one & golfing a ton of bytes! :)

Try It Online!

Yytsi

Posted 2015-11-13T22:11:10.897

Reputation: 3 582

I got it down to 100, but if you switched to the "Visual C# Interactive" REPL you could do better - https://tio.run/##Sy7WTc4vSv3/v7Q4My9dwdk2uLK4JDVXzzk/rzg/J9U6OSexuFghoLq4JLEkM1mhLD8zRcE3MTNPQ7PaWS@8KLMkVUPDWS8oNTFFQ1MbxtBUNbIxtFdKSSzKVrJSyslMzyhR0rSurf3/P8kIAA

– dana – 2018-12-24T15:38:40.787

2

GolfScript, 21 bytes

{^}*~1&"lightdark"5/=

Explanation:

{^}*            # XOR the bytes of the input together
~               # negate the result
1&              # extract only the lowest bit (i.e. 0 or 1)
"lightdark"5/   # split the string "lightdark" into the array ["light" "dark"]
=               # use the bit as an index into the array, returning "light"
                # for 0 and "dark" for 1

Conveniently, since the ASCII codes of a Unix-style newline (LF = ASCII 10) and a space (ASCII 32) are even, this code can handle arbitrary spaces and linefeeds in its input. Both upper- and lowercase letters are also accepted, and the letter can be given before or after the number. Tabs or carriage returns, however, will throw it off.

Not unexpectedly, this program is quite similar to Peter Taylor's CJam entry. I didn't actually look at any of the other entries before I wrote this, though.

Ilmari Karonen

Posted 2015-11-13T22:11:10.897

Reputation: 19 513

2

Burlesque, 25 bytes

)**++"dark light"wdcyj!!Q

One-to-one translation from the 56 bytes Haskell solution to this challenge:

)**++             -- sum . map fromEnum
"dark light"wdcy  -- cycle["dark","light"]
j                 -- swap
!!                -- same as Haskell !!

mroman

Posted 2015-11-13T22:11:10.897

Reputation: 1 382

2

Prolog, 80 bytes

p:-read(X),string_codes(X,[A,B]),Y is(A+B)mod 2,(Y=0->write(dark);write(light)).

Try it online here

Emigna

Posted 2015-11-13T22:11:10.897

Reputation: 50 798

/\1 instead of mod 2 + removing the parens around (A+B) saves a few bytes – ASCII-only – 2018-06-01T10:34:32.930

2

PlatyPar, 21 bytes

This is a non-competing answer, as I made this language after the posting of this question. It was neither made for this question nor has it been augmented to fit this specific question.

X,u#^2%?"dark"\"light

Explanation

X,u#^                  ## charcode of the letter XOR the number
     2%?      \        ## if it is odd
        "dark"         ## output "dark"
               "light  ## else output "light

Try it online!

Cyoce

Posted 2015-11-13T22:11:10.897

Reputation: 2 690

2

Lua, 53 Bytes

l,n=(...):byte(1,2)print(l%2==n%2 and"dark"or"light")

Pretty simple, takes command line input through ... and assigns variables l and n to the first and second byte of the input and then checks the ASCII value of each. If both are even or both are odd, the square is dark, else the square is light.

Cyv

Posted 2015-11-13T22:11:10.897

Reputation: 211

2

><> Fish 26 bytes

d"darkthgil"ii+2%?!rooooo;

A spin on the already posted fish code by sp3000.

It uses the same based checking with mod but with a few changes.

Using 1 line allows us to save 6 bytes (1 for the new line, 2 for directional instructions and 3 for the jump instructions)

Lose 1 byte to placing a [CR] onto the stack but it allows us to use 5 prints on both answers.

Lose 1 byte to reversing the stack [r] when needed for an answer.

Lastly putting both answers on the stack in 1 string allows us to save 2 bytes not having to use ["] twice.

Teal pelican

Posted 2015-11-13T22:11:10.897

Reputation: 1 338

1

AHK, 78 bytes

a=%1%
If Mod(Asc(a)+Asc(SubStr(a,2)),2)=1
s=light
Else
s=dark
FileAppend,%s%,*

AHK uses 1 as the name for the first parameter so you have to assign to a different name before you use it in functions. Otherwise, it'll think you mean the value 1 and not the variable named 1. Also, the only way to report to STDOUT is by using FileAppend with * as the file name.

Engineer Toast

Posted 2015-11-13T22:11:10.897

Reputation: 5 769

1

K (oK), 16 bytes

`dark`light 2!+/

Try it online!

+/ sum the (code points of the) argument

2! mod-2

darklight  select that from this list of symbols

Adám

Posted 2015-11-13T22:11:10.897

Reputation: 37 779

1

Jelly, 11 bytes

OḂEị“_ß“ṗɠ»

Try it online!

Erik the Outgolfer

Posted 2015-11-13T22:11:10.897

Reputation: 38 134

1

Chip, 57 bytes

*gS!~s
fA.Z\ZZZvt
cZ}x< eab
>--^/vZZvZZvt
ZZZd ddac ce
ab

Try it online!

XOR's the low bit of each input (like most if not all other answers) to make the decision. Outputs dabh`, bitwise-OR'd with hhe`t for light or ``pc for dark. (Dark also exits one byte early).

Phlarx

Posted 2015-11-13T22:11:10.897

Reputation: 1 366

1

Japt, 16 bytes

`ä•Krk`qe g~Uxc

Try it online!

How it works

`ä•Krk`qe g~Uxc

`ä•Krk`          Compressed literal for "lightedark"
        qe        Split with "e"
           g      Take the element at the index (wrapping)...
             U      Input array of chars
              xc    Sum the chars' charcodes
            ~       Take bitwise not, in order to swap parity

The string array compression trick did quite a job here.

Bubbler

Posted 2015-11-13T22:11:10.897

Reputation: 16 616

1

05AB1E (legacy), 13 bytes

“–°‡Ž“#I35öÈè

Try it online!

Here is a golf with your own language :)

Explanation

“–°‡Ž“       : compressed: "dark light"
      #      : split by space
            è: select the 0th or 1st element based on {
       I35ö  :  take the input and convert it to int from base 35
           È :  1 if even else 0
               }

krinistof

Posted 2015-11-13T22:11:10.897

Reputation: 431

0

Java, 178 bytes

interface z{static void main(String[]a){int b=a[0].charAt(0)-'a',c=a[0].charAt(1)-'0';if(b%2==0&&c%2!=0||b%2!=0&&c%2==0)System.out.print("dark");else System.out.print("light");}}

Takes input as first argument.

Ungolfed:

interface z {
    static void main(String[]a) {
        int b = a[0].charAt(0) - 'a',                               // Convert value from a to value from 0...7
                c = a[0].charAt(1) - '0';                           // Get number
        if (b % 2 == 0 && c % 2 != 0 ||                             // If b is divisible by 2 and c is divisible by 2 or
                b % 2 != 0 && c % 2 == 0)                           // b is not divisible and c is divisible
            System.out.print("dark");                               // output dark
        else System.out.print("light");                             // else output light
    }
}

cookie

Posted 2015-11-13T22:11:10.897

Reputation: 271

0

Tcl, 63 bytes

scan [gets stdin] %c%d h v
puts [expr ($h+$v)%2?"light":"dark"]

Try it online!

sergiol

Posted 2015-11-13T22:11:10.897

Reputation: 3 055

0

QBIC, 38 bytes

~(asc(;)+!_sA,-1|!)%2|?@Light`\?@Dark

Explanation

~(                       IF
  asc( )                 the ascii value of
      ;                  the input string (of the input "b1" only the first char is evaluated by asc())
        + _s ,  |        plus a substring of
            A            A$ (the input, this was assigned to A$ by ;)
              -1         taking only the first char from the right
         !        !      and cast this to num
                   )%2   MODULO 2 (is non-zero, implicit)
|?@Light`                THEN PRINT the literal "Light"
\?@Dark                  ELSE PRINT "Dark" (no terminating ` is needed at EOF)

steenbergh

Posted 2015-11-13T22:11:10.897

Reputation: 7 772

0

F# (Mono), 63 bytes

printf(if(stdin.Read()+stdin.Read())%2<1 then"dark"else"light")

Try it online!

dana

Posted 2015-11-13T22:11:10.897

Reputation: 2 541

0

APL (Dyalog Unicode), 25 bytesSBCS

-1 thanks to Bubbler.

'dark' 'light'⊃⍨2|+/⎕UCS⍞

Try it online!

 get text from stdin

⎕UCS convert to Universal Character Set code points

+/ sum

'dark' 'light'⌽⍨ use that to cyclically rotate the list of strings

 pick the first

Adám

Posted 2015-11-13T22:11:10.897

Reputation: 37 779

24 bytes. – Bubbler – 2020-02-27T03:18:04.943

@Bubbler 23.

– Adám – 2020-02-27T06:17:04.057

OP requires a full program, so the 23 is invalid. – Bubbler – 2020-02-27T06:20:49.073

@Bubbler Oh. Hm. – Adám – 2020-02-27T06:21:24.957

0

Kotlin, 45 bytes

{if(it.sumBy{it-'@'}%2>0)"light" else "dark"}

Try it online!

snail_

Posted 2015-11-13T22:11:10.897

Reputation: 1 982

0

Runic Enchantments, 25 bytes

iu+2%1(8*?"light"@"dark"@

Try it online!

How it works

>                      implicit entry
 i                     read string from input
  u                    break the string into characters
   +                   add them together
    2%                 modulo 2
      1(               compare with 1
        8*             multiply the result (true -> 8, false -> 0)
          ?            pop x, if x is truthy, skip x characters
           "light"@    output light if false
           "dark"@     ouput dark if true

Draco18s no longer trusts SE

Posted 2015-11-13T22:11:10.897

Reputation: 3 053