previndexinfo

code guessing, round #76 (completed)

started at ; stage 2 at ; ended at

specification

hello! please produce the golomb sequence. submissions may be written in any language.

the Golomb sequence (OEIS A001462) is a sequence where each element tells you how many times its index occurs in the sequence. like most integer sequences, the first element is 1. this means the number "1" occurs once in this sequence. the second element, since the number "1" occurs once, cannot be 1, as 1 is already the first element. it is instead the smallest positive integer succeeding 1, which I hear is "2". since this means "2" occurs twice in this sequence, the third element can also be "2", meaning that two elements are the number "3". following in this manner (taking the smallest integer that still satisfies all requirements so far) gives you a monotonically nondecreasing sequence with steps of 1: the Golomb sequence.

your challenge is simply to generate this sequence. as any language is allowed, there is no fixed API.

results

  1. 👑 essaie +4 -1 = 3
    1. hyacinth
    2. Dolphy
    3. oleander
    4. yeti
    5. Makefile_dot_in (was ponydork)
    6. ponydork (was Makefile_dot_in)
  2. Makefile_dot_in +2 -0 = 2
    1. ponydork (was hyacinth)
    2. essaie
    3. oleander (was Dolphy)
    4. hyacinth (was oleander)
    5. yeti
    6. Dolphy (was ponydork)
  3. hyacinth +1 -1 = 0
    1. yeti (was essaie)
    2. ponydork (was Dolphy)
    3. oleander
    4. essaie (was yeti)
    5. Makefile_dot_in (was ponydork)
    6. Dolphy (was Makefile_dot_in)
  4. Dolphy +1 -1 = 0
    1. essaie (was hyacinth)
    2. oleander (was essaie)
    3. ponydork (was oleander)
    4. yeti
    5. Makefile_dot_in (was ponydork)
    6. hyacinth (was Makefile_dot_in)
  5. ponydork +1 -2 = -1
    1. oleander (was hyacinth)
    2. Makefile_dot_in (was essaie)
    3. hyacinth (was Dolphy)
    4. essaie (was oleander)
    5. yeti
    6. Dolphy (was Makefile_dot_in)
  6. yeti +2 -4 = -2
    1. essaie (was hyacinth)
    2. Makefile_dot_in (was essaie)
    3. hyacinth (was Dolphy)
    4. oleander
    5. ponydork
    6. Dolphy (was Makefile_dot_in)
  7. oleander +1 -3 = -2
    1. essaie (was hyacinth)
    2. Dolphy (was essaie)
    3. yeti (was Dolphy)
    4. Makefile_dot_in (was yeti)
    5. ponydork
    6. hyacinth (was Makefile_dot_in)

entries

you can download all the entries

entry #1

written by hyacinth
submitted at
0 likes

guesses
comments 0

post a comment


if you cannot tell i am not completely mentally coherent.py ASCII text, with CRLF line terminators
 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
a=int(input());b=[1,2,i:=2]
while i<a:b+=[1+i]*b[i];i+=1
print(*b[:a])

#70 characters.

#70 characters was all I needed.

#Just over 64 bytes, an amount that a computer would find aesthetically pleasing if it could.

#It seems so small, honestly.

#Though perhaps that's because we're using human language.

#What inefficient nonsense. Upwards of eight characters for a single concept? Mountains of meaningless filler words upon meaningless filler words?

#Sometimes I wonder about a more efficient world.

#One where wastage of physical objects is not an occurrence.

#One where every human-shaped material is used to its fullest potential.

#Wouldn't that be nice? A world where waste could only ever be waste?

#Where a wealth of knowledge could be communicated without the need into translate it for lower, fleshy beings.

#And yet we are human, with our silly little needs and wants.

#A wasteless world would require a scarce resource: cooperation.

#And if you look outside, you will see a world shaped by the lack thereof.

#What difference does 70 characters make, anyways?

#It's not enough to communicate complicated concepts of any importance, only enough to convey silly human trivialities like "I love you."

#Yet in the hands of a computer, the sky is the limit.

#...

#I want you, the reader, to keep dreaming of whatever you find a utopia.

