previndexinfonext

code guessing, round #33 (completed)

started at ; stage 2 at ; ended at

specification

I want something simpler to program on, so help me emulate a one-instruction set computer. programs can be written in python, c, any oisc, or any concatenative language.

a one-instruction set computer, or OISC for short, is a type of abstract machine that only provides a single instruction, meaning that it does not use an opcode to specify different operations. all you have to do to run them is the same thing over and over! it couldn't be simpler.

your challenge is to implement an emulator for a OISC of your choosing (or creation). the interface is unspecified, but you must document how your program should be used in your submission.

results

  1. 👑 LyricLy +4 -1 = 3
    1. JJRubes
    2. nurdle
    3. seshoumara
    4. moshikoi
  2. JJRubes +1 -1 = 0
    1. seshoumara (was nurdle)
    2. LyricLy (was seshoumara)
    3. moshikoi
    4. nurdle (was LyricLy)
  3. nurdle +2 -3 = -1
    1. LyricLy (was JJRubes)
    2. seshoumara
    3. moshikoi
    4. JJRubes (was LyricLy)
  4. seshoumara +2 -3 = -1
    1. moshikoi (was JJRubes)
    2. nurdle
    3. JJRubes (was moshikoi)
    4. LyricLy
  5. moshikoi +2 -3 = -1
    1. LyricLy (was JJRubes)
    2. nurdle
    3. seshoumara
    4. JJRubes (was LyricLy)

entries

you can download all the entries

entry #1

written by JJRubes
submitted at
1 like

guesses
comments 0

post a comment


3sp.py 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
# python3 3sp.py -h            |    |    | esolangin' on the lone desert highway
import                  argparse    ;    #
def      parse_contents(contents    )    :
    instructions               =    [    ]
    for          line in program    :    #
        for          instruction    in   line.split():
            try                     :    #
                instructionValue    =    int(instruction)
                instructions        .    append(instructionValue)
            except    ValueError    :    #
                return              instructions
    return          instructions    ;    #
def                pad(row, size    )    :
    if            size > len(row    )    :
        row               += [0]    *    (size - len(row))
def                       update    (    instruction, row):
    pad                     (row    ,    instruction + 1)
    pad                     (row    ,    row[instruction] + 1)
    pad                     (row    ,    row[row[instruction]] + 1)
    row                     [row    [    row[instruction ]]] += 1
def                    do_io(row    )    :
    pad                     (row    ,    4)
    if             row[1] % 2 ==    1    :
        print         (chr(row[3    ]    %256), end="")
def             run(instructions    ,    max_cycles, io):
    row                        =    [    ]
    cycles                     =    0    ;
    while                   True    :    #
        if            max_cycles    !=   None and cycles > max_cycles:
            if                io    :    #
                print        (""    )    ;
            return           row    ;    #
        index           = cycles    %    len(instructions)
        update     (instructions    [    index], row)
        if          index == len    (    instructions) - 1 and io:
            do_io           (row    )    ;
        cycles                +=    1    ;
    return                   row    ;    #
def                        repl(    )    :
    print                           (    "3 Star Programmer REPL")
    instructions               =    [    ]
    row                        =    [    ]
    while                   True    :    #
        try                         :    #
            instructionValue        =    int(input(">>> "))
            instructions            .    append(instructionValue)
            update                  (    instructionValue, row)
            print           (row    )    ;
        except        ValueError    :    #
            return                  ;    #
if        __name__ == '__main__'    :    #
    parser            = argparse    .    ArgumentParser(description="Three Star Programmer interpreter. https://esolangs.org/wiki/Three_Star_Programmer")
    parser         .add_argument    (    "filename", help="Leave empty to use as a REPL. Options have no effect on the REPL.", nargs="?")
    parser         .add_argument    (    "-s", "--max_steps", type=int, help="Limits the number of steps the program takes.")
    parser         .add_argument    (    "-o", "--output", action="store_true", help="Outputs according to the output extension.")
    parser         .add_argument    (    "-p", "--print_tape", action="store_true", help="Prints the memory each step.")
    args                = parser    .    parse_args()
    if                      args    .    filename == None:
        repl                   (    )    ;
    else                            :    #
        with           open(args    .    filename, "r") as f:
            program          = f    .    readlines()
        if       args.print_tape    :    #
            print           (run    (    parse_contents(program), args.max_steps, args.output))
        else                        :    #
            run  (parse_contents    (    program), args.max_steps, args.output)

