previndexinfonext

code guessing, round #93 (completed)

started at ; stage 2 at ; ended at

specification

been a lot of these lately, so do your part to help break code guessing ties. submissions may be written in any language.

refer to the rules for information on the algorithm.

your challenge, given a round number and some number of tied user IDs, is to determine which player wins the round. as any language is allowed, there is no fixed API.

results

  1. 👑 oleander +3 -1 = 2
    1. Dolphy
    2. Olek Sabak
    3. kimapr (was olive)
    4. olive (was kimapr)
    5. Makefile_dot_in
  2. Olek Sabak +2 -1 = 1
    1. oleander (was Dolphy)
    2. Dolphy (was olive)
    3. olive (was oleander)
    4. kimapr
    5. Makefile_dot_in
  3. olive +2 -1 = 1
    1. Dolphy
    2. kimapr (was Olek Sabak)
    3. Olek Sabak (was oleander)
    4. oleander (was kimapr)
    5. Makefile_dot_in
  4. kimapr +2 -1 = 1
    1. oleander (was Dolphy)
    2. Dolphy (was Olek Sabak)
    3. olive
    4. Olek Sabak (was oleander)
    5. Makefile_dot_in
  5. Dolphy +0 -2 = -2
    1. oleander (was Olek Sabak)
    2. Makefile_dot_in (was olive)
    3. kimapr (was oleander)
    4. olive (was kimapr)
    5. Olek Sabak (was Makefile_dot_in)
  6. Makefile_dot_in +1 -4 = -3
    1. Olek Sabak (was Dolphy)
    2. Dolphy (was Olek Sabak)
    3. kimapr (was olive)
    4. oleander
    5. olive (was kimapr)

entries

you can download all the entries

entry #1

written by Dolphy
submitted at
0 likes

guesses
comments 0

post a comment


entry.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from typing import List
import requests as req
from hashlib import sha256


def entry(round_number: int, participant_ids: List[int]) -> int:
    # Server should always be able to send anonymous requests to the cg website
    r = req.get(f"https://codeguessing.gay/{round_number}/")
    if not r.status_code.__str__().startswith('2'):
        raise RuntimeError("Try again later")

    hash = sha256(r.text.encode())
    winner = int(hash.hexdigest(), 16) % participant_ids.__len__()
    return participant_ids[winner]

entry #2

written by Olek Sabak
submitted at
1 like

guesses
comments 0

post a comment


tiebreaker.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
import requests as r # dependency
import html.parser as p


# how to run:
# 1) input data on https://codeguessing.gay as appropriate
# 2) run python tiebreaker.py <n> where n is the round number you want calculated


def get_cg(n):
    return r.get(f'https://codeguessing.gay/{n}/').text


class CGParser(p.HTMLParser):

    TARGET_PATH = ['html','body', 'ol', 'li', 'details', 'summary', 'strong']

    def reset(self, *args, **kwargs):
        super().reset(*args, **kwargs)
        self.path = []
        self.output = None


    def handle_starttag(self, tag, _):
        if not self.output:
            self.path.append(tag)


    def handle_endtag(self, tag):
        if not self.output:
            self.path = self.path[:-self.path[::-1].index(tag) - 1]


    def handle_data(self, data):
        if not self.output and self.path == self.TARGET_PATH:
            self.output = data


def get_winner(n):
    c = CGParser()
    c.feed(get_cg(n))
    return c.output


if __name__ == '__main__':
    import sys
    print(get_winner(int(sys.argv[1])), end='')

entry #3

written by olive
submitted at
0 likes

guesses
comments 0

post a comment


sha256.lua 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
-- all numbers are 32bit, except for appended length