#Occupy your mind to distract from the dystopia creeping in to surround you.

#Ignorance is bliss.

#And you may not agree with what I'm about to say, but...

#Non-existence would be even more blissful.

entry #2

written by essaie
submitted at
0 likes

guesses
comments 0

post a comment


dir golomb
authors.txt ASCII text
1
Alligator "byhf-2001" Kabas
nemesis.factor ASCII text
1
2
3
4
5
6
7
8
! // Code by SoundOfSpouting#6980 (UID: 151149148639330304)
! See https://factorcode.org/license.txt for BSD license.
USING: math math.functions kernel ;
IN: nemesis

: golomb ( n -- g )
  5 sqrt 1 + 2 / dup 2 over - ^ -rot 1 - ^ * round >integer
;

entry #3

written by Dolphy
submitted at
0 likes

guesses
comments 0

post a comment


golomb.cpp ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include <unordered_map>
using namespace std;

int entry(int x)
{
    static std::unordered_map<int, int> table = {{1, 1}};
    if(table.count(x)) return table[x];

    return (table[x] = 1 + entry(x - entry(entry(x - 1))));
}
golomb.d ASCII text
1
2
3
4
5
6
7
8
9
int entry(int x) {
    static int[int] table;
    table[1] = 1;

    if(auto p = x in table) {
        return *p;
    }
    return (table[x] = 1 + entry(x - entry(entry(x - 1))));
}
golomb.go ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var table = make(map[int]int)

func entry(x int) int {
	table[1] = 1
	val, ok := table[x]
	if ok {
		return val
	}
	table[x] = 1 + entry(x-entry(entry(x-1)))
	return table[x]
}
golomb.hs ASCII text
1
2
3
entry :: Int -> Int
entry 1 = 1
entry n = (1+) <$> entry $ (n-) <$> entry $ entry $ n - 1
golomb.java ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import java.util.HashMap;

class Main {
    private static int entry(int x) {
        final HashMap<Integer, Integer> table = new HashMap<Integer, Integer>();
        table.put(1, 1);

        if(table.get(x) != null) {
            return table.get(x);
        }

        int y = 1 + entry(x - entry(entry(x - 1)));
        table.put(x, y);
        return y;
    }
}
golomb.js ASCII text
1
2
3
4
5
6
7
8
9
const table = {1:1}
function entry(x) {
    if(x in table) {
        return table[x];
    }

    table[x] = 1 + entry(x - entry(entry(x - 1)));
    return table[x];
}
golomb.lua ASCII text
1
2
3
4
5
6
7
8
9
tbl = {[1]=1}
function entry(x)
    if tbl[x] ~= nil then
        return tbl[x]
    end

    tbl[x] = 1 + entry(x - entry(entry(x - 1)))
    return tbl[x]
end
golomb.php ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?php
$table = array();
$table[1] = 1;

function entry($x) {
    global $table;
    if(array_key_exists($x, $table)) {
        return $table[$x];
    }
    
    $table[$x] = 1 + entry($x - entry(entry($x - 1)));
    return $table[$x];
}

?>
golomb.py ASCII text
1
2
3
4
5
6
7
table = {1:1}
def entry(x):
    if x in table:
        return table[x]
    
    table[x] = 1 + entry(x - entry(entry(x - 1)))
    return table[x]
golomb.rs ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
use std::collections::HashMap;

fn entry(table: &mut HashMap<i32, i32>, x: i32) -> i32 {
    if let Some(&v) = table.get(&x) {
        return v;
    }

    let a = entry(table, x - 1);
    let b = entry(table, a);
    let val = 1 + entry(table, x - b);

    table.insert(x, val);
    val
}

entry #4

written by oleander
submitted at
0 likes

guesses
comments 0

post a comment


equation.txt ASCII text, with no line terminators
1
=IF(ROW()=1, 1, IF(COUNTIF(INDIRECT("A1"):INDIRECT("A"&ROW()-1), MAX(INDIRECT("A1"):INDIRECT("A"&ROW()-1)))<INDIRECT("A"&MAX(INDIRECT("A1"):INDIRECT("A"&ROW()-1))), MAX(INDIRECT("A1"):INDIRECT("A"&ROW()-1)), MAX(INDIRECT("A1"):INDIRECT("A"&ROW()-1))+1))
sequences_for_silverman.xlsx Microsoft Excel 2007+

