Anonymous Anonymous - 11 months ago
1007 0

poging voor opgave 5 aivd puzzel

C++

opgave5.c

#include <iostream>
#include <string>
#include <vector>
#include <string>

using namespace std;

char letters[13] = { 'A', 'B', 'D', 'E', 'G', 'H', 'I', 'L', 'N', 'O', 'S', 'T', 'U' }; 
int waardes[13] = { 188461, 565383, 696149, 88447, 265341, 796023, 388069, 164207, 492621, 477863, 433589, 300767, 902301 }; 

int input = 0;
int puzzels[13] = { 696318, 994738, 186634, 937474, 818450, 387210, 184092, 377231,  999091, 293830, 725605, 893049, 394922 };
int diepte = 6;

vector<string> resultaten;

bool check(int nummer) {
	auto tmp = to_string(nummer);
	if (tmp.length() >= 6) {
		return (tmp).substr((tmp).length() - 6) == to_string(input);
	} else {
		return false;
	}
}

bool lessLength (const string& s1, const string& s2)
{
    return s1.length() < s2.length();
}

int dieper(int pogingvorig, vector<int> index) {
	size_t nI;
	for (nI=0; waardes[nI]!=0; nI++) {

		int poging = 0;
		poging = pogingvorig + waardes[nI];

		vector<int> index_(index);

		index_.push_back(nI);

		if (check(poging)) {
			
			string resultaat;
			size_t nX;
			for (auto i: index_)
  				resultaat += letters[i];
			
			resultaten.push_back(resultaat);
			
		} else {
			if (index_.size() < diepte) {
				dieper(poging, index_);
			}
		}

	}
	return 0;
}

int main() {
	for (auto p : puzzels) {
		input = p;

		cout << "PUZZEL: " << input << "\n\n";
		vector<int> start;

		dieper(0, start);

		sort(resultaten.begin(), resultaten.end());
		sort(resultaten.begin(), resultaten.end(), lessLength);  
		
		size_t nI;
		for(auto i : resultaten) {
			cout << i << "\n";
		} 

		cout << "\n\n";


	}
	
	return 0;
}
Python

vergelijk_woordenboek.py

#https://raw.githubusercontent.com/titoBouzout/Dictionaries/master/Dutch.dic

with open('resultaten.txt', 'r') as file1:
	with open('woordenboek', 'r') as file2:
		same = set(file1).intersection(file2)

same.discard('\n')

with open('matches.txt', 'w') as file_out:
	for line in same:
		file_out.write(line)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download