local spack <const>, sunpack <const> = string.pack, string.unpack
local format <const>, rep <const> = string.format, string.rep
local K <const> = {
	0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
	0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
	0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
	0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
	0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
	0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
	0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
	0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
	0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
	0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
	0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
	0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
	0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
	0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
	0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
	0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
}
local sha256values <const> = function(s)
	local K = K
	
	s = s .. "\x80" .. rep("\x00", (55-#s)%64) .. spack(">I8", #s*8)
	
	local h0, h1, h2, h3, h4, h5, h6, h7 =
		0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
		0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
	
	for j = 1, #s, 64 do
		local w = {sunpack("> I4I4I4I4 I4I4I4I4 I4I4I4I4 I4I4I4I4", s, j)}
		
		for i = 17, 64 do
			-- function rightrot(x,y) return (x >> y) | ((x << (32-y)) & 0xffffffff) end
			local wim15, wim2 = w[i-15], w[i-2]
			local s0 = (wim15 >> 3)
			         ~ ((wim15 >>  7) | (wim15 << 25))
			         ~ ((wim15 >> 18) | (wim15 << 14))
			local s1 = (wim2 >> 10)
			         ~ ((wim2 >> 17) | (wim2 << 15))
			         ~ ((wim2 >> 19) | (wim2 << 13))
			w[i] = (w[i-16] + s0 + w[i-7] + s1) & 0xffffffff
		end
		
		local a, b, c, d, e, f, g, h = h0, h1, h2, h3, h4, h5, h6, h7
		
		for i=1,64 do
			-- function rightrot(x,y) return (x >> y) | ((x << (32-y)) & 0xffffffff) end
			local S1 = ((e >>  6) | (e << 26))
			         ~ ((e >> 11) | (e << 21))
			         ~ ((e >> 25) | (e <<  7))
		--	local ch = (e & f) ~ ((~e) & g) -- bitwise choice
			local ch = g ~ (e & (f ~ g))
			local temp1 = h + S1 + ch + K[i] + w[i]
			
			local S0 = ((a >>  2) | (a << 30))
			         ~ ((a >> 13) | (a << 19))
			         ~ ((a >> 22) | (a << 10))
		--	local maj = (a & b) ~ (a & c) ~ (b & c) -- bitwise majority
			local maj = (a & b) ~ (c & (a ~ b))
			local temp2 = S0 + maj

			a, b, c, d, e, f, g, h =
				(temp1 + temp2) & 0xffffffff, a, b, c,
				(temp1 + d    ) & 0xffffffff, e, f, g
		end
		
		h0, h1, h2, h3, h4, h5, h6, h7 =
			(h0+a)&0xffffffff, (h1+b)&0xffffffff, (h2+c)&0xffffffff, (h3+d)&0xffffffff,
			(h4+e)&0xffffffff, (h5+f)&0xffffffff, (h6+g)&0xffffffff, (h7+h)&0xffffffff
	end
	
	return h0, h1, h2, h3, h4, h5, h6, h7
end

local function sha256byte(s) return spack(">I4I4I4I4 I4I4I4I4", sha256values(s)) end

local function sha256hex(s)
	return format("%08x%08x%08x%08x%08x%08x%08x%08x", sha256values(s))
end

---[[
local tests = {
	{ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
		"" },
	{ "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
		"a" },
	{ "f07f9e2b2bb62bdbbda731319f19cec91f369ce1f6cb1d6ba8e8b962d1c73d3a",
		"jk8ssl" },
	{ "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb",
		"abc\n" },
	{ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
		"abc" },
	{ "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650",
		"message digest" },
	{ "3520b54ccec750d15256ada5b3d51cfddcec7fad1482f6bde2ea1c31a2c5b3a5",
		"message digest\n" },
	{ "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73",
		"abcdefghijklmnopqrstuvwxyz" },
	{ "db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0",
		"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
	{ "f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e",
		"12345678901234567890123456789012345678901234567890123456789012345678901234567890" },
	{ "2edc986847e209b4016e141a6dc8716d3207350f416969382d431539bf292e4a",
		rep("a",1024) },
}

for i, test in ipairs(tests) do
	local r = sha256hex(test[2])
	if test[1] == r then print(i, "PASS")
	else print(i, "FAIL", test[1], r)
	end
end
--]]

return sha256hex, sha256byte, sha256values
tiebreaker.lua 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
#!/usr/bin/lua5.4

local sha256hex, sha256byte, sha256values = dofile("sha256.lua")

local function killmattparker(round, uids)
	table.sort(uids)
	local c = #uids
	assert(c < 0xffffffff)
	local h0, h1, h2, h3, h4, h5, h6, h7 = sha256values(tostring(round))
	while h0|h1|h2|h3|h4|h5|h6 ~= 0 or h7 > c do
		h7 = h7 - c
		if h7 < 0 then h6 = h6 - 1 ; h7 = h7 + 0x100000000 end
		if h6 < 0 then h5 = h5 - 1 ; h6 = h6 + 0x100000000 end
		if h5 < 0 then h4 = h4 - 1 ; h5 = h5 + 0x100000000 end
		if h4 < 0 then h3 = h3 - 1 ; h4 = h4 + 0x100000000 end
		if h3 < 0 then h2 = h2 - 1 ; h3 = h3 + 0x100000000 end
		if h2 < 0 then h1 = h1 - 1 ; h2 = h2 + 0x100000000 end
		if h1 < 0 then h0 = h0 - 1 ; h1 = h1 + 0x100000000 end
		assert(h0 >= 0)
	end
	return uids[h7]
end


---[[
local tests = {
	-- lyric please add past tiebreaks to the website it feels ungrounded them being unrecorded
	-- also i don't know if my program actually works, see!
}

for i, test in ipairs(tests) do
	local r = killmattparker(test[2], test[3])
	if test[1] == r then print(i, "PASS")
	else print(i, "FAIL", test[1], r)
	end
end
--]]

return killmattparker

 -- rebedubeduh bi!-bi! rebedubeduh bi!-bi! (brass then piano) (kind jazzy)

entry #4

written by oleander
submitted at
0 likes

guesses
comments 0

post a comment


tiebreaker.php ASCII text, with CR line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php
$roundnumber = 71;
$hash = hash("sha256", (string)$roundnumber);
$userids = array("322724805201756181", "354287021151354882", "490120830056005653", "358359026083430410");
sort($userids);

$mod = 0;
for ($i = 0; $i < 64; $i++) {
    $mod = ($mod * 16 + hexdec($hash[$i])) % count($userids);
}

echo $userids[$mod];
?>

entry #5

written by kimapr
submitted at
1 like

guesses
comments 0

post a comment


entry.sh 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
#!/bin/bash

# they say it's code guessing time.. it's been a while
# though so my knowledge of the game rules might be a
# little rusty... anyway we shall break ties

CurrentTime="$(date)"

echo This program will resolve a tie in the game \"Code Guessing\", found at https://cg.esolangs.gay/
echo

# first Obtain a "round number".  donno whats  it for but task says it's given

echo Please enter the \# of the round.

read -p '> ' round
echo

# we ask the user for "discord ids"

echo Please enter a number of Discord IDs.

export gamers="$({
	{
		while read -p '> ' ID
		do
			if [ $((ID)) -le 0 ]
			then
				break
			fi

			echo $((ID))
		done
	} | {
		# then we sort them

		sort -n
	}
})"

echo

# then we obtain the the last twitter of the Prime Minister of United Kingdom

echo Please open the twitter page of the current Prime Minister of United Kingdom.
echo At the time of writing this code, this is: https://twitter.com/Keir_Starmer
echo Obtain a tweet containing text authored by the PM and type it below.
printf 'The tweet must be newer than "%s".\n' "$CurrentTime"
echo
echo '<<TWEET_EOF'

export tweet_hash=$(
	while IFS= read -r LINE
	do
		if [ "$LINE" = "TWEET_EOF" ]
		then
			break
		fi

		printf '%s\n' "$LINE"

		# And hash it
	done | sha256sum | grep -o '^[^ ]*'
)

echo

echo Hash: $tweet_hash
echo

# divide "H" by "N"
# division is hard, we will use python for this
# also use python for Outputs.

"$(command -v python3 || command -v python)" <<EOF
import os

gamers = os.getenv('gamers').split('\n')
H = int(os.getenv('tweet_hash'), 16)
N = len(gamers)

print('Tie winner is:', gamers[H % N])
EOF

entry #6

written by Makefile_dot_in
submitted at
0 likes

guesses
comments 0

post a comment


cg93.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
#include <math.h>
#include <sqlite3.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/sha.h>
#include <string.h>

void sqlite_fail_on_err(sqlite3 *db) {
  if (sqlite3_errcode(db) == SQLITE_OK) return;
  fprintf(stderr, "SQLite Error: %s\n", sqlite3_errmsg(db));
  exit(1);
} 

void sqlite_conn_destr(sqlite3 **db) {
  sqlite3_close_v2(*db);
}

void sqlite_stmt_destr(sqlite3_stmt **stmt) { sqlite3_finalize(*stmt); }

void mem_destr(void *p) { free(*(void**)p); }

unsigned _BitInt(256) sha256hash(const char *input) {
  unsigned _BitInt(256) ret;
  unsigned char md[SHA256_DIGEST_LENGTH];
  SHA256((unsigned char*)input, strlen(input), md);
  for (size_t i = 0; i < SHA256_DIGEST_LENGTH; ++i)
    ret <<= 8, ret |= md[i];
  return ret;
}

int main(int argc, const char **argv) {
  if (argc != 3) {
    fprintf(stderr, "invalid number of arguments\n");
    return 0;
  }

  int roundnum = atoi(argv[1]);
  const char *f = argv[2];
  [[gnu::cleanup(sqlite_conn_destr)]] sqlite3 *db;
  sqlite3_open(f, &db);
  sqlite_fail_on_err(db);

  [[gnu::cleanup(sqlite_stmt_destr)]] sqlite3_stmt *stmt;
  sqlite3_prepare_v2(db, "select People.name from Scores "
                         "join People on People.id = Scores.player_id "
                         "where round_num = ?1 "
                         "and total = (select max(total) from Scores where round_num = ?1) "
                         "and plus = (select max(plus) from Scores as s2 where round_num = ?1 and s2.total = Scores.total)"
                         "order by player_id asc", -1, &stmt, NULL);
  sqlite_fail_on_err(db);

  sqlite3_bind_int(stmt, 1, roundnum);
  sqlite_fail_on_err(db);  
  unsigned _BitInt(256) hash = sha256hash(argv[1]);

  int ret;
  size_t len = 0;
  size_t cap = 16;
  char **ids = malloc(sizeof(*ids) * cap);
  while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
      if (len == cap) {
        cap *= 2;
        ids = realloc(ids, sizeof(*ids) * cap);
      }

      ids[len++] = strdup((char*)sqlite3_column_text(stmt, 0));
  }

  if (ret != SQLITE_DONE)
    sqlite_fail_on_err(db);

  if (len == 0) {
    printf("No candidates found.\n");
    return 1;
  }

  size_t idx = (size_t)(hash % (unsigned _BitInt(256))len);
  printf("Winner : %s!\n", ids[idx]);

  for (size_t i = 0; i < len; ++i) {
    printf("Candidate: %s\n", ids[i]);
    free(ids[i]);
  }

  free(ids);
  
  return 0;
}