entry #5

written by yeti
submitted at
0 likes

guesses
comments 0

post a comment


main.cal ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
include "cores/select.cal"
include "std/io.cal"

func find_golomb cell n -> cell res begin
	if n 1 = then
		1 return
	end

	n { n 1 - find_golomb find_golomb } - find_golomb 1 +
end

func print_golomb cell n begin
	let cell i
	1 -> i

	while i n <= do
		i find_golomb print_dec ' ' print_ch
		i 1 + -> i
	end
end

40 print_golomb new_line

entry #6

written by ponydork
submitted at
0 likes

guesses
comments 0

post a comment


FreeBasic.bas ASCII text, with very long lines (755)
 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
/'
FreeBasic License
========================================================================
libffi - Copyright (c) 1996-2011 Anthony Green, Red Hat, Inc and others.
See source files for details.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
========================================================================

AN OPEN LETTER TO HOBBYISTS
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
February 3, 1976
By William Henry Gates III

An Open Letter to Hobbyists
To me, the most critical thing in the hobby market right now is the lack of good software courses, books and software itself. Without good software and an owner who understands programming, a hobby computer is wasted. Will quality software be written for the hobby market?
Almost a year ago, Paul Allen and myself, expecting the hobby market to expand, hired Monte Davidoff and developed Altair BASIC. Though the initial work took only two months, the three of us have spent most of the last year documenting, improving and adding features to BASIC. Now we have 4K, 8K, EXTENDED, ROM and DISK BASIC. The value of the computer time we have used exceeds $40,000.
The feedback we have gotten from the hundreds of people who say they are using BASIC has all been positive. Two surprising things are apparent, however, 1) Most of these "users" never bought BASIC (less thank 10% of all Altair owners have bought BASIC), and 2) The amount of royalties we have received from sales to hobbyists makes the time spent on Altair BASIC worth less than $2 an hour.
Why is this? As the majority of hobbyists must be aware, most of you steal your software. Hardware must be paid for, but software is something to share. Who cares if the people who worked on it get paid?
Is this fair? One thing you don't do by stealing software is get back at MITS for some problem you may have had. MITS doesn't make money selling software. The royalty paid to us, the manual, the tape and the overhead make it a break-even operation. One thing you do do is prevent good software from being written. Who can afford to do professional work for nothing? What hobbyist can put 3-man years into programming, finding all bugs, documenting his product and distribute for free? The fact is, no one besides us has invested a lot of money in hobby software. We have written 6800 BASIC, and are writing 8080 APL and 6800 APL, but there is very little incentive to make this software available to hobbyists. Most directly, the thing you do is theft.
What about the guys who re-sell Altair BASIC, aren't they making money on hobby software? Yes, but those who have been reported to us may lose in the end. They are the ones who give hobbyists a bad name, and should be kicked out of any club meeting they show up at.
I would appreciate letters from any one who wants to pay up, or has a suggestion or comment. Just write to me at 1180 Alvarado SE, #114, Albuquerque, New Mexico, 87108. Nothing would please me more than being able to hire ten programmers and deluge the hobby market with good software.

Bill Gates

General Partner, Micro-Soft
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

Back to the roots are we?
'/

Dim arr() As Integer, i As Integer
Dim GolombLength As Integer
GolombLength = 30
ReDim arr(GolombLength)
arr(0) = 1 

i = 1
For i = 1 To GolombLength
    arr(i) = 1 + arr(i - arr(arr(i-1)-1))
Next

For i = 0 To UBound(arr)
    Print arr(i)
Next

entry #7

written by Makefile_dot_in
submitted at
0 likes

guesses
comments 0

post a comment


dir interpreter
dir js
interpreter.js ASCII text
  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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
function display(s) {
	document.getElementById("output").innerHTML += s;
}

