Skip to content

Instantly share code, notes, and snippets.

@theortsac
Created November 6, 2023 14:51
Show Gist options
  • Save theortsac/cde31bf4bee223abf07499ddc17852d9 to your computer and use it in GitHub Desktop.
Save theortsac/cde31bf4bee223abf07499ddc17852d9 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
char dict[8] = {'-', '>', '.', ']', '<', '+', '[', ','};
void sieve(int n)
{
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p) {
prime[i] = false;
}
}
}
for (int p = 2; p <= n; p++) {
if (prime[p] ) primes.push_back(p);
}
}
string multiply(string num1, string num2)
{
int len1 = num1.size();
int len2 = num2.size();
if (len1 == 0 || len2 == 0)
return "0";
vector<int> result(len1 + len2, 0);
int i_n1 = 0;
int i_n2 = 0;
for (int i=len1-1; i>=0; i--)
{
int carry = 0;
int n1 = num1[i] - '0';
i_n2 = 0;
for (int j=len2-1; j>=0; j--)
{
int n2 = num2[j] - '0';
int sum = n1*n2 + result[i_n1 + i_n2] + carry;
carry = sum/10;
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
if (carry > 0)
result[i_n1 + i_n2] += carry;
i_n1++;
}
int i = result.size() - 1;
while (i>=0 && result[i] == 0)
i--;
if (i == -1)
return "0";
string s = "";
while (i >= 0)
s += std::to_string(result[i--]);
return s;
}
int main()
{
sieve(1000000);
string s = "brainfuck goes here";
int i = 0;
string ans = "1";
for (auto u : s) {
int index = 0;
while (dict[index] != u) {
index++;
}
string prime_pow = to_string(primes[i]);
while (index--) {
prime_pow = multiply(prime_pow, to_string(primes[i]));
}
ans = multiply(ans, prime_pow);
i++;
}
cout << ans << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment