Commit edaf972b authored by Simon Wüllhorst's avatar Simon Wüllhorst

Quick & Dirty 92 solutions

parents
/*
============================================================================
Name : ad_pk_2.c
Author : S. Wüllhorst
Version :
Copyright : foo bar
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
void ausgabe(int brett[8], int *optcount){
int i = 0, j = 0;
int max = 8;
printf("-----------------\n");
printf("Nr: %d\n", *optcount);
for(;i < max; ++i){
j = 0;
for(;j < max; ++j){
if(brett[i] == j){
printf("|D");
}else{
printf("| ");
}
}
printf("|\n");
}
}
int bedroht(int brett[8], int level, int maxlevel, int position){
--level;
int diff = maxlevel - level;
if(brett[level] == position){
return 1;
}else if(brett[level] == position-diff || brett[level] == position+diff){
return 1;
}else{
if(level > 0){
return bedroht(brett,level,maxlevel, position);
}else{
return 0;
}
}
}
void setze(int brett[8], int level, int *optcount){
++level;
int i = 0;
int max = 8;
for(;i<max;++i){
if(bedroht(brett,level,level, i) == 0){
brett[level] = i;
if(level == max-1){
++(*optcount);
ausgabe(brett, optcount);
}else{
setze(brett,level, optcount);
}
}
}
//return 0;
}
void dame_meta(){
int brett[8] = {-1};
int i = 0;
int max = 8;
int optcount = 0;
for(;i<max;++i){
brett[0] = i;
setze(brett,0,&optcount);
}
}
int main(void) {
dame_meta();
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment