r/dailyprogrammer • u/oskar_s • Apr 27 '12
[4/27/2012] Challenge #45 [easy]
Your challenge today is to write a program that can draw a checkered grid (like a chessboard) to any dimension. For instance, a 3 by 8 board might look like this:
*********************************
* *###* *###* *###* *###*
* *###* *###* *###* *###*
* *###* *###* *###* *###*
*********************************
*###* *###* *###* *###* *
*###* *###* *###* *###* *
*###* *###* *###* *###* *
*********************************
* *###* *###* *###* *###*
* *###* *###* *###* *###*
* *###* *###* *###* *###*
*********************************Yours doesn't have to look like mine, you can make it look any way you want (now that I think of it, mine looks kinda bad, actually). Also try to make it scalable, so that if you want to make a 2 by 5 board, but with bigger squares, it would print out:
*******************************
* *#####* *#####* *
* *#####* *#####* *
* *#####* *#####* *
* *#####* *#####* *
* *#####* *#####* *
*******************************
*#####* *#####* *#####*
*#####* *#####* *#####*
*#####* *#####* *#####*
*#####* *#####* *#####*
*#####* *#####* *#####*
*******************************Have fun!
14
Upvotes
8
u/[deleted] Apr 27 '12
J code: (
tw th bw bhare set to4 6 5 3, here)Or as a one-liner:
Output:
3
u/juanfeng Apr 27 '12 edited Apr 27 '12
Python
3
u/[deleted] Apr 29 '12
Processing was made for this sort of thing:
My output is this (10 x 8 board):
http://imgur.com/Arccd
2
u/Nedroo Apr 27 '12 edited Apr 27 '12
Scala
2
u/emcoffey3 0 0 Apr 28 '12
C#
2
u/RawketLawnchair Apr 29 '12
Java, I feel like this code is way too long looking at these other submissions.
2
u/whydoyoulook 0 0 May 01 '12 edited May 01 '12
My Java solution. As usual, I'm sure there are many more elegant solutions than this. Feedback always welcome.
3
u/debugmonkey 0 0 Apr 27 '12 edited Apr 27 '12
C++ Answer. Not quite as small as the Python answer but it's good enough for me :)
1
u/chriszimort Apr 28 '12
Very ugly c# implementation.
1
u/robin-gvx 0 2 Apr 28 '12
Zero explicit variables: http://hastebin.com/raw/popoqidawu
(Maybe I should add a
repeatstatement to Déjà Vu...)1
u/siberianluck Apr 28 '12
Here's a python version that uses ansi escapes
https://gist.github.com/2520694
1
u/magwhich Apr 29 '12
python
1
u/[deleted] Apr 30 '12
My C Solution:
1
u/ctess Apr 30 '12
Powershell (Sorry if it's sloppy, I was going for readability)
1
u/[deleted] Oct 06 '12 edited Oct 06 '12
JavaScript - (Little cheat to gain scalability)
Usage:
1
u/stereopump 0 0 Apr 27 '12
C++
1
u/eruonna Apr 27 '12
Haskell:
Output: