Number

From Esolang
Jump to navigation Jump to search

Introduction

Number is a joke language.

Command

Any number can be a command. This language is output only.

The output can only contain these characters: [Space]!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~, which is all the characters visible in the ASCII table.

The number means the number-th string in this order.

  • If string a is shorter than string b, a is in front of b.
  • If a's first char is the same as b's, compare the second char. If a's second char is smaller than b's, a is in front of b.
  • If a's first n chars are the same as b's, compare the n+1-th char. If a's n+1-th char is smaller than b's, a is in front of b.

e.g. 1 - [Space], 95 - ~, 96 - [Space][Space]

There is a table for number from 1 to 866495 here.[1]

Output to program

The program under written in C++ can translate the output into the program.

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 20100
string n,final = "";
int ans = 0,i = 1,a,b;
struct bigNumber {
	int len, x[N];
	bigNumber() {
		memset(x, 0, sizeof(x));
		len = 1;
	}
	void write() {
		for (int i = len; i > 0; --i) {
			printf("%d", x[i]);
		}
	}
};
bigNumber fix(bigNumber a) {
	for (int i = 1; i < a.len; ++i) {
		if (a.x[i] < 0)
			a.x[i] += 10, a.x[i + 1]--;
		a.x[i + 1] += a.x[i] / 10;
		a.x[i] %= 10;
	}
	while (a.x[a.len] >= 10) {
		a.x[a.len + 1] += a.x[a.len] / 10;
		a.x[a.len] %= 10;
		a.len++;
	}
	while (!a.x[a.len] && a.len > 1)
		a.len--;
	return a;
}
inline bool operator < (bigNumber a, bigNumber b) {
	if (a.len != b.len)
		return a.len < b.len;
	for (int i = a.len; i > 0; --i)
		if (a.x[i] != b.x[i])
			return a.x[i] < b.x[i];
	return 0;
}
inline bool operator <= (bigNumber a, bigNumber b) {
	if (a.len != b.len)
		return a.len < b.len;
	for (int i = a.len; i > 0; --i)
		if (a.x[i] < b.x[i])
			return 1;
		else if (a.x[i] > b.x[i])
			return 0;
	return 1;
}
inline bigNumber operator + (bigNumber a, int b) {
	a.x[1] += b;
	return fix(a);
}
inline bigNumber operator + (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = max(a.len, b.len);
	for (int i = 1; i <= c.len; ++i)
		c.x[i] = a.x[i] + b.x[i];
	return fix(c);
}
inline bigNumber operator - (bigNumber a, int b) {
	a.x[1] -= b;
	return fix(a);
}
inline bigNumber operator - (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = max(a.len, b.len) + 1;
	for (int i = 1; i <= c.len; ++i)
		c.x[i] = a.x[i] - b.x[i];
	return fix(c);
}
inline bigNumber operator * (bigNumber a, int b) {
	for (int i = 1; i <= a.len; ++i)
		a.x[i] *= b;
	return fix(a);
}
inline bigNumber operator * (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = a.len + b.len - 1;
	for (int i = 1; i <= a.len; ++i)
		for (int j = 1; j <= b.len; ++j)
			c.x[i + j - 1] += a.x[i] * b.x[j];
	return fix(c);
}
inline bigNumber operator / (bigNumber a, int b) {
	int x = 0;
	bigNumber c;
	c.len = a.len;
	for (int i = c.len; i > 0; --i) {
		c.x[i] = (x * 10 + a.x[i]) / b;
		x = (x * 10 + a.x[i]) % b;
	}
	return fix(c);
}
inline bigNumber operator / (bigNumber a, bigNumber b) {
	bigNumber c ;
	int s = 0 ;
	while (a.len > b.len)
		b = b * 10, s++ ;
	while (s >= 0) {
		c = c * 10 ;
		while (b <= a)
			c = c + 1, a = a - b;
		b = b / 10, s-- ;
	}
	return fix(c) ;
}
inline bigNumber operator % (bigNumber a, int b) {
	bigNumber c = a / b;
	a = a - c * b;
	return fix(a);
}
inline bigNumber operator % (bigNumber a, bigNumber b) {
	int s = 0;
	while (a.len > b.len)
		b = b * 10, s++;
	while (s >= 0) {
		while (b <= a)
			a = a - b;
		b = b / 10, s--;
	}
	return fix(a);
}
bigNumber read(){
	string S;
	bigNumber a;
	cin >> S;
	for (int i = 1; i <= S.size(); ++i)
		a = a * 10 + (int)(S[i - 1] - '0');
	return a;
}

bigNumber s_to_i(string s)
{
	bigNumber num;
	for(int i = 0;s[i];++i)
		num = num * 95 + (s[i] - ' ');
	return num;
}

signed main(){
	getline(cin, n);
	s_to_i(n).write();
	return 0;
}

Example

Hello, World!

