Thread: How to learn everything

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    "How to learn everything?"

    Cure the disease by solving an actual problem.

    Wolves vs. Sheep Puzzle

    Since your brain needs something to do: My idea of putting sheep on the main diagonal and them putting wolves a knight's move away hasn't worked and I've been trying to put a fifth wolf in for too long. It's impossible, prove me wrong.

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by whiteflags View Post
    Wolves vs. Sheep Puzzle
    It's impossible, prove me wrong.
    It's impossible, here is proof by exhaustive search.

    Code:
    #include <stdio.h>
    
    void MarkDirty(bool* , int);
    int CountClean(bool*);
    
    int main(){
    
    	bool Dirty[25];
    
    	for(int a = 0;a<25;a++){
    		for(int b = 0;b<25;b++){
    			for(int c = 0;c<25;c++){
    				for(int d = 0;d<25;d++){
    					for(int e = 0;e<25;e++){
    						if(a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e){
    							// every wolf is in a unique location
    							for(int x = 0;x<25;x++) Dirty[x] = false;
    							MarkDirty(Dirty , a);
    							MarkDirty(Dirty , b);
    							MarkDirty(Dirty , c);
    							MarkDirty(Dirty , d);
    							MarkDirty(Dirty , e);
    
    							if(CountClean(Dirty) > 2){
    								printf("Solution at %d %d %d %d %d\n" , a , b , c , d , e);
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    
    	return 0;
    	}
    
    void MarkDirty(bool* Dirty, int Cell){
    	int Row = Cell - (Cell % 5);
    	
    	for(int x = Row;x<Row + 5;x++) Dirty[x] = true;
    	for(int x = 0;x<5;x++) Dirty[(Cell + (x*5)) % 25] = true;
    	for(int x = 0;x<5;x++) Dirty[(Cell + (x*5) + x) % 25] = true;
    	for(int x = 0;x<5;x++) Dirty[(Cell + (x*5) - x) % 25] = true;
    	
    	return;
    	}
    
    int CountClean(bool* Dirty){
    	int Count = 0;
    
    	for(int x = 0;x<25;x++){
    		if(!Dirty[x]) Count++;
    		}
    
    	return Count;
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. You have to learn C in order to learn C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-16-2004, 10:33 AM
  2. Quickly learn C# for a C++ expert
    By BigDaddyDrew in forum C# Programming
    Replies: 9
    Last Post: 06-06-2004, 04:38 PM
  3. The best place to learn
    By CougarElite in forum C Programming
    Replies: 15
    Last Post: 04-25-2004, 04:07 PM
  4. Novice trying to learn C++
    By dead in forum C++ Programming
    Replies: 10
    Last Post: 12-01-2003, 09:25 PM
  5. Wanna learn Assembly?
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 137
    Last Post: 06-29-2002, 01:49 AM