4/src/4.c
char *solve(struct puzzle_input *input, int part) {
	char *ret;
	int answer, i, j, k, valid;

	answer = 0;
	for (i = 0; i < input->passphrase_count; i++) {
		valid = 1;
		for (j = 0; j < input->passphrases[i]->word_count; j++) {
			for (k = 0; k < input->passphrases[i]->word_count; k++) {
				if (j == k) {
					continue;
				}
				if (strcmp(input->passphrases[i]->words[j], input->passphrases[i]->words[k]) == 0 || (part == 2 && strcmp(input->passphrases[i]->alpha_words[j], input->passphrases[i]->alpha_words[k]) == 0)) {
					valid = 0;
					break;
				}
			}
			if (!valid) {
				break;
			}
		}
		if (valid) {
			answer++;
		}
	}

	ret = malloc(16);
	snprintf(ret, 16, "%d", answer);
	return ret;
}
// Parts 1 and 2 are similar enough to use the same function for both parts.
Parts 1 and 2 are similar enough to use the same function for both parts.
Parts 1 and 2 are similar enough to use the same function for both parts .
char *solve(struct puzzle_input *input, int part) {
	char *ret;
	int answer, i, j, k, valid;
	answer = 0;
	for (i = 0; i < input->passphrase_count; i++) {
		valid = 1;
		for (j = 0; j < input->passphrases[i]->word_count; j++) {
			for (k = 0; k < input->passphrases[i]->word_count; k++) {
				if (j == k) {
					continue;
				}
				if (strcmp(input->passphrases[i]->words[j], input->passphrases[i]->words[k]) == 0 || (part == 2 && strcmp(input->passphrases[i]->alpha_words[j], input->passphrases[i]->alpha_words[k]) == 0)) {
					valid = 0;
					break;
				}
			}
			if (!valid) {
				break;
			}
		}
		if (valid) {
			answer++;
		}
	}
	ret = malloc(16);
	snprintf(ret, 16, "%d", answer);
	return ret;
}
char * solve ( struct puzzle_input * input , int part ) { char * ret ; int answer , i , j , k , valid ; answer = 0 ; for ( i = 0 ; i < input -> passphrase_count ; i ++ ) { valid = 1 ; for ( j = 0 ; j < input -> passphrases [ i ] -> word_count ; j ++ ) { for ( k = 0 ; k < input -> passphrases [ i ] -> word_count ; k ++ ) { if ( j == k ) { continue ; } if ( strcmp ( input -> passphrases [ i ] -> words [ j ] , input -> passphrases [ i ] -> words [ k ] ) == 0 || ( part == 2 && strcmp ( input -> passphrases [ i ] -> alpha_words [ j ] , input -> passphrases [ i ] -> alpha_words [ k ] ) == 0 ) ) { valid = 0 ; break ; } } if ( ! valid ) { break ; } } if ( valid ) { answer ++ ; } } ret = malloc ( 16 ) ; snprintf ( ret , 16 , " " , answer ) ; return ret ; }
Parts 1 and 2 are similar enough to use the same function for both parts.
Parts 1 and 2 are similar enough to use the same function for both parts .