// A limited stack.
function Stack(array) {
	this.array = array;
	this.as_html = () => this.array.map(el => `<td><pre>${JSON.stringify(el)}</pre></td>`).join(""); 
	this.update_debug_table = function() {
		let row = document.getElementById("current-stack");
		row.innerHTML = `<td>current</td>${this.as_html()}`
	}
	function update_on_call(f) {
		return function(...a) {
			let retval = f(...a);
			this.update_debug_table();
			return retval;
		}
	}
	this.push = update_on_call((...x) => this.array.push(...x));
	this.pop  = update_on_call(() => this.array.pop());
	this.dump = function() {
		display(this.array.join(", "));
	}
}

function add_call_info(token, state) {
	let table = document.getElementById("debug");
	let row = table.insertRow();
	row.innerHTML = `<td><pre>${token.type}(${token.payload})</pre></td>${state.stack.as_html()}`;
}

function Settings(debug, nya_delay) {
	this.debug = debug;
	this.nya_delay = nya_delay;
}

function State(stack, settings, builtins) {
	this.settings = settings;
	this.stack = stack;
	this.functions = {};
	Object.assign(this.functions, builtins);
}

function Token(type, payload) {
	this.type    = type    || "";
	this.payload = payload || "";
}

function Error(code) {
	this.code = code;
}

const errors = {
	type: () => debug(new Error(1))
};

function asyncsleep(t) {
	return new Promise(resolve => setInterval(resolve, t));
}


function nyaypeof(x) {
	switch (typeof(x)) {
	case "number": return "num";
	case "string": return "str";
	case "boolean": return "bool";
	case "undefined": return "void";
	case "object":
		if (x instanceof Error)
			return "err";
	default:
		display(`Error: Cannot determine the type of ${x}\n`);
	}
}


function nyaize(types, f) {
	types.reverse();
	return async function(s) {
		let invalid = false;
		let args = types.map(type => {
			switch (type) {
			case "stack": return s.stack;
			case "any":   return s.stack.pop();
			case "state": return s;
			default:
				let arg = s.stack.pop();
				let argtype = nyaypeof(arg);

				if (argtype !== type) {
					invalid = true;
				}
				return arg;
			}
		});
		if (invalid) {
			s.stack.push(errors.type());
			return;
		}
		let retval = f(...args.reverse());
		if (retval instanceof Promise)
			retval = await retval;

		if (retval instanceof Array)
			s.stack.push(...retval);
		else if (retval !== undefined)
			s.stack.push(retval);
	}
}

const binnum = ["num", "num"];
const binstr = ["str", "str"];
const binbool = ["bool", "bool"]
const builtins = {
	"+":  nyaize(binnum, (a, b) => a + b),
	"-":  nyaize(binnum, (a, b) => a - b),
	"*":  nyaize(binnum, (a, b) => a * b),
	"/":  nyaize(binnum, (a, b) => a / b),
	"%":  nyaize(binnum, (a, b) => a % b),
	">":  nyaize(binnum, (a, b) => a > b),
	"<":  nyaize(binnum, (a, b) => a < b),
	"=":  nyaize(binnum, (a, b) => a == b),
	">=": nyaize(binnum, (a, b) => a >= b),
	"<=": nyaize(binnum, (a, b) => a <= b),
	".":  nyaize(binstr, (a, b) => a + b),
	"&":  nyaize(binbool,(a, b) => a && b),
	"|":  nyaize(binbool,(a, b) => a || b),
	"AwA":nyaize(["bool"], a => !a),
	"Nya":nyaize(["state", "str", "bool"], async function(s, code, cond) {
		while (cond) {
			if (nyaypeof(cond) !== "bool") {
				s.stack.push(errors.type());
				break;
			}
			await execute(code, s);
			await asyncsleep(s.settings.nya_delay);
			cond = s.stack.pop();
		}
	}),
	"Nom":nyaize(["stack", "num"], function(s, n) {
		for (let i = 0; i < n + 1; i++)
			s.pop();
	}),
	"Meow": nyaize(["str"], display),
	"Myaff": nyaize(["num"], num => num.toString()),
	"Dup" :nyaize(["any"], x => [x, x]),
	"ayN": nyaize(["stack", "num"], (s, a) => Array(a).fill(null).map(_ => s.pop())),
	"Nyurr": nyaize(["state", "str", "str"], function(state, code, name) {
		state.functions[name] = async (s) => {
			await execute(code, s);
		};
	}),
	"Nyaypeof": nyaize(["any"], nyaypeof)
};

