Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- bool f19 (int s, int p) {
- if (s >= 36 && p == 2) {
- return true;
- } else {
- if (s < 36 && p == 2) return false;
- if (s >= 36) return false;
- }
- return f19(s + 1, p + 1) || f19(s + 2, p + 1) || f19(s * 2, p + 1);
- }
- bool f20 (int s, int p) {
- if (s >= 36 && p == 3) {
- return true;
- } else {
- if (s < 36 && p == 3) return false;
- if (s >= 36) return false;
- }
- if (p % 2 != 0) return f20(s + 1, p + 1) && f20(s + 2, p + 1) && f20(s * 2, p + 1);
- return f20(s + 1, p + 1) || f20(s + 2, p + 1) || f20(s * 2, p + 1);
- }
- bool f21 (int s, int p) {
- if (s >= 36 && (p == 4 || p == 2)) {
- return true;
- } else {
- if (s < 36 && p == 4) return false;
- if (s >= 36) return false;
- }
- if (p % 2 == 0) return f21(s + 1, p + 1) && f21(s + 2, p + 1) && f21(s * 2, p + 1);
- return f21(s + 1, p + 1) || f21(s + 2, p + 1) || f21(s * 2, p + 1);
- }
- bool f21d (int s, int p) {
- if (s >= 36 && p == 2) {
- return true;
- } else {
- if (s < 36 && p == 2) return false;
- if (s >= 36) return false;
- }
- if (p % 2 == 0) return f21d(s + 1, p + 1) && f21d(s + 2, p + 1) && f21d(s * 2, p + 1);
- return f21d(s + 1, p + 1) || f21d(s + 2, p + 1) || f21d(s * 2, p + 1);
- }
- int main() {
- cout << "19: ";
- for (int i = 1; i <= 35; i++) {
- if (f19(i, 0)) {
- cout << i << endl;
- break;
- }
- }
- cout << "20: ";
- for (int i = 1; i <= 35; i++) {
- if (f20(i, 0)) {
- cout << i << " ";
- }
- }
- cout << endl << "21: ";
- for (int i = 1; i <= 35; i++) {
- if (f21(i, 0)) {
- cout << i << " ";
- }
- }
- cout << endl << "No 21: ";
- for (int i = 1; i <= 35; i++) {
- if (f21d(i, 0)) {
- cout << i << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement