LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-09-2005, 03:10 PM   #1
StarLion
LQ Newbie
 
Registered: Sep 2005
Posts: 4

Rep: Reputation: 0
Ruby Syntax Error


Code:
def MakeBoard
 rcount = 0
 puts "Push enter, then begin input. (For Input Format Compliance, extra enter key is necessary)"
 gets
 board = [0,0,0,0,0,0,0,0,0]
 9.times do
   instr = gets
   board[rcount] = [instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],instr[8]]
   rcount += 1
 end
 return board
end

def CheckBoard(board)
 complete = 1 #Is the puzzle complete?
 problems = 0 #Are there any problems?

 #first, rows.
 h = 0
 9.times do
  g = 0
  group = [0,0,0,0,0,0,0,0,0]
  9.times do
    if board[h][g] == "."
      group[g] = 0
      complete = 0
    else
      group[g] = board[h][g]
    end
  end
  problems = VerifyGroup(group) 

  #puts "Row " + h.to_s + " Problems? " + problems.to_s
end
 #end Row Check

 #next, columns.
 h = 0
 9.times do
  g = 0
  group = [0,0,0,0,0,0,0,0,0]
  9.times do
    if board[g][h] == "."
      group[g] = 0
      complete = 0
    else
      group[g] = board[g][h]
    end
  end
  problems = VerifyGroup(group) 
  #puts "Col " + h.to_s + " Problems? " + problems.to_s
 end
 ##end Col Check

 ##Finally, the tricky one... the Boxes..
 startx = 0
 starty = 0
 curx = 0
 cury = 0
 count = 0
 group = [0,0,0,0,0,0,0,0,0]
 3.times do #Row Blocks
  3.times do #Cols Blocks
   3.times do #Rows of Block
    3.times do #Cols of Block
     if board[curx][cury] == "."
      group[count] = 0
     else
      group[count] = board[curx][cury]
     end
     curx += 1
    end
    curx = startx
    cury += 1
   end #We now have a 3x3 block. Verify Data.
   problems = VerifyGroup(group)
   #puts "Box " + startx.to_s + "," + starty.to_s + " Problems? " + problems.to_s
   count = 0
   startx += 3
   cury = starty
   curx = startx
  end
  starty += 3
  startx = 0
  cury = starty
  curx = startx
 end

#Resolve the output.
if problems == 0
  if complete == 1 
    $output = $output + "You've done it!\n"
  else
    $output = $output + "Looking good so far...\n"
  end
else
  $output = $output + "You've got a problem."
end
end #FINALLY!

def VerifyGroup(group)
  #logic for Check
  flag = 0
  check = [0,0,0,0,0,0,0,0,0,0]
  group.each do |num|
   if check[num] == 0 && num != 0
      check[num] = 1
   else if num == 0
      check[0] = 0 
   else
      flag = 1
   end
   num += 1
  end
  return flag
end


output = ""
n = gets
n.to_i.times do
board = MakeBoard()
CheckBoard(board)
end
Throws "Syntax error" on the last line (end)... now, i'm not thinking there's something wrong with my spelling of the word end, but i cant seem to locate where this error IS occuring!
 
Old 12-10-2005, 09:14 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Unmatched "end"

I think the error is on the last line; it doesn't seem like that "end" matches anything above it. Before that all of your functions, conditionals, and loops have all been finished, so there shouldn't be an "end" on the last line.
 
  


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
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
GEdit syntax highlighting for ruby dublinclontarf Programming 0 08-18-2004 01:19 PM
Where's the syntax error tamtam Programming 2 07-24-2004 09:07 AM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

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

All times are GMT -5. The time now is 05:32 PM.

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