Skip to content

Instantly share code, notes, and snippets.

#include <any>
#include <print>
#include <string>
using namespace std;
#pragma GCC diagnostic ignored "-Wnon-template-friend"
template<class... Ts>
class A {
public:
I'm changing `auto x` and `auto y` to `auto a` and `auto b` because `x` shows up in a lot of places and isn't the same name: https://godbolt.org/z/9x5dvcofY
Lines 27 and 28:
auto a = AffineType{};
auto b = AffineType{};
Because AffineType is templated on `InstanceIdentifier` but a template argument isn't provided, the compiler must deduce what it is templated on. There is a default value, which is a lambda. Each lambda is a *unique value*, so the type of `a` and `b` is different - `a = b;` would also be a compiler error. I will be calling those lambda values `LV1` and `LV2`, and so those lines are actually:
27: AffineType<LV1> a{};
#include <any>
#include <print>
#include <string>
#include<bits/stdc++.h>
using namespace std;
struct poly_base {
virtual void operator()(std::vector<std::any> args) = 0;
virtual ~poly_base()=default;
};
#include <any>
#include <print>
#include <string>
#include <type_traits>
using namespace std;
#pragma GCC diagnostic ignored "-Wnon-template-friend"
template <class T, class... Ts>
class A : A<Ts...> {
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
string s =
"08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n\
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00\n\
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65\n\
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91\n\
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80\n\
@dgodfrey206
dgodfrey206 / Summation of Primes.cpp
Created February 11, 2026 01:11
Find the sum of all the primes below two million.
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 2e6;
long long sum = 2;
for (int i = 3; i < n; i += 2) {
bool prime = true;
for (int j = 2; j * j <= i; j++) {
@dgodfrey206
dgodfrey206 / Special Pythagorean Triplet.cpp
Created February 11, 2026 00:43
There exists exactly one Pythagorean triplet for which a+b+c=100. Find the product abc.
#include <bits/stdc++.h>
using namespace std;
// find two numbers who's squares, when added, equal a number whose square root, plus those two numbers equals 1000
int main() {
cout << []{
int n = 1000;
for (int a = 1; a <= n; a++) {
for (int b = a + 1; b <= n; b++) {
@dgodfrey206
dgodfrey206 / Largest Product in a Series.cpp
Created February 10, 2026 17:47
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
#include <bits/stdc++.h>
using namespace std;
string num = "73167176531330624919225119674426574742355349194934\
96983520312774506326239578318016984801869478851843\
85861560789112949495459501737958331952853208805511\
12540698747158523863050715693290963295227443043557\
66896648950445244523161731856403098711121722383113\
62229893423380308135336276614282806444486645238749\
30358907296290491560440772390713810515859307960866\
@dgodfrey206
dgodfrey206 / 10001st Prime.cpp
Created February 10, 2026 17:13
What is the 10001st prime number?
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 10001;
int limit = n/2;
vector<int> prime;
while (true) {
@dgodfrey206
dgodfrey206 / sum_square_difference.cpp
Created February 10, 2026 15:49
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 100;
int result = (n * (n + 1) * (3 * n * (n + 1) - 2 * (2 * n + 1)))/12;
cout << result;
}