22011474394810164197455861

Interpreter

C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 20100
string n,final = "";
int ans = 0,i = 1,a,b;
struct bigNumber {
	int len, x[N];
	bigNumber() {
		memset(x, 0, sizeof(x));
		len = 1;
	}
	void write() {
		for (int i = len; i > 0; --i) {
			printf("%d", x[i]);
		}
	}
};
bigNumber fix(bigNumber a) {
	for (int i = 1; i < a.len; ++i) {
		if (a.x[i] < 0)
			a.x[i] += 10, a.x[i + 1]--;
		a.x[i + 1] += a.x[i] / 10;
		a.x[i] %= 10;
	}
	while (a.x[a.len] >= 10) {
		a.x[a.len + 1] += a.x[a.len] / 10;
		a.x[a.len] %= 10;
		a.len++;
	}
	while (!a.x[a.len] && a.len > 1)
		a.len--;
	return a;
}
inline bool operator < (bigNumber a, bigNumber b) {
	if (a.len != b.len)
		return a.len < b.len;
	for (int i = a.len; i > 0; --i)
		if (a.x[i] != b.x[i])
			return a.x[i] < b.x[i];
	return 0;
}
inline bool operator <= (bigNumber a, bigNumber b) {
	if (a.len != b.len)
		return a.len < b.len;
	for (int i = a.len; i > 0; --i)
		if (a.x[i] < b.x[i])
			return 1;
		else if (a.x[i] > b.x[i])
			return 0;
	return 1;
}
inline bool operator == (bigNumber a, bigNumber b) {
	return (a <= b && b <= a);
}
inline bool operator > (bigNumber a, bigNumber b) {
	return b < a;
}
inline bool operator >= (bigNumber a, bigNumber b) {
	return b <= a;
}
inline bigNumber operator + (bigNumber a, int b) {
	a.x[1] += b;
	return fix(a);
}
inline bigNumber operator + (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = max(a.len, b.len);
	for (int i = 1; i <= c.len; ++i)
		c.x[i] = a.x[i] + b.x[i];
	return fix(c);
}
inline bigNumber operator - (bigNumber a, int b) {
	a.x[1] -= b;
	return fix(a);
}
inline bigNumber operator - (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = max(a.len, b.len) + 1;
	for (int i = 1; i <= c.len; ++i)
		c.x[i] = a.x[i] - b.x[i];
	return fix(c);
}
inline bigNumber operator * (bigNumber a, int b) {
	for (int i = 1; i <= a.len; ++i)
		a.x[i] *= b;
	return fix(a);
}
inline bigNumber operator * (bigNumber a, bigNumber b) {
	bigNumber c;
	c.len = a.len + b.len - 1;
	for (int i = 1; i <= a.len; ++i)
		for (int j = 1; j <= b.len; ++j)
			c.x[i + j - 1] += a.x[i] * b.x[j];
	return fix(c);
}
inline bigNumber operator / (bigNumber a, int b) {
	int x = 0;
	bigNumber c;
	c.len = a.len;
	for (int i = c.len; i > 0; --i) {
		c.x[i] = (x * 10 + a.x[i]) / b;
		x = (x * 10 + a.x[i]) % b;
	}
	return fix(c);
}
inline bigNumber operator / (bigNumber a, bigNumber b) {
	bigNumber c ;
	int s = 0 ;
	while (a.len > b.len)
		b = b * 10, s++ ;
	while (s >= 0) {
		c = c * 10 ;
		while (b <= a)
			c = c + 1, a = a - b;
		b = b / 10, s-- ;
	}
	return fix(c) ;
}
inline bigNumber operator % (bigNumber a, int b) {
	bigNumber c = a / b;
	a = a - c * b;
	return fix(a);
}
inline bigNumber operator % (bigNumber a, bigNumber b) {
	int s = 0;
	while (a.len > b.len)
		b = b * 10, s++;
	while (s >= 0) {
		while (b <= a)
			a = a - b;
		b = b / 10, s--;
	}
	return fix(a);
}
bigNumber read(){
	string S;
	bigNumber a;
	cin >> S;
	for (int i = 1; i <= S.size(); ++i)
		a = a * 10 + (int)(S[i - 1] - '0');
	return a;
}

bigNumber s_to_i(string s)
{
	bigNumber num;
	for(int i = 0;s[i];++i)
		num = num * 95 + (s[i] - ' ');
	return num;
}

string i_to_s(bigNumber x)
{
	const bigNumber zero;
	string s = "";
	if(x == zero) return " ";
	while(zero < x) {
		for(int i = 0; i < 95; i++)
			if(zero + i == x % 95)
				s += ' ' + i;
		x = x / 95;
	}
	reverse(s.begin(),s.end());
	
	return s;
}
bigNumber x;
signed main(){
	x = read();
	cout << i_to_s(x);
	return 0;
}