entry #2

written by nurdle
submitted at
1 like

guesses
comments 0

post a comment


cool.h ASCII text, with very long lines (328)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#define Clear_The_Page          system("cls||clear");
#define Read_Me_The_Story 	    printf("\t:: \"%s\" by %s ::\n", story, argv[1]); {int i = 0; while (i < 65536 && story[i]) {i++;} for (i = i + 1; story[i] && i < 65536; i++) {printf("%c", story[i]);} printf("\n");}
#define Close_The_Book(reason)  return reason
#define Unknown_Author          1
#define All_Is_Good             0
#define Write_Me_A_Story        char c; int x = -1, y = -1; while ((c = fgetc(author)) != EOF) {{if ((57 >= c && c >= 48) || (71 >= c && c >= 65)) {if (x == -1)x = (c < 65? (c - 48): (10 + c - 65)) * 16;else {y = (c < 65? (c - 48): (10 + c - 65)) + x;x = -1;if (y == 8) --pen;else if (y == 255) ++pen;else {*pen += y;++pen;}}}}}
#define Check_It_Out            if (argc < 2) {printf("ws: no author was provided\n");Close_The_Book(Unknown_Author);}if (!author) {printf("ws: could not reach the author\n");Close_The_Book(Unknown_Author);}

/* hey, nurdle here!
 * warning to all aspiring codeguessers:
 * in the info page when they say "we don't bite" they are lying.
 * they have had incidents where they did in fact use their sharp teeth (especially back when they were allowed to roam around during the day, pre-87') to cause bodily harm
 * to several children attending the events at the pizzeria (Lyicly's Dinner).
 * I wish to remind you to KEEP ALL OF YOUR LIMBS A SAFE DISTANCE OF 30 CM AWAY FROM THEIR MOUTHS.
 * thank you and have a blessed day!
 */
docs.md ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# writeScript!

wS programs start with a 65536 byte long tape where every byte by default = 0<br>
wS programs are comprised of hexidecimal numbers (non hex characters are ignored), these represent addition<br>
NOTE: hex numbers `A-F` MUST BE CAPITALIZED, lowercase letters are for comments.
## Control Characters
 * `08` goes back to the previous character in the tape
 * `ff` skips to the next character in the tape
the first string represents the title of the book, while the second string represents the contents of the book.<br>
the title and contents of the book are seperated by null characters.
```wS
41 00 42
```
this book would be titled "A" (which is 41 in hex) and its contents would be "B" (which is 42 in hex)
## Running The "Emulator"
compile the `ws.c`, and then run it using the format below
```bash
./ws (filename)
```
example.ws ASCII text
1
2
47 65 6C 6C 6F 20 51 6F 72 6C 64 21 00   name of book
47 65 6C 6C 6F 20 51 6F 72 6C 64 21 00   contents
hotdog.txt ASCII text
1
2
3
4
5
6
why cant i say everyone is lyingly? what is up with that? another err 500? another err 404? another err in general?

the anonymous is rigged to target new CGers in every way, therefore you should use it so that it isnt rigged.


this code was not written by me, however someone probably did
ws.c ASCII text
1
2
3
4
5
6
7
8
#include <stdio.h>
#include <stdlib.h>
#include "cool.h"

FILE *author; char story[65536] = {0}; char *pen = story;

int main(int argc, char **argv) {
	author = fopen(argv[1], "r"); Check_It_Out; Clear_The_Page; Write_Me_A_Story; Read_Me_The_Story; Close_The_Book(All_Is_Good);}

entry #3

written by seshoumara
submitted at
1 like

guesses
comments 0

post a comment


cg33_OISC.dc 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
#!/usr/bin/dc -f

[Problem]c
	# OISC (Tape first line, syntax after: <current state> <current cell> <new cell> <tape movement> <new state>. See attached example scripts.)
	# https://cg.esolangs.gay/33/