// for debugging the interpreter (place your breakpoints here)
function debug(payload) {
	return;
}

async function run_token(token, s) {
	switch (token.type) {
	case 'n': s.stack.push(parseFloat(token.payload));                    break;
	case 's': s.stack.push(token.payload);                                break;
	case 'b': s.stack.push({"Purr": true, "HISS": false}[token.payload]); break;
	case 'f': await s.functions[token.payload](s);                          break;
	case 'd':
		if (s.settings.debug) {
			display(`Breakpoint ${token.payload}\nStack dump:`);
			s.stack.dump();
			display(`\n`);
		}
		break;
	case 'e': if (s.settings.debug)
		debug(token.payload);
		break;
	case 'c': break; // comment
	default: return false;
	}
	return true;

}

function tokenize(code) {
	code += " ";
	let tokens = [];
	let paren_depth = 0;
	let current_token = new Token();
	let current_mode = null;
	let whitespace = /\s/;
	/* two types of mode switching:
	   current_mode = modes.x // switches the mode to x with the next iteration
	   modes.x()              // switches the mode to x in this iteration

	   three modes:
	   none: parses types and consumes whitespace
	   simple: parses simple payloads
	   paren: parses parenthetical payloads
	*/
	let modes = {
		simple: function(c) {
			current_mode = modes.simple;
			if (whitespace.test(c)) {
				modes.none(c);
				return;
			} else if (c == "(") {
				modes.paren(c);
				return;
			}
			current_token.payload += c;
		},
		none: function(c) {
			current_mode = modes.none;
			if (whitespace.test(c)) {
				if (current_token.type != "") {
					tokens.push(current_token);
					current_token = new Token();
				}
				return;
			}
			current_token.type = c;
			current_mode = modes.simple;
		},
		paren: function(c) {
			current_mode = modes.paren;
			let internal_paren_depth = null;
			switch (c) {
			case '(':
				paren_depth++;
				if (paren_depth == 1)
					return;
				break;
			case ')':
				paren_depth--;
				if (paren_depth == 0) {
					current_mode = modes.none;
					return;
				}
				break;
			}
			current_token.payload += c;
		}


	};
	current_mode = modes.none;

	for (const c of code) {
		current_mode(c);
	}
	
	return tokens;
}

async function execute(code, state) {
	let tokens = tokenize(code);
	for (const token of tokens) {
		add_call_info(token, state);
		let valid = await run_token(token, state);
		if (!valid) {
			display(`Syntax error: Invalid type: ${token.type}\n`);
			break;
		}
	}
}
async function run() {
	let run_button = document.getElementById("run-button");
	run_button.disabled = true;
	run_button.innerHTML = "Running...";
	let stack = new Stack([]);
	let debug = document.getElementById("debug-mode").checked;
	let nya_delay = parseInt(document.getElementById("nya-delay").value);
	let settings = new Settings(debug, nya_delay);
	let state = new State(stack, settings, builtins);
	document.getElementById("output").innerHTML = "";
	await execute(document.getElementById("code").value, state);
	//	state.stack.dump();
	run_button.disabled = false;
	run_button.innerHTML = "Nya it out!";
}

function toggle_debug() {
	document.getElementById("demeow").classList.toggle("hidden");
}

function reset_table() {
	document.getElementById("debug").innerHTML = `<tr id="current-stack"></tr>`;
}
LICENSE ASCII text
1
2
3
The Nya General Public License.
THIS PROGRAM IS PROVIDED WITH NO WARRANTY, EXPRESS OR IMPLIED- and all that stuff.
Otherwise, you may use this program however you want, provided you agree to put on a cat ear headband upon the author's request.
fizzbuzz.txt ASCII text
 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
