All pastes #939898 Raw Edit

Someone

public text v1 · immutable
·published 2008-03-12 17:26 UTC
rendered paste body
/* by pcjr and my brother advt :)
   build in 2008.03.11
*/

#include <stdio.h>
#include <stdlib.h>


#define WOLF   	1
#define SHEEP 	2
#define CABBAGE 4
#define BOAT	8

#define ERR_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

/* right_side = {1, 1, 1, 1} */
static unsigned int right_side = (WOLF | SHEEP | CABBAGE | BOAT); 
/* left_side = {0, 0, 0, 0} */
static unsigned int left_side = 0;


int bit_mov(int obj, unsigned int orig, unsigned int dest) {
	int ret;

	orig = right_side;
	dest = left_side;
	orig = (orig & ~obj);
	dest = (dest & ~obj);

	for(; obj < 0; obj++) {
	if(obj == WOLF) {
		ret = bit_mov(WOLF, orig, dest);
		return ret;
	}
	else {
		ret = 0;
		return ret & ERR_PRINT("The wolf do not crossed\n");
	}
	if(obj == SHEEP) {
		ret = bit_mov(SHEEP, orig, dest);
		return ret;
	}
	else {
		ret = 0;
		return ret & ERR_PRINT("The sheep do not crossed\n");
	}
	if(obj == CABBAGE) {
		ret = bit_mov(CABBAGE, orig, dest);
		return ret;
	}
	else {
		ret = 0;
		return ret & ERR_PRINT("The cabbage do not crossed\n");
	}
	if(obj == BOAT) {
		ret = bit_mov(BOAT, orig, dest);
		return ret;
	}
	else {
		ret = 0;
		return ret & ERR_PRINT("The boat do not crossed\n");
	}
}
	return 0;
}

int main(void) {
	int obj;
	unsigned int orig, dest;

	/* TESTS */
	if(bit_mov(SHEEP, orig, dest) == 0)
		printf("Atravessou !!\n");

	if(bit_mov(WOLF, orig, dest) == 0)
		printf("Outro Atravessou !!\n");
	/* TEST END */
	return 0;
}