David Jann
Projekte
Hier finden Sie aktuelle Projekte und Spielereien.
projects
//Prime is King
//Rules
//ABC == Prime
//AB == Prime
// BC == Prime
#include<iostream>
#include<bits/stdc++.h> //Vector - Stuff
//Globale Variables
std::vector<int> numbers = {}; //all Primes
//Functions
bool test_2_digits (int digits);
int main() {
//Variables
std::vector<int> abc = {};
bool b_abc = false; //a Boolean for ABC
bool b_ab = false; //a Boolean for AB
bool b_bc = false; //a Boolean for BC
//Fill "numbers"
for (int i = 2; i < 1000; i++) {
numbers.push_back(i);
}
//Filter "numbers" => find all Primes till 999
for (int i = 0; i < numbers.size() - 1; i++) {
for (int j = 0; j < numbers.size() - 1; j++) {
if (numbers[j] % numbers[i] == 0 ^ numbers[i] == numbers[j]) {
numbers.erase(numbers.begin() + j);
}
}
//Test: Size of ABC == 3
if (numbers[i] > 100) {
b_abc = true;
}
//Test: AB is Prime
if (b_abc) {
b_ab = test_2_digits(numbers[i] / 10);
}
//Test: BC is Prime
if (b_ab) {
b_bc = test_2_digits(numbers[i] % 100);
}
//Push in Vector
if (b_bc) {
abc.push_back(numbers[i]);
}
//Reset Booleans
b_abc = false;
b_ab = false;
b_bc = false;
}
//Print the Primes
std::cout << "Primes left: \n";
for (int i = 0; i < abc.size(); i++) {
std::cout << abc[i] << "\t";
}
return 0;
}
//Compare AB/BC with proved 2-Digit-Primes
bool test_2_digits (int digits) {
int n = 0;
while (numbers[n] < 100) {
if (digits == numbers[n]) {
return true;
}
n++;
}
return false;
}