forked from dshamlin98/dshamlin98.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LNGI operator notation to general.html
222 lines (214 loc) · 8.5 KB
/
LNGI operator notation to general.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<body>
Running: <input type="checkbox" id="numberRunning" checked></input>
<button onclick="func1()">Reset to 0</button>
<button onclick="func2()">x2 Speed</button>
<button onclick="func3()">/2 Speed</button>
<button onclick="func4()">Increase precision</button>
<button onclick="func5()">Decrease precision</button>
<p>NUMBER:<br><font size="5" id="number"></font></p>
<script>
var t=0;
var tStep=1;
var tReduce=0;
function save() {
localStorage.setItem('beonlngi', JSON.stringify(t));
}
function load() {
if (localStorage.getItem('beonlngi')) {
t = JSON.parse(localStorage.getItem('beonlngi'));
}
}
function smoothCurve(fraction, lowerLimit, upperLimit, steepness) {
fraction = Math.max(Math.min(fraction, 1), 0);
steepness = 2;//Math.max(Math.min(steepness, 2), 2);
return lowerLimit-1+(upperLimit-lowerLimit+1)**((fraction+fraction**steepness*(steepness-1))/steepness)
}
var maxPrecisionDigits = 35;
var precisionDigits = maxPrecisionDigits;
var versionNum = 0;
var finishedArray = false;
function removeTrailingZerosInArray(Array) {
while (Array.includes(",0]")) {
Array = Array.replace(/,0\]/g, "]");
}
return Array;
}
function LinArraySolve(Array) { // Array is of the form ...[a,b,c,...](number)
// version: 1 = dont degenerate to 1 if (number) = 1
// [removed arrays][activeArray](numberArray)
// Array = "[1,3,5][0,2,2][0,2,2](3.4783)"
Array = removeTrailingZerosInArray(Array);
singleArray = Array.slice(Array.lastIndexOf("[")); // [0,2,2](3.4783)
removedArray = Array.slice(0, Array.lastIndexOf("[")); // [1,3,5][0,2,2]
numberArray = Number(singleArray.slice(singleArray.indexOf("(")+1, singleArray.indexOf(")"))); // 3.4783
if (isNaN(numberArray)) {
finishedArray = true;
return Array;
}
activeArray = singleArray.slice(singleArray.indexOf("[")+1, singleArray.indexOf("]")).split(","); // array: 0,2,2 numbers are strings
// Rule 1
if (activeArray[0]==1 && activeArray.length==1) {
if (numberArray < 10 && precisionDigits > 10) {
resultNumber=(10**numberArray);
if (resultNumber >= 10000) {
precisionDigits=0;//finishedArray = true;
}
return removedArray + "(" + resultNumber + ")";
} else if (numberArray < 10000 && precisionDigits > 28) {
//precisionDigits=0;
return removedArray + "(" + ((10**(numberArray%1)).toFixed(3) + "xe" + Math.floor(numberArray)) + ")"
} else {
//precisionDigits=0;
finishedArray = true;
return Array;
}
}
// Rule 2
sumOfEntriesInActiveArray = activeArray.reduce(function(a,b){return a - -b;}, 0);
if (activeArray[0] > 0 && numberArray>=1 && numberArray<2) { // Rule 2a
versionNum = 0;
activeArray[0] -= 1;
numberArray = smoothCurve(numberArray%1, 1, 10, sumOfEntriesInActiveArray);
precisionDigits -= 1+Math.log10(numberArray);
return removedArray + "[" + activeArray + "](" + numberArray + ")";
}
if (activeArray[0] > 0) { // Rule 2b
versionNum = 0;
if (numberArray>=10) {
//precisionDigits=0;
finishedArray = true;
return Array;
} else {
oldActiveArray = activeArray+"";
newActiveArray = activeArray;
newActiveArray[0] -= 1;
newNumberArray = numberArray;
newNumberArray -= Math.floor(numberArray-1);
return removedArray + ("[" + newActiveArray + "]").repeat(Math.floor(numberArray-1)) + "[" + oldActiveArray + "](" + newNumberArray + ")";
}
}
if (activeArray[0] == 0) { // Rule 3
currentEntry=0;
while (activeArray[currentEntry]==0){
currentEntry++;
} // current entry is first non0 entry
activeArray[currentEntry]--;
if (numberArray >= 2) {
activeArray[currentEntry-1] = Math.ceil(numberArray);
if (currentEntry==1) {
numberArray = smoothCurve(numberArray-Math.ceil(numberArray)+1, 2, 10, sumOfEntriesInActiveArray);
versionNum = 0;
precisionDigits -= Math.log10(numberArray);
} else {
numberArray = smoothCurve(numberArray-Math.ceil(numberArray)+1, 0, 10, sumOfEntriesInActiveArray);
versionNum = 1;
precisionDigits -= Math.log10(1+numberArray);
}
return removeTrailingZerosInArray(removedArray + "[" + activeArray + "](" + numberArray + ")");
} else if (numberArray >= 1 && numberArray < 2 && versionNum==0) {
activeArray[currentEntry-1] = 2;
numberArray = smoothCurve(numberArray%1, 1, 10, sumOfEntriesInActiveArray);
precisionDigits -= Math.log10(numberArray);
return removeTrailingZerosInArray(removedArray + "[" + activeArray + "](" + numberArray + ")");
} else if (numberArray < 2 && versionNum==1) {
if (currentEntry < 1) {versionNum = 0;}
activeArray[currentEntry-1] = Math.ceil(numberArray);
if (currentEntry>1) {
numberArray = smoothCurve(numberArray-Math.ceil(numberArray)+1, 0, 10, sumOfEntriesInActiveArray);
precisionDigits -= Math.log10(1+numberArray);
} else {
numberArray = smoothCurve(numberArray-Math.ceil(numberArray)+1, 2, 10, sumOfEntriesInActiveArray);
precisionDigits -= Math.log10(numberArray);
}
return removeTrailingZerosInArray(removedArray + "[" + activeArray + "](" + numberArray + ")");
}
}
}
function evaluateLinArray(Array) {
finishedArray = false;
precisionDigits = maxPrecisionDigits;
Array = LinArraySolve(Array);
while ((precisionDigits > 0 || !Array.includes("][")) && !Array.includes("e") && !finishedArray &&Array.length<400) {
Array = LinArraySolve(Array);
}
numberArray = Number(Array.slice(Array.indexOf("(")+1, Array.indexOf(")"))); // 1.234
if (isNaN(numberArray)) {return Array;}
if (numberArray >= 2) {
if (precisionDigits > 26) {
numberArray = numberArray.toFixed(3);
} else if (precisionDigits > 22) {
numberArray = numberArray.toFixed(2);
} else if (precisionDigits > 20) {
numberArray = numberArray.toFixed(1);
} else {
numberArray = Math.floor(numberArray);
}
return Array.slice(0,Array.indexOf("(")) + "(" + numberArray + ")";
} else {
return Array.slice(0,Array.lastIndexOf("[")) + "(10)";
}
return Array;
}
function linArrayEntries(number) {
versionNum = 1;
return "[" + "0,".repeat(Math.floor(number)) + "1](" + smoothCurve(number%1, 1, 10, 1) + ")";
}
function convertOnceToLAN(Array) { // [1,2,3][2,4][3,3](12)
//Array = Array.replace("(","").replace(")","");
removedArray = Array.slice(0, Array.lastIndexOf("[")); // [1,2,3][2,4]
partialArray = Array.slice(Array.lastIndexOf("[")+1, Array.lastIndexOf("]")).split(","); // 3,3 (array)
lastNumberArray = Array.slice(Array.indexOf("(")+1,Array.indexOf(")")); // 12
if (partialArray.length < 3) {
if (partialArray.length < 2) { partialArray[1] = 0; }
partialArray[1]++;
if (partialArray[0] > 0) {
return removedArray+"(10"+"\u200b"+"{".repeat(partialArray[1])+partialArray[0]+"}".repeat(partialArray[1])+"\u200b"+lastNumberArray+")";
} else {
return removedArray+"(10"+"\u200b"+"{".repeat(partialArray[1]-1)+lastNumberArray+"}".repeat(partialArray[1]-1)+"\u200b"+"10)";
}
}
}
function convertToLAN(Array) {
currentArray = Array
while (currentArray.includes("[")) {
currentArray = convertOnceToLAN(currentArray);
}
currentArray = currentArray.replace(/\{1\}/g,"^").replace(/\{2\}/g,"^^").replace(/\{3\}/g,"^^^").replace(/\{4\}/g,"^^^^").replace(/\{\^\}/g,"{{1}}").replace(/\{\^\^\}/g,"{{2}}").replace(/\{\^\^\^\}/g,"{{3}}").replace(/\{\^\^\^\^\}/g,"{{4}}")
return currentArray.replace("(","").replace(")","").replace("xe","e");
}
load();
function displayNumber() {
tReduce = 0;
if (t < 5000) {
finalNumber = Math.floor(t/50);
} else if (t >= 5000 && t < 100000){
finalNumber = Math.floor(10**(2+8*((t-5000)/95000)));
} else if (t >= 100000 && t < 10000000) {
finalNumber = convertToLAN(evaluateLinArray(linArrayEntries(1+Math.log10(1+(t-100000)/1100000)**0.8)));
} else if (t >= 10000000 && t < 60000000) {
finalNumber = convertToLAN(evaluateLinArray(linArrayEntries(Math.min(2+((t-10000000)/50000000)**0.9,3))));
while (finalNumber == "10" && 2+((t-10000000)/50000000)**0.9 > 1) {
tReduce++;
finalNumber = convertToLAN(evaluateLinArray(linArrayEntries(2+Math.max(((t-10000000-tReduce)/50000000),0)**0.9)));
}
} else {
finalNumber = "10{{{{{{{{{{10}}}}}}}}}}10 (limit)"
}
if (document.getElementById("numberRunning").checked) {
t+=tStep;
}
finalNumber // for unan
document.getElementById("number").innerHTML = finalNumber;
}
setInterval(displayNumber, 15);
setInterval(save, 100);
function func1() {t=0}
function func2() {tStep*=2}
function func3() {tStep/=2}
function func4() {maxPrecisionDigits+=1}
function func5() {maxPrecisionDigits-=1}
</script>
</body>
</html>