previndexinfonext

code guessing, round #46 (completed)

started at ; stage 2 at ; ended at

specification

I'm designing a schema and I need something to find candidate keys in my database. submissions may be written in any language.

a candidate key of a table in a relational database system is a minimal set of columns that can be used as a primary key, meaning that the values in those columns are unique in each row. for example, take this (rather poorly designed) table:

contest date held winner winner's second name
dog fight oct 17 2000 discarding sabot sabot
cat-off jul 01 2001 palm tree oil tree
rat duel oct 05 2001 cart of iron of
rat duel mar 21 2006 cart of iron of
shark race mar 21 2006 linguist NULL

while no column on its own is unique, notice that there are no two rows with the same value in both contest and date held. this makes (contest, date held) a candidate key. as a candidate key must be minimal, it cannot be a superset of a candidate key, meaning that (contest, date held, winner) is not a candidate. the full set of candidate keys in this example is {(contest, date held), (date held, winner), (date held, winner's second name)}. thinking about the semantic meaning of these columns, the only primary key that makes sense is (contest, date held), but fortunately determining this is outside the scope of this challenge.

the problem is thus as follows. for some set of values V, a set of indices I, and a set T of functions from I to V, the goal is to find each subset i of I such that the elements of T are unique when their domains are restricted to i and that there is no subset of i with the same property.

note the edge cases: when the table has no rows or only one row, the set of candidate keys is {()}. when any row is duplicated entirely, the set of candidate keys is {}.

your challenge is to solve the problem written above, which has intentionally been given in an abstract manner. the set V of values you accept, and the form you take the table in, is up to your discretion. one admissable example would be taking a list of strings of the same length, treating each character as a value, each index as a column, and each string as a row. the result would then be a list of lists of indices. as any language is allowed, there is no fixed API.

results

  1. 👑 LyricLy +4 -0 = 4
    1. razetime (was TheQwertiest)
    2. kotnen
    3. vspf
    4. TheQwertiest (was luatic)
    5. luatic (was razetime)
    6. kimapr
    7. olus2000
  2. razetime +4 -0 = 4
    1. vspf (was TheQwertiest)
    2. kotnen
    3. LyricLy (was vspf)
    4. luatic
    5. TheQwertiest (was LyricLy)
    6. kimapr
    7. olus2000
  3. kotnen +3 -2 = 1
    1. LyricLy (was TheQwertiest)
    2. vspf
    3. luatic
    4. TheQwertiest (was LyricLy)
    5. kimapr (was razetime)
    6. razetime (was kimapr)
    7. olus2000
  4. TheQwertiest +1 -0 = 1
    1. luatic (was kotnen)
    2. razetime (was vspf)
    3. vspf (was luatic)
    4. kimapr (was LyricLy)
    5. kotnen (was razetime)
    6. LyricLy (was kimapr)
    7. olus2000
  5. luatic +2 -3 = -1
    1. LyricLy (was TheQwertiest)
    2. TheQwertiest (was kotnen)
    3. razetime (was vspf)
    4. kotnen (was LyricLy)
    5. vspf (was razetime)
    6. kimapr
    7. olus2000
  6. vspf +1 -3 = -2
    1. razetime (was TheQwertiest)
    2. luatic (was kotnen)
    3. TheQwertiest (was luatic)
    4. olus2000 (was LyricLy)
    5. LyricLy (was razetime)
    6. kimapr
    7. kotnen (was olus2000)
  7. olus2000 +2 -5 = -3
    1. kimapr (was TheQwertiest)
    2. LyricLy (was kotnen)
    3. vspf
    4. luatic
    5. kotnen (was LyricLy)
    6. TheQwertiest (was razetime)
    7. razetime (was kimapr)
  8. kimapr +0 -4 = -4
    1. razetime (was TheQwertiest)
    2. luatic (was kotnen)
    3. LyricLy (was vspf)
    4. vspf (was luatic)
    5. olus2000 (was LyricLy)
    6. kotnen (was razetime)
    7. TheQwertiest (was olus2000)

entries

you can download all the entries

entry #1

written by TheQwertiest
submitted at
1 like

guesses
comments 0

post a comment


distunk.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
at        = lambda glauds : sum ( 2 ** how * glauds [ how ] for how in glauds )
the      = lambda glauds , how , rorm : how if glauds else rorm
delcot  = lambda glauds , how , rorm : glauds ( how ( rorm ) , how ( rorm ) )
it     = lambda : at ( { int ( ) : 1 } )
would = lambda : at ( { it ( ) : int ( ) } )
of   = lambda glauds : glauds [ would ( ) ]
def tondam ( where , doshes , deave , but ) :
    if at ( where ) in doshes : return deave
    doshery = lambda glauds : [ how for how , rorm in but if rorm == glauds and where [ how ] and where [ glauds ] ]
    lutt = doshes . add ( at ( where ) )
    for glauds in filter ( doshery , where ) :
        where [ glauds ] = would ( )
        deave = tondam ( where , doshes , deave , but )
        where [ glauds ] = lutt = it ( )
    return the ( lutt , deave , deave + [ [ glauds for glauds in where if where [ glauds ] ] ] )

" " " expects a list of strings of equal length with no duplicates " " "
from itertools import *
" " " returns a list of lists of indices representing minimal sets " " "
def SOLVE ( crenned ) :
    doshery = lambda glauds , how : max ( len ( list ( rorm ) ) for _ , rorm in groupby ( sorted ( { ( rorm [ glauds ] , rorm [ how ] ) for rorm in crenned } ) , of ) )
    but = [ ( glauds , how ) for glauds , how in delcot ( product , range , len ( of ( crenned ) ) ) if glauds != how and doshery ( glauds , how ) == it ( ) ]
    return the ( len ( crenned ) <= it ( ) , [ [ ] ] , tondam ( { glauds : it ( ) for glauds in range ( len ( of ( crenned ) ) ) } , set ( ) , [ ] , but ) )

EXAMPLE = [
    #0123
    "dods" ,
    "cjpt" ,
    "roco" ,
    "rmco" ,
    "smlN" ,
]

print ( SOLVE ( EXAMPLE ) )                 # [[1, 3], [1, 2], [0, 1]]
print ( SOLVE ( [ "ab" , "aa" , "ba" ] ) ) # [[0, 1]]
print ( SOLVE ( [ "ab" , "ac" ] ) )       # [[1]]
print ( SOLVE ( [ "abc" ] ) )            # [[]]

entry #2

written by kotnen
submitted at
0 likes

guesses
comments 0

post a comment


njuwu.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
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
# -*- coding: utf-8 -*-
# ^^^^^^^^^^^^^^^^^^^^^ emacs needs this i guess
# got told i need to comment my code more so here goes

from __future__ import annotations # need this in-case someone is using an
                                   # older version of python maybe? tbh. its
                                   # just habit to import it at this lol

import itertools # python stdlib is useful for once... kinda wish i was using

NULL = None

# typehinting is so cool... please help i hate myself for this so much
def entry(aaaaa: Iterable[len: R + 1, Iterable[len: C + 1, str]]) -> {()}:

    cn, *r = map(tuple, aaaaa) # i want tuples dammit, not other iter. types
    c = list(zip(*r  ))            # luckily, zip returns tuples automatically
                                   # ^^^ this comment was aligned properly with
                                   #     the other comment originally but then
                                   #     i changed the length of the previous
                                   #     line so now its not anymore

    char, *string = (NULL,) # nullptr, will later be replaced with a
                            # ptr to a string in the database
    
    # boss said we had to be careful about the edge cases, so here we are
    if len(r) < 2: # zero or one rows means we return empty tuple set
        empty_tuple_set = {()} # here's the empty tuple set ... lets return it
        return empty_tuple_set

    if len(set(r)) != len(r):
        print(r)
        return { ... } - { ... } # no comments for this (except this comment)

    # time for lunch break
    # :x!oh, im not using vim... guess ill just leave the editor
    # open while i eat
    
    
    # for <num of columns (abrev. column num, further abrev. coln)> in...
    # range(len ( r)):
    # wait actually lets cache the range(len
    # ) thing since we might need it later
    range_len_thing = tuple(range(len(c)))
    #                 ^^^^^ lets tupleize it (just in case)
    for coln in range_len_thing: # i knew we would need it later!! caching ftw
        
        e = { ... } - { ... } # again, no comments (except this one here)
        for AAA in itertools.combinations(range_len_thing, coln+1):
            # how do we tell python that `e' is not a local variable...
            # you might say it's a `notlocal` variable...
            
            F = lambda x: lambda y: x(y) # this is part of the magic later :3
            T = lambda x: lambda y: y(x) # this is part of the magic later :3
            # __code__.co_code editing is cool... # (double comment goes here)
            #                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            #                          that comment was only to make the lines
            #                          lineup nicely cause i like how it looks

            tz = tuple(zip(*[C for i, C in enumerate(c) if i in AAA]))
            # ^^^^^^ NOT a timezone:    t for tuple, z for zip
            #print(AAA, tz)
            if len(set(tz)) == len(tz):
                print(tz, AAA)
                e = e | {tuple(cn[i] for i in AAA)}
            
            # actually i lied we aren't using the lambda calculus at all
            # i bet you got all excited about seeing it didnt you...
            continue
        
        if e:
            return e

        continue

    raise FindCandidateKeysFunctionSomethingWentWrongErrorException("")
    #     ^^^^^^^^^^^^ we don't need to give it any more information other
    #                  than the empty string. the name of the exception
    #                  says enough

    return None




print(
    entry(
        [
            ["contest", "date held", "winner", "winner's second name"],
            ["dog fight", "oct 17 2000", "discarding sabot", "sabot"],
            ["cat-off", "jul 01 2001", "palm tree oil", "tree"],
            ["rat duel", "oct 05 2001", "cart of iron", "of"],
            ["rat duel", "mar 21 2006", "cart of iron", "of"],
            ["shark race", "mar 21 2006", "linguist", "NULL"],
        ]
    )
)

entry #3

written by vspf
submitted at
0 likes

guesses
comments 0

post a comment


46.py.py Unicode text, UTF-8 text, with very long lines (324)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
g="";a=input("".join([chr(ord(q)//127)+chr(ord(q)%127) for q in"⊩㧱㢮㧴㈻ㇽ㧭ၗ㒋㎸㦂ㆀ㊎㥶㫯၅㜆㣷㊎၉㚲㣽㭼ၓ㊋ゑん㉿၂㰧㫯㤂㑺る၂ゑ㤭ᑔᑷろㆼ㭲㧴ၔ㏽ၒ㞈㤭㧴㊈㥲㘊㊎ၓ㊋ゑん㉿၂㰧㛷㭵㒅㊎ᛜ⨔㈻㗵㄃㖴㣽㬩㥵㞆㗸၂㈻㧴㈻㌃㤁㦬㣽㬩㊉㧱㣳㇊အ㌎㊍၉㜂㩿㧵㛹ၔ㏽၆㒅るၒ㞈၏㊺ㇽ㧭ᗴ㠂㊎㤭㊉㧱㢮㨃㑺㉉Ԁ₭၅㯩㚃㗹၏㊺ㇽ㧭၉㚲㧴㈻ㆌ㤀㉾㦬㌉㣻ん၉㤭を၆㝽㘃㭼᳐㈘㊗〩㌖㌖㐡㌖㈘㞚㤊㈘㐡խ㏽㣳ၔ㏽ဂㆾᗴᅃᄊ၁㛶ဂぁ၉㚲㧴㈻㌃㤁㦬㣽㬩ゑ㈻㧴㈻㗵㄃㘇ᛜՊ㏽ၐ㣽㎋れၗ㒃㖴㣳㨁㣼၉㛵㞃㣳㆑ၒ㊎㩷㧿၉㊺㈑㟼㑺ん㈻㗵㄃㘇၁㣳ၕ㥲ㆼᑏ㐁ㆅၙ㞆ၐ㣽ヿㄊ㰧㥵㞆㗸㚹㦬㏹㫯၉㚲㱶㩽၄んめを㈻ろ㱾゘㤶Ԁ"]))
while a:g+=a+"\n";a=input()
g=g.split("\n")[:-1]
def o(n):return o(n-1)+[i+[n-1]for i in o(n-1)]if n else[[]]
if len(g)<3:print("Oops, not enough rows...");exit()
h=[i.split("|")for i in g]
if len(h[0])==1:print("Oops, not enough columns...");exit()
q=[[(G[K],h[0][K])for K in range(len(G))]for G in h[1:]]
J=[[[j[Q]for Q in i]for j in q]for i in o(len(q))]
X=[H for H in J if[H.count(l)for l in H]==[1]*len(H)]
W=[set([w[1] for w in x[0]]) for x in X]
if not W:print("Oops, no candidate keys...");exit()
F=[list(f) for f in W if len([p for p in W if p.issubset(f)])==1]
print("\n".join(["|".join(S) for S in F]))

entry #4

written by luatic
submitted at
0 likes

guesses
comments 0

post a comment


README.rst 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
==========================
CG 46: Find Candidate Keys
==========================

Input
=====

**Tab-Separated Values** (TSV) on standard input as Olive intended.
The escape sequences ``\t``, ``\n``, ``\r`` and ``\\`` are supported.

Example
-------

Here is the example table in TSV format::

	contest	date held	winner	winner's second name
	dog fight	oct 17 2000	discarding sabot	sabot
	cat-off	jul 01 2001	palm tree oil	tree
	rat duel	oct 05 2001	cart of iron	of
	rat duel	mar 21 2006	cart of iron	of
	shark race	mar 21 2006	linguist	NULL

Output
======

For consistency, the output is also **pseudo-TSV** that is written to standard output.

Edge cases:

* The empty set of columns is represented by an empty line.
* The empty set of candidate keys is represented by no lines being printed.

Example
-------

Here is the output for the example table::

	date held	winner's second name
	date held	winner
	contest	date held
find_candidate_keys.clj Unicode text, UTF-8 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
;; © 2042 Kim Apr
(ns find_candidate_keys
  (:require [clojure.string :as str]
            [clojure.set :as set]))
(def escs {"\\t" "\t" "\\n" "\n" "\\r" "\r" "\\\\" "\\"})
(defn rd-row [line]
  (map
   (fn [s] (str/replace s #"\\." (fn [c] (escs c c))))
   (str/split line #"\t")))
(defn rd-tsv []
  (let [ln (read-line)]
    (if (nil? ln) nil
           (cons (rd-row ln) (rd-tsv)))))
(defn transp [rws]
  (let [rst-rws (rest rws)]
    (if (empty? rst-rws)
         (map list (first rws))
        (map cons (first rws)
             (transp rst-rws)))))
(defn ntrvl [col]
  (filter
   ;; clj-kondo WILL lie to you!!!
   (fn [cl] (not (empty? (rest cl))))
   col))
(defn cl-add [cl i el] (assoc cl el (conj (cl el #{}) i)))
(defn eq-cls [col]
   (vals
    (reduce
     (fn [cl pair]
       (let [[i el] pair] (cl-add cl i el)))
      {}
     (map-indexed vector col))))
(defn mapify-eq-cls [cls]
  (reduce
   (fn [map cl]
     (reduce
      (fn [map i] (assoc map i cl))
      map
      cl))
   {}
   cls))
(defn merge-eq-cls [cls1 cls2]
  (let [m2 (mapify-eq-cls cls2)]
    (reduce
     (fn [cls cl1]
       (reduce
        (fn [cls cl2] (cons (set/intersection cl1 cl2) cls))
        cls
        (set (remove nil? (map m2 cl1)))))
     '()
     cls1)))
(defn map-subseq [f seq]
  (if (empty? seq) '()
      (cons (f seq) (map-subseq f (rest seq)))))
(defn cands [keys cnds]
  (if
   (empty? cnds) keys
   (reduce
    (fn [keys cnd]
      (if (empty? (cnd :eq))
        (cons (rest (reverse (map (comp first first) (cnd :cols)))) keys)
        (cands
         keys
         (remove nil? (map-subseq
          (fn [col]
            (let [mrgd (ntrvl (merge-eq-cls
                               (cnd :eq)
                               (ntrvl (eq-cls (rest (first col))))))]
              (if (= (cnd :eq) mrgd) nil
                  {:cols (cons col (cnd :cols)) :eq mrgd})))
          (rest (first (cnd :cols))))))))
    keys
    cnds)))
(defn cnd-empty [cols]
  (list {:cols (list (cons '() cols))
         :eq (ntrvl (list (set (range (count (rest (first cols)))))))}))
(def unescs (set/map-invert escs))
(defn wr-row [cnd]
  (println
   (str/join
    "\t"
    (map
     ;; It is with great disgust that I have to inform you that `.` in Java
     ;; matches "any character (may or may not match line terminators)"
     (fn [s] (str/replace s #".|\r|\n" (fn [c] (unescs c c)))) cnd))))
(defn wr-tsv [cnds]
  (run! wr-row cnds))
(wr-tsv (cands '() (cnd-empty (transp (rd-tsv)))))

entry #5

written by LyricLy
submitted at
0 likes

guesses
comments 0

post a comment


new macedonia.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from itertools import chain, combinations

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

s=eval(input())
if not s:
    print([()])
l = []
for p in powerset(s[0].keys()):
    if any([set(p)>set(x) for x in l]):
        continue
    ff =[tuple([r[x] for x in p]) for r in s]
    if len(ff)==len(set(ff)):
        l.append(p)
print(l)

entry #6

written by razetime
submitted at
1 like

guesses
comments 0

post a comment


bailiff.js Unicode text, UTF-8 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
 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
/*
 *********
 * JUDGE *
 *********
 * Order, order in the room please.
 * Good Morning, ladies and gentlemen. Calling the case of the People of the 
 * State of Esolangs versus Database Admin. Are both sides ready?
 */

/*
 *********************
 * DISTRICT ATTORNEY *
 *********************
 * Ready for the People, Your Honour.
 */

/*
 *******************
 * PUBLIC DEFENDER *
 *******************
 * Ready for the defense, Your Honour.
 */

/*
 *********
 * JUDGE *
 *********
 * Will the clerk please swear in the jury?
 */

/*
 *********
 * CLERK *
 *********
 * Will the jury please stand and raise your right hand? [Wait for
 * everyone to stand.] Do each of you swear that you will fairly try the
 * case before this court, and that you will return a true verdict according to
 * the evidence and the instructions of the court, so help you, God? Please
 * say “I do”. [Wait for jurors to say “I do.”] You may be seated.
 */

/*
 *********************
 * DISTRICT ATTORNEY *
 *********************
 * Your Honor and ladies and gentlemen of the jury: the defendant has been
 * charged with the act of the segregation of candidate keys from their natural
 * habitat. The evidence will show that a group of table keys were racially
 * profiled on the night of October 22nd. The next day the defendant was
 * arrested teaching the rules of apartheid segregation to the "superior" and
 * "unique" keys on October 29th. The evidence I will present to you will prove
 * that the defendant is guilty as charged.
 */

/*
 *******************
 * PUBLIC DEFENDER *
 *******************
 * Your Honor and ladies and gentlemen of the jury: under the law my client is
 * presumed innocent until proved guilty. During this trial, you will hear no
 * real evidence against my client. You will come to know the truth: that my
 * client was just performing the duties of his paid job with no ulterior
 * motives.
 * Therfore my client is not guilty.
 */
let hearing = (table) => {
        /*
         *********
         * JUDGE *
         *********
         * The prosecution may call its first witness.
         */

        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * The people call the Back End of the table.
         */

        /*
         *********
         * CLERK *
         *********
         * Please stand. Raise your right hand. Do you promise that the
         * testimony you shall give in the case before this court shall be the truth,
         * the whole truth, and nothing but the truth, so help you God?
         */

        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * The people call the Back End of the table.
         */

        /*
         ************
         * BACK END *
         ************
         * I do.
         */
        
        /*
         *********
         * CLERK *
         *********
         * Please state your first and last name.
         */
        
        /*
         ************
         * BACK END *
         ************
         * Relationah Aljabrah.
         */
        
        /*
         *********
         * CLERK *
         *********
         * You may be seated.
         */
        
        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * Please state the details of the crime as you saw it on the 22nd of October.
         */
        
        /*
         ************
         * BACK END *
         ************
         * i was out there mindin my own business when i noticed half my friends
         * was missin!
         */

        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * From this anecdote, we can conclude that the defendant was performing
         * an obstruction to the task of the BACK END worker, who was also 
         * a witness to the crime.
         */
        
        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * As the record may be seen in paragraph 5, your honour, there is a 
         * stark "special casing" requirement in the code for the current hearing.
         * This has been addressed in the below transcript.
         */
        if (table.length <= 2) {
                return [[]];
        }
        /*
         *********************
         * DISTRICT ATTORNEY *
         *********************
         * As the jury may be able to see, this "candidate key extraction"
         * was a premeditated crime. The perpetrators of the crime had their
         * target columns decided many lines before the time of return.
         */
        let col_names = table[0];
        let table_rows = table.slice(1);
        let candidate_keys = (col_indices, rows) => {
                /*
                 *******************
                 * PUBLIC DEFENDER *
                 *******************
                 * The given claims from the People, your honour, are false,
                 * as my client has an alibi during the time of crime.
                 * The number of columns for the table was also a stark
                 * "special case", preventing such a selection from happening!
                 */
                if (col_indices.length > 1) {
                        let result_keys = [];

                        for(let i = 0; i < col_indices.length; i++) {
                                let recur_col_indices = col_indices.slice();
                                recur_col_indices.splice(i,1);
                                /*
                                 *********
                                 * JUDGE *
                                 *********
                                 * The jury is thanked and excused for the session.
                                 * Court is adjourned, as we lack the stack frames to continue. 
                                 */
                                let result_iter = candidate_keys(recur_col_indices, rows);
                                for (let j = 0; j < result_iter.length; j++) {
                                        result_keys.push(result_iter[j]);
                                }
                        }
                        if (result_keys.length > 0) {
                                return result_keys;
                        }
                }
                let selected_rows = [];
                for (let i = 0; i < rows.length; i++) {
                        let curr_row = [];
                        for (let j = 0; j < col_indices.length; j++) {
                                curr_row.push(rows[i][col_indices[j]]);
                        }
                        selected_rows.push(curr_row);
                }
                for (let i = 0; i < selected_rows.length; i++) {
                        for (let j = 0; j < selected_rows.length; j++) {
                                if (i != j) {
                                        if (selected_rows[i].length == selected_rows[j].length) {
                                                let is_equal = true;
                                                for(let k = 0; k < selected_rows[i].length; k++) {
                                                        if (selected_rows[i][k] != selected_rows[j][k]) {
                                                                is_equal = false;
                                                                break;
                                                        }
                                                }
                                                if (is_equal) {
                                                        
                                                        return [];
                                                }
                                        }
                                }
                        }
                }
                return [col_indices];
        }
        let range = [];
        for (let i = 0; i < table_rows[0].length; i++) {
                range.push(i);
        }
        let candidate_key_indices =  candidate_keys(range, table_rows);
        let unique_candidate_keys = [];
        for (let i = 0; i < candidate_key_indices.length; i++) {
                let isnt_added = true;
                for(let j = 0; j < unique_candidate_keys.length; j++) { 
                        let is_equal = true;
                        if (candidate_key_indices[i].length == unique_candidate_keys[j].length) {
                                for (let k = 0; k < candidate_key_indices.length; k++) {
                                        if (candidate_key_indices[i][k] != unique_candidate_keys[j][k]) {
                                                is_equal = false;
                                                break;
                                        }
                                }
                        } else {
                                is_equal = false;
                        }
                        if (is_equal) {
                                isnt_added = false;
                                break;
                        }
                }
                if (isnt_added) {
                        unique_candidate_keys.push(candidate_key_indices[i]);
                }
        }
        for (let i = 0; i < unique_candidate_keys.length; i++) {
                for (let j = 0; j < unique_candidate_keys[i].length; j++) {
                        unique_candidate_keys[i][j] = col_names[unique_candidate_keys[i][j]];
                }
        }
        return unique_candidate_keys;
};

entry #7

written by kimapr
submitted at
1 like

guesses
comments 0

post a comment


meow.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
mreow=((meowest,submissive,meow,mreow,Mreow)=>{meow =_=>
new Set();meowest=(prrr,Meow)=>!((mreow,Prrr)=>
{Prrr=meow();for(mreow of Meow)
{if((meow=>(meow=JSON.stringify(meow),Prrr.has(meow)?1:(Prrr
.add(meow),0)))(prrr.map(i=>mreow[i]))){return 1}}//          ^     ^   - Meow
return 0;})();submissive=(owo,//                            /  |   |  \
uwu)=>((Owo,Uwu)=>{for(;Owo>=0//                           | \___.___/ |
&&Uwu>=0;Owo--,Uwu--)while(owo[Owo]!=uwu[Uwu]//            \           /
&&Owo>=0)Owo--;Owo++;Uwu++;return Uwu>=0&&Owo>=0})(owo.length-1,uwu.length
-1);Mreow=(meow,mreow,mrrp,prrr,Prrr,Meow)=>(//
(nyaa,Mrrp)=>{if(Meow.length<=//              prrr
1){meow.mrrp.push([]);return}Mrrp=0;for(;mrrp<prrr;mrrp++){
/* * * * * */nyaa=mreow.concat([mrrp]);if(/*  prrr   */    meowest  (nyaa,Meow))
/*   ^ ^   */{meow.mrrp.forEach((prrr,Prrr)=>(prrr!=[][0]? submissive(prrr,nyaa)
/*  (O_O)  */&&(meow.mrrp[Prrr]=[][0]):Mrrp++));Mrrp
/*  /   \  */>=meow.mrrp.length/2&&(meow.mrrp=meow.mrrp.   filter // ( mreow ? )
/*  ^^ ^^  */(meow=>(meow!=[][0])));meow.mrrp.push//       dismissive( :(  ;w; )
/*|||||||||*/(nyaa)}else Mreow(meow,nyaa,mrrp+1,
/*.-.-.-.-.*/ prrr,Prrr,Meow)}})();mreow
=(Prrr,...Meow)=>((prrr)=>(prrr={mrrp:[]},Mreow(prrr
,[],0,Prrr.length,Prrr,Meow),prrr.mrrp.filter(
meow=>meow!=[][0]).map(meow=>meow.map(meow=>
Prrr[meow]))))();return mreow})()

/*
consowo.meow(mreow(
	["contest","date held","winner","winner's second name"],
	["dog fight","oct 17 2000","discarding sabot","sabot"],
	["cat-off","jul 01 2001","palm tree oil","tree"],
	["rat duel","oct 05 2001","cart of iron","of"],
	["rat duel","mar 21 2006","cart of iron","of"],
	["shark race","mar 21 2006","linguist",null]
))
//*/

entry #8

written by olus2000
submitted at
1 like

guesses
comments 0

post a comment


main.ua Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# uiua version 0.0.22
# Function set modeled as a rank-2 array of scalars
Ded ← =⊡1△∶≡'⧻⊝.
Nxt ← ▽≡(/×/<⬚'¯∞↙2)./⊂⊠⊂⇡
Entry ← |1 ⊙';;⍥(⎋=0⧻.Nxt∶⊙,(;|⎋1⊏⊚)/↥.Ded⊠⊏,,)∞[[]]∶⬚0⊡1△.

△.Entry ["asdfgh"
         "awdrgy"
         "qwerty"
         "asergh"
         "asefgh"]
△.Entry ["a"]
△.Entry ["asdf" "asdf"]
△.Entry []