all stats

Sinthorion's stats

guessed the most

namecorrect guessesgames togetherratio

were guessed the most by

namecorrect guessesgames togetherratio

entries

round #3

guesses
comments 0

post a comment


sinthorion.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
 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
// C is a functional programming language featuring concepts such as
// purity, immutability, first class functions, and flexible dynamic typing

// C is a rather old language, which means we need a lot of boilerplate
// I recommend skipping this section to get to the fun parts

#include <stdint.h>
#define Num intptr_t

#define let const Num
#define defun Env
#define params(...) (Env env, ##__VA_ARGS__)
#define return(V) ({env.x = V; return env;})

#define cons(L, R) ({ env = fmallocsetcons(env, L, R); env.x; })
#define null 0
#define left(cons) (cons?((Num*)cons)[0]:null)
#define right(cons) (cons?((Num*)cons)[1]:null)

#define call(F, ...) ({env = F(env, ##__VA_ARGS__); env.x;})

#define ref(V) ({let ret = (let)V; ret;})

// create our own memory management, since C's is inferior

#define MEMINIT(N) \
static Num memarr[N]; \
Mem mem = { (Num)memarr, 0}; \
Env env = { 0, mem }

let numsize = sizeof(Num);

struct Mem { Num mem; Num next; };
typedef struct Mem Mem;

struct Env { Num x; struct Mem mem; };
typedef struct Env Env;

let set(let ptr, let val)
{
    Num *mut = (void*)ptr;
    *mut = val;
    let con = (const Num) mut;
    return con;
}

// I don't understand this part either; just ignore it

defun fmallocsetcons params(let left, let right)
{
    let ptr = set(env.mem.mem+env.mem.next, left);
    set(env.mem.mem+env.mem.next+numsize, right);
    Mem newmem = { env.mem.mem, env.mem.next + 2*numsize };
    Env ret = { ptr, newmem };
    return ret;
}

defun fmallocsetmatrix params (let matrix)
{
    int * ptr = (int*)(env.mem.mem + env.mem.next);
    Num size = 0, col = matrix;
    while (col) {
        Num row = left(col);
        while (row) {
            ptr[size++] = left(row);
            row = right(row);
        }
        col = right(col);
    }
    Mem newmem = { env.mem.mem, env.mem.next + size * sizeof(int) };
    Env ret = { (Num) ptr, newmem };
    return ret;
}

typedef defun (*monad) params(let);
typedef defun (*dyad) params(let, let);

defun apply1 params(let func, let a)
{
    monad f = (monad) func;
    return(call(f, a));
}

defun apply2 params(let func, let a, let b)
{
    dyad f = (dyad) func;
    return(call(f, a, b));
}

// with that done, let's start

// In C we define functions with the defun keyword
// params and local variables are defined with the let keyword
defun sum params(let list)
{
    return(list
        ? left(list) + call(sum, right(list))
        : null);
}

defun map params(let func, let list)
{
    if (!list) return(null);

    //  we call functions with the call keyword
    let retl = call(apply1, func, left(list));
    let retr = call(map, func, right(list));

    return(cons(retl,retr));
}

// inject one additional (plus) param into map function
// needed since C lacks partial application
defun mapplus1 params(let func, let plus, let list)
{
    if (!list) return(null);

    let retl = call(apply2, func, plus, left(list));
    let retr = call(mapplus1, func, plus, right(list));

    return(cons(retl,retr));
}

// merge two lists by combining one element from each list as pair in the new list
// assume both lists have the same size; ignore any remainders
defun zip params(let list1, let list2)
{
    return(list1 == null || list2 == null
        ? 0
        : cons(cons(left(list1), left(list2)),
                call(zip, right(list1), right(list2))));
}

defun length params(let list)
{
    return(list
        ? 1 + call(length, right(list))
        : 0);
}

defun nth params(let n, let list)
{
    return(n
        ? call(nth, n-1, right(list))
        : left(list));
}

defun getrow params(let matrix, let rownum)
{
    return(rownum
        ? call(getrow, right(matrix), rownum - 1)
        : left(matrix));
}

defun getcol params(let matrix, let colnum)
{
    return(call(mapplus1, ref(nth), colnum, matrix));
}

defun mult_pair params(let pair)
{
    return(left(pair) * right(pair));
}

defun matrixmult_single params(let m1, let m2, let rownum, let colnum)
{
    let row = call(getrow, m1, rownum);
    let col = call(getcol, m2, colnum);
    let zipped = call(zip, row, col);

    let products = call(map, ref(mult_pair), zipped);
    return(call(sum, products));
}

defun _matrixmult_row params(let m1, let m2, let n, let rownum, let colnum)
{
    return(colnum >= n
           ? 0
           : cons(call(matrixmult_single, m1, m2, rownum, colnum), call(_matrixmult_row, m1, m2, n, rownum, colnum+1)));
}
defun matrixmult_row params(let m1, let m2, let n, let rownum)
{
    return(call(_matrixmult_row, m1, m2, n, rownum, null));
}

defun _matrixmult params(let m1, let m2, let n, let rownum)
{
    return(rownum >= n
        ? 0
        : cons(call(matrixmult_row, m1, m2, n, rownum), call(_matrixmult, m1, m2, n, rownum+1)));
}
defun matrixmult params(let m1, let m2, let n)
{
    return(call(_matrixmult, m1, m2, n, null));
}

// the real world sometimes forces us to break from our elegancy and purity
defun ints2list params(int * ints, int len)
{
    return(len
           ? cons(ints[0], call(ints2list, ints+1, len-1))
           : null);
}

// convert impure external matrix-array to superior cons matrix
defun _matrix_deserialise params(int * m, int n, int col)
{
    if (col == n) return(null);
    let row = call(ints2list, m, n);
    return(cons(
            row,
            call(_matrix_deserialise, m + n, n, col + 1)
    ));
}
defun matrix_deserialize params(int * m, int n)
{
    return(call(_matrix_deserialise, m, n, null));
}

// convert back to matrix-array for lesser beings to understand
defun matrix_serialize params(let matrix)
{
    return(call(fmallocsetmatrix, matrix));
}

int * entry(int * m1, int * m2, int n)
{
    MEMINIT(1024 * 1024);

    let a = call(matrix_deserialize, m1, n);
    let b = call(matrix_deserialize, m2, n);

    let c = call(matrixmult, a, b, n);

    int * result = (int*)call(matrix_serialize, c);
    return result;
}

round #1

guesses
comments 0

post a comment


330678593904443393-sinthorion.py ASCII text
1
2
3
4
5
6
7
8
9
import sqlite3

def entry(input):
  values = ','.join([f"({x})" for x in input])
  cur = sqlite3.connect("sort.db").cursor()
  cur.execute(f"select val from\
    (select 0 as val union all values {values}) input\
    order by val limit -1 offset 1")
  return [row[0] for row in cur.fetchall()]