LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2007, 12:17 AM   #1
som_kurian
Member
 
Registered: Oct 2007
Posts: 33

Rep: Reputation: 15
To get a pattern of chessboard


Hi friends,


For getting a pattern of chessboard



But due to some reasons..I am not getting the desired output.Can u help me with this..

for (( i=1; i <= 9; i++ ))
do
for (( j=1; j <= 9; j++ ))
do

tot=`expr $i + $j`
tmp=`expr $tot % 2`
if [ $tmp -eq 0 ]/* if even puts white color */
then
echo -e -n "\033[40m"
else
echo -e -n "\033[47m"
fi
done
echo -e -n "\033[40m"
echo " "
done

Last edited by som_kurian; 11-23-2007 at 03:35 AM.
 
Old 11-17-2007, 02:02 AM   #2
juergen
Member
 
Registered: Sep 2001
Posts: 40

Rep: Reputation: 16
You are getting pretty close, but:
  • You need to ditch the /* */ comment; comments in bash start with a #
  • In the first for statement, for (( i=1; 1 <= 9; i++ )), the 1 in '1 <= 9' has to be turned into an i
  • The <= comparisons in both for statements should be regular < if you want a true 8x8 board
  • You need to actually print something in order for the color to show up; so the 'echo -e -n "\033[47m"' turns into 'echo -e -n "\033[47m "' (note the added space)
  • The two echos between the 'done' statements appear superfluous to me

That's what I came up with off the top of my head; the list may not be complete, but it ought to help a bit.

Good luck!
 
Old 11-17-2007, 05:45 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Here's an example that was kicking around here awhile back...
Code:
#!/bin/bash

clear
echo ""

for (( i = 1; i <= 8; i++ )); do
  for (( j = 2; j <= 9; j++ )); do
    tot=$(expr $i + $j)
    tmp=$(expr $tot % 2)
    if [ $tmp -eq 0 ]; then
      echo -en "\033[40m  "
    else
      echo -en "\033[47m  "
    fi
  done
 echo ""
done
echo -e "\033[0m\n"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
A chessboard Gins Programming 9 07-29-2006 05:24 PM
Http pattern rigel_kent Programming 10 05-06-2006 01:24 PM
using grep when the pattern contains a ! farmerjoe Programming 9 03-15-2005 11:04 PM
Pattern Recognition trbdk3 Linux - Software 1 01-27-2005 01:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration