1
   

turn on all the squares

 
 
Reply Sat 11 Mar, 2006 02:27 am
Consider an n by n board. Each square has a pair of co-ordinates ( x,y ) where 1<= x, y <= n. Each square has two states : either "ON" or "OFF". Initially, all the squares are OFF. For a square (i.j), its neighbors are the squares: { (i' , j' ) | 1<= i' , j' <=n; |i-i'| , |j-j'| <=1} . The neighbors of (4,2) in case of n=4 are {(4,1),(4,2),(3,2),(4,3)} . Note that (i, j) is a neighbor of itself. Define the operation toggle (i,j) that toggles the state of square (i ,j)'s neighbors. i.e. if the state is "ON" then it is turned "OFF" and vice versa. Write a program that, given a n by n board off all OFF squares, computes the shortest sequence of toggle operations that turns all the squares ON. If no sequences can turn all the squares "ON", output "No Solution". On addition to that, the solution should contain step by step change of state (shown graphically).
Example Input
2 3
Example Output
(1,1) (1,2) (2,2) (2,1)
(2,2) (1,3) (3,3) (3,1) ( 1,1)
if you have to toggle ( 2,1) then we toggle its neighbors ( 2,2) (2,1) (1,1) (1,3) . The diagonal elements are not considered.

tell me yhe logic for doing this or full solution
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 689 • Replies: 13
No top replies

 
markr
 
  1  
Reply Sat 11 Mar, 2006 01:01 pm
Order doesn't matter, parity does. You need to fill the grid with 0s and (the least number of) 1s such that for each square, the sum of its neighbors is odd. A 1 represents a toggle operation.

possibly non-optimal solutions:
1x1
1

2x2
11
11

3x3
101
010
101

4x4
1001
0000
0110
0110
0 Replies
 
markr
 
  1  
Reply Sat 11 Mar, 2006 09:42 pm
My program gives:
n, toggles
2, 4
3, 5
4, 4
5, 15
6, 28
7, 33
8, 40
9, 25
10, 44
11, 55
12, 72
13, 105
14, 56
15, 117
16, 104
17, 147
18, 188
19, 141
20, 224

Here's 20x20:

1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1
0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0
1 0 1 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 1
0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0
0 0 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 0 0 0
1 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1
1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 1
1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 0 0 1
1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 1
1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1
1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1
1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 1
1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 0 0 1
1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 1
1 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1
0 0 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 0 0 0
0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0
1 0 1 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 1
0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0
1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1
0 Replies
 
anurag1408
 
  1  
Reply Sun 12 Mar, 2006 07:05 am
markr
could u please tell me the logic and program for this.please. is it possible for all n to turn squares on
give your program.paste it here.i want to see
0 Replies
 
markr
 
  1  
Reply Sun 12 Mar, 2006 01:18 pm
I've given you a big enough hint already. You should be able to code that.
0 Replies
 
anurag1408
 
  1  
Reply Mon 13 Mar, 2006 01:52 am
markr

i request u to please give me the code for this problem if u have.i need it urgently.also tell me the logic u have used.
i will be thankful to u.
u can mail me at [email protected]

mail me as well as paste it here so that everybody can see.
i am waiting for it.please
0 Replies
 
anurag1408
 
  1  
Reply Tue 14 Mar, 2006 01:52 am
hurry up
hi markr
i need it urgently.please give it to me the code and tell me the logic.
pleaseeeeee
hurry up
bye
0 Replies
 
anurag1408
 
  1  
Reply Fri 17 Mar, 2006 12:52 am
hi markr
for a 4*4 square u have shown no of 1 to be 6.but u given ans 4.how is it .please reply.give me code for this .Tell me the logic how to approach and which square to go .or give me the coding please
0 Replies
 
markr
 
  1  
Reply Fri 17 Mar, 2006 10:22 am
Let's see your attempt (code) to solve it.
0 Replies
 
anurag1408
 
  1  
Reply Sun 19 Mar, 2006 12:20 am
request
well markr
u di not tell me the logic.i have to submit the code before 21 march for a event.
please give me the code.it will really help me.after all forum is made for helping each other.please do it early and reply me
i am asking u as a friend,please
0 Replies
 
whimsical
 
  1  
Reply Sun 19 Mar, 2006 07:35 am
You seem really desperate. But I agree with Mark, why take part of a programming event (or is it homework?) if you can't show a bit of work yourself.

Whim
0 Replies
 
lmur
 
  1  
Reply Sun 19 Mar, 2006 07:42 am
I will show you, anurag1408.

But it will cost you - one million dollars.

e-mail me at [email protected]
0 Replies
 
markr
 
  1  
Reply Sun 19 Mar, 2006 02:20 pm
I've already provided you with what I think is the key to solving the problem. At this point, it's a coding exercise. I've also given you data to test your algorithm (assuming I've coded it correctly). I'm not going to post my solution.
0 Replies
 
anurag1408
 
  1  
Reply Mon 20 Mar, 2006 06:04 am
please
i need it.mail me at [email protected] if u dont want to paste it here
0 Replies
 
 

Related Topics

Alternative Einstein's riddle answer - Discussion by cedor
Urgent !!! Puzzle / Riddle...Plz helpp - Question by zuzusheryl
Bottle - Question by Megha
"The World's Hardest Riddle" - Discussion by maxlovesmarie
Hard Riddle - Question by retsgned
Riddle Time - Question by Teddy Isaiah
riddle me this (easy) - Question by gree012
Riddle - Question by georgio7
Trick Question I think! - Question by sophocles
Answer my riddle - Question by DanDMan52
 
  1. Forums
  2. » turn on all the squares
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.08 seconds on 12/22/2024 at 11:17:55