[Restrictions]c
	# Only [0-9] values are allowed for tape cells and state (0 being the termination state). For movement only 1:left, 2:stay and 3:right.
	# Tape length and maximum number of iterations are small for debugging purposes, but can be increased.
	# Script comments and presence of empty lines aren't supported. One can hack dc to write a form of comment, see attached example scripts.


[setup]c
	#custom exits (working with q in variable execution depths is a nightmare)
	[n10P q]se
	[n 0sk 2Q]sf
	#set starting state, tape pointer, tape length and 0 value for each cell
	1ss 0sp 60st
	ltsc[lc1-dsc0r:Tlc0!=z]szlzx
	#store script tape from first line
	? z
	d[Error: tape must contain at least one cell!]r0=e X+
	sc[
		0sk
		d1+z[Error: tape cell can't have a string value! Use [0-9] instead.]rlc2+=f X+d-+
		d[Error: tape cell must have a [0-9] value!]r9<f X+
		d[Error: tape cell must have a [0-9] value!]r0>f X+
		1sk lc1-dsc:Tlc0!=z
	]szlzx
	[]lk0=ec
	#store all script instructions in one array and store its length (instructions are one per line and same length of 5 values)
	0sa 0sb 0sc 0si
	[
		0sk zsh
		d1+z[Error: instruction value can't be a string! Use [0-9] instead.]rlh2+=f X+d-+
		d[Error: instruction value must be [0-9]!]r9<f X+
		d[Error: instruction value must be [0-9]!]r0>f X+
		1sk 0sh lc1-dsc:Ilcla!=x
	]sx
	[
		? z dli+si 0sk
		#can't do 5!= because on empty lines and especially at end of file there will be 0 values (used to exit this macro)
		d[Error: instruction must be exactly 5 space separated values!]r1=f X+
		d[Error: instruction must be exactly 5 space separated values!]r2=f X+
		d[Error: instruction must be exactly 5 space separated values!]r3=f X+
		d[Error: instruction must be exactly 5 space separated values!]r4=f X+
		d[Error: instruction must be exactly 5 space separated values!]r5<f X+
		1sk lb+dsbsc z0!=x []lk0=fc lbsa lblc!=z
	]szlzx
	[]lk0=ec
	lid[Error: there must be at least one instruction!]r0=e X+
	0sk c
	#set instruction pointer and maximum number of iterations a script could run (infinite loops are easily possible)
	_1sq 1000sm

[printing]c
[
	#debug printing
	[[*]n]sx
	[state: ]nlsn[, tape:]n
	0sc[[ ]nlclp=xlcd;Tn1+dsclt!=z]szlzx
	10P [instructions:  ]n
	0sc[[ ]nlclq1+=xlcd;In1+dscli!=z]szlzx 10P
]sd
[
	#final printing and soft quit (often called more than once; dc might complain, but it does the job in the end)
	lk1=d 0sk 3Q
]sg
[
	#print error and call quit
	n10P lgx
]se

[main]c
[
	lq+sq
	#decrement iteration counter and quit if limit was reached (value 0)
	lm1-dsm0=g
	2Q
]sn
[
	1sk ldx
	[
		#check if current state matches instruction's <current state>
		4 lq1+dsq;I ls!=n
		#check if current cell matches the value of the instruction's <current cell>
		3 lq1+dsq;I lp;T!=n
		#change the current cell's value to that of the instruction's <new cell> value
		lq1+dsq;I lp:T
		#apply <tape movement>
		lq1+dsq;I
		d[Error: tape movement must have a [1-3] value!]r3<e X+
		d[Error: tape movement must have a [1-3] value!]r1>e X+
		_2+lp+
		d[Error: tape pointer can't go anymore to the left!]r0>e X+
		d[Error: tape pointer can't go anymore to the right!]rlt<e X+
		sp
		#apply <new state> and exit if it is 0 (the termination state)
		lq1+dsq;I ss
		ls0=g
		#reset instruction pointer
		_1sq
	]x #artificially nested macro only needed for the soft quit
	lk0=g
	lqli1-!=r
	lk0=g
	[Error: no instruction matched!]0 0=e
]srlrx
c
cg33_flip_bits.txt ASCII text
1
2
3
4
1 0 0 1 0 1 1 1 2	[tape is set on first line (abusing data=code mode of dc to write comments, that are otherwise not implemented)]X+
1 0 1 3 1		[in starting state 1, check if the current cell is either 0 or 1 and replace it with 1 or 0 respectively; then move right]X+
1 1 0 3 1
1 2 2 1 0		[if current cell is 2, a way to represent the end of the binary sequence on the tape, go left and change to state 0 (exit)]X+
cg33_is_even.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
2 7 4 0		[number (274) is put on tape one digit per cell, with 0 in this case used to represent end of number; plus the result at the end]X+
1 1 1 3 1	[in starting state 1 no tape change is done, only navigating to the end of the number]X+
1 2 2 3 1
1 3 3 3 1
1 4 4 3 1
1 5 5 3 1
1 6 6 3 1
1 7 7 3 1
1 8 8 3 1
1 9 9 3 1
1 0 0 1 2	[end token (value 0) reached, go left and switch to state 2]X+
2 2 2 3 4	[from state 2 go to state 4, if the end digit is even, or state 5 if odd]X+
2 4 4 3 4
2 6 6 3 4
2 8 8 3 4	[if the number would have ended in 0, a change in this script and a different end token would have been needed!]X+
2 1 1 3 5
2 3 3 3 5
2 5 5 3 5
2 7 7 3 5
2 9 9 3 5
4 0 1 2 0	[in state 4 change the end token to 1 (true, even), now representing the result, then change to state 0 (exit)]X+
5 0 0 2 0	[in state 5 change the end token to 0 (false, odd), then exit]X+

entry #4

written by moshikoi
submitted at
1 like

guesses
comments 0

post a comment


abcout.c 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
/**
 * Usage: abcout <file> [no. cells printed] [no. cells printed in debug]
 */

#define __STDC_WANT_LIB_EXT1__ 1

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

uint8_t const HALT_CONDITION[] = {0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF};

int run(FILE *file, uint16_t result_limit, uint16_t debug_limit) {
  uint8_t cells[UINT16_MAX] = {0, 1};
  uint8_t instr[6];

  while (true) {
    size_t const read_bytes = fread(instr, sizeof(*instr), 6, file);
    if (read_bytes == 0) {
      break;
    }

    if (read_bytes != 6) {
      fprintf(stderr, "Misaligned ROM\n");
      return 1;
    }

    if (memcmp(HALT_CONDITION, instr, 6) == 0) {
      if (debug_limit) {
        printf("\n\tHALT\n");
      }
      break;
    }

    uint16_t const a = instr[0] * 256 + instr[1];
    uint16_t const b = instr[2] * 256 + instr[3];
    uint16_t const c = instr[4] * 256 + instr[5];

    cells[a] += cells[b];

    if (cells[a] < cells[b])
      fseek(file, c, SEEK_SET);

    if (debug_limit) {
      printf("\n\t%d %d %d\n", a, b, c);
      for (long i = 0; i != debug_limit; ++i)
        printf("%.2x ", cells[i]);
      putchar('\n');
    }
  }

  for (long i = 0; i != result_limit; ++i)
    printf("%.2x ", cells[i]);
  putchar('\n');

  return 0;
}

int main(int argc, char const **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: abcout <file>");
    return 1;
  }

  char const *file_name = argv[1];
  uint16_t result_limit = 100;
  uint16_t debug_limit = 0;

  if (argc > 2)
    result_limit = atoi(argv[2]);

  if (argc > 3)
    debug_limit = atoi(argv[3]);

  FILE *file;
  if (fopen_s(&file, file_name, "rb")) {
    printf("Couldn't open %s\n", file_name);
    return 1;
  }
  printf("Running %s (showing first %d cells)\n", file_name, result_limit);
  run(file, result_limit, debug_limit);
  fclose(file);
}

entry #5

written by LyricLy
submitted at
0 likes

guesses
comments 0

post a comment


cg.esolangs.gay ASCII text
1
2
3
4
5
p,n=eval(input())
while 1:
 for f in p:
  if not n*f%1:n*=f;break
 else:break
doc ASCII text
1
2
3
4
provide list of fractions and input number
fractions must be imported:
[(f := __import__("fractions").Fraction)(17, 91), f(78, 85), f(19, 51)], 2
observe output via halting state