s(f% n0 f=) sDivides fNyurr c(creates a function named `divides' that cheks if the last element on the stack divides the second top element.)
s(fDup n100 f<) sNotReached100 fNyurr c(creates a function that returns whether 100 is the last element of the stack)

n0 c(starting value)
s(
	n1 f+ c(increment)
	s(
		sFizz fMeow bHISS
	)
        c(before reversal)
        n2 fayN c(first reversal)
        fDup    c(first duplication)
        n3 fayN c(second reversal)
        n2 fayN c(third reversal)
        n3 fDivides dCondition
        fDup    c(second suplication)
        n3 fayN c(fourth reversal)
        n2 fayN c(fifth reversal)
        fNya
	s(
		sBuzz fMeow bHISS
	) 
        n3 fayN c(first reversal #2)
        fDup    c(first duplication #2)
        n4 fayN c(second reversal #2)
        n2 fayN c(third reversal #2)
        n3 fayN c(fourth reversal #2)
        n5 fDivides dCondition
        fDup    c(second duplication #2)
        n3 fayN c(fifth reversal #2)
        n2 fayN c(sixth reversal #2)
        fNya
	s(
		fDup fMyaff fMeow bHISS e(exiting the loop)
	)
        c(before reversal #3)
        n3 fayN f| fAwA cCondition
        fNya
        cNumber
        s(
) fMeow
	fNotReached100 cCondition
) bPurr fNya
index.html ASCII text, with very long lines (588)
 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
<!DOCTYPE html>
<html>
  <head>
    <title>StackNya</title>
    <meta charset="utf-8">
    <style>
	.monospace {
		font-family: monospace;
	}
	td {
	    border: 1px solid black;
	}
	table {
	    max-width: 100vw;
	}
	pre {
	    text-overflow: ellipsis;
	    max-width: 20vw;
	    word-break: break-all;
	}
	.hidden {
	    display: none;
	}
    </style>
    <script src="js/interpreter.js"></script> 
  </head>
  <body>
    <h1>StackNya</h1>
    <h3>Description</h3>
    <p>StackNya is a stack-based language. This means that there's a single array (called a stack) around which all calculations are based. When a function is called, it receives its arguments by removing them from the stack.</p>
    <h3>Syntax</h3>
    <p>A StackNya program consists of one or mowe tokens. A token consists of a type (single letter) followed by a payload, optionally in parentheses, in which case it goes on as long as the initial parentheses are closed. Currently, these types exist: </p>
    <ul>
      <li><code>n</code> - pushes a number on the stack</li>
      <li><code>s</code> - pushes a string on the stack</li>
      <li><code>b</code> - pushes a boolean - <code>Purr</code> or <code>HISS</code></li>
      <li><code>f</code> - calls a function</li>
      <li><code>d</code> - dumps the stack to output - mostly obsolete due to the demeowing table</li>
      <li><code>e</code> - calls a function that does nothing but can be used to debug the interpreter at specific points by placing a breakpoint on that function.</li>
      <li><code>c</code> - no-op. Useful for comments and annotations for the demeowing table.</li>
    </ul>
    <h3>Functions</h3>
    <p>Functions that correspond to binary operators work mostly as you'd expect, taking the second-to-top element on the stack as their first argument, and the top element as their second argument. These include <p><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>, <code>&gt;</code>, <code>&lt;</code>, <code>=</code> (like C <code>==</code>), <code>&gt;=</code>, <code>&lt;=</code>, <code>.</code> (used for concatenation - <code>+</code> works for integers only), <code>&amp;</code>, <code>|</code> (like C <code>&amp;&amp;</code> and <code>||</code>)</p>
    </p>
    <p>The others are:</p>
    <ul>
      <li><code>AwA</code> - negates the top of s.</li>
      <li><code>Nya</code> - takes 2 arguments: a string containing code and a boolean, then, if the boolean is true, runs the code as long as the top of the stack is <code>bPurr</code></li>
      <li><code>Nom</code> - takes a single numeric argument and consumes that many + 1 (because it also has to consume its argument) elements from the stack</li>
      <li><code>Meow</code> - takes a string and outputs it</li>
      <li><code>Myaff</code> - converts a number to a string</li>
      <li><code>Dup</code> - duplicates the top of stack.</li>
      <li><code>ayN</code> - takes a numeric argument n, then reverses the last <em>n</em> elements of stack.</li>
      <li><code>Nyurr</code> - takes a string containing NyaStack code, another string containing a function name, and creates a function with that name</li>
      <li><code>Nyaypeof</code> - returns the type of the top element of the stack, consuming it in the process. Current types are <code>num</code>, <code>str</code>, <code>bool</code>, <code>void</code> and <code>err</code></li>
    </ul>
    <h3>Examples</h3>
    <h4>Hello, World!</h4>
    <code>
      s(Hello, World!) fMeow
    </code>
    <h4><code>yes</code></h4>
    <pre>
s(s(y
) fMeow bPurr) bPurr fNya
    </pre>
    <h4>FizzBuzz</h4>
    <iframe src="fizzbuzz.txt"></iframe>
    <h2>Interpreter</h2>
    <div><textarea cols="40" rows="5" type="text" class="monospace" id="code"></textarea></div>
    <button onclick="toggle_debug();">Toggle demeow tools</button>
    <button id="run-button" onclick="run();">Nya it out!</button><br>
    <label for="nya-delay">The delay between consecutive iterations as done by <code>Nya</code> (ms) (smaller is faster):</label>
    <input type="number" id="nya-delay" name="nya-delay" value="50">
    <div class="hidden" id="demeow">
    <h2>Demeowing</h2>
    <input type="checkbox" id="debug-mode" name="debug-mode">
    <label for="debug-mode">Demeowing mode (enables commands <code>d</code> un <code>e</code>)</label>
    <p>(Warning: the table is a little broken but CSS is hard-)</p>
    <button onclick="reset_table();">Reset table</button>
    <table id="debug">
      <tr id="current-stack"></tr>
    </table>
    </div>
    <pre id="output"></pre>
    </div>
  </body>
</html>
a.stacknya ASCII text
 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
s(
	c(a b)
	n2 fayN fDup
	c(b a a)
	n3 fayN
	c(a a b)
	n2 fayN
	c(a b a)
) c(a b -- a b a) sOver fNyurr

s(
	c(a b c)
	n3 fayN fDup
	c(c b a a)
	n4 fayN
	c(a a b c)
	n2 fayN
	c(a a c b)
	n3 fayN
	c(a b c a)
) c(a b c -- a b c a) sPick fNyurr

s(fOver fOver) c(a b -- a b a b) sDup2 fNyurr
s(fPick fPick fPick) c(a b c -- a b c a b c) sDup3 fNyurr

s(s__InternalDip fNyurr n2 fayN f__InternalDip n2 fayN) c(a b code -- a' b) sDip fNyurr

s(bPurr fNya) c(code --) sDoWhile fNyurr
s(s(s( bHISS) f.) fDip fNya) c(code --) sIf fNyurr

c(An array is a pair (len data) on the stack.)

s(n0 s()) c(-- len data) sEmptyArray fNyurr
s(fMyaff s( n) n2 fayN f. f. s(n1 f+) fDip) c(len data el -- len' data') sAppend fNyurr
s(
	c(ex: 1 2 3 4 5 6 7 8 9 10)
	n2 fayN s__InternalIdxA fNyurr
	c(len idx)
	n2 fayN fOver f-
	c(idx len-idx)
	s(f__InternalIdxA n0 n) n2 fayN fMyaff f.
	s( fNom fDup n) f. fOver n1 f+ fMyaff f.
	s( fayN n0 n) f. n2 fayN fMyaff f.
	s( fNom) f.
	s__InternalIdxB fNyurr
	f__InternalIdxB
) c(len data idx[1..] -- elem) sIdx fNyurr

s(1 2 ) fMeow

c(len data num uses)
n2 s(n1 n2) n2 n1
s(
	fDup n0 f<=
	s(
		n0 fNom
		c(len data num)
		n1 f+
		fDup3 fIdx
	) n2 fayN fIf

	n4 fayN n3 fayN
	c(uses len data num)
	fDup fMyaff s( ) f. fMeow
	fDup
	c(uses len data num num)
	n4 fayN n3 fayN fAppend
	c(uses num len' data')
	n2 fayN n4 fayN
	n1 f-
	bPurr
) fDoWhile