previndexinfonext

code guessing, round #24 (completed)

started at ; stage 2 at ; ended at

specification

phonebooks are a thing of the past. implement an associative array. programs can be written in python, haskell, ocaml, or f#.

an associative array, also known as a map or dictionary and often implemented as a hash table or search tree, is a type of collection that associates unique keys with values, allowing fast lookup based on these keys.

the required interface this round consists of 3 functions: creating a new object, looking up an entry and inserting a new entry. if lookup fails, return a special error value (detailed in the APIs section). inserting should overwrite any existing entry in the array.

keys are guaranteed to be equatable. you may also impose other restrictions on the key; for example, a hash table may require that the keys are hashable, or a tree may require they can be ordered.

APIs:

results

  1. 👑 soup girl +5 -0 = 5
    1. Olivia
    2. Olive (was LyricLy)
    3. olus2000
    4. pii
    5. BeatButton
    6. razetime
    7. LyricLy (was Olive)
  2. razetime +4 -1 = 3
    1. Olivia
    2. LyricLy
    3. olus2000
    4. pii
    5. soup girl (was BeatButton)
    6. BeatButton (was Olive)
    7. Olive (was soup girl)
  3. LyricLy +2 -1 = 1
    1. Olivia
    2. pii
    3. Olive (was BeatButton)
    4. BeatButton (was razetime)
    5. soup girl (was Olive)
    6. razetime (was soup girl)
  4. Olive +0 -0 = 0
    1. BeatButton +0 -1 = -1
      1. Olivia +1 -3 = -2
        1. razetime (was LyricLy)
        2. olus2000
        3. LyricLy (was pii)
        4. soup girl (was BeatButton)
        5. pii (was razetime)
        6. BeatButton (was Olive)
        7. Olive (was soup girl)
      2. olus2000 +1 -3 = -2
        1. soup girl (was Olivia)
        2. BeatButton (was LyricLy)
        3. pii
        4. Olive (was BeatButton)
        5. LyricLy (was razetime)
        6. Olivia (was Olive)
        7. razetime (was soup girl)
      3. pii +0 -4 = -4
        1. Olive (was Olivia)
        2. razetime (was LyricLy)
        3. LyricLy (was olus2000)
        4. olus2000 (was BeatButton)
        5. BeatButton (was razetime)
        6. soup girl (was Olive)
        7. Olivia (was soup girl)

      entries

      you can download all the entries

      entry #1

      written by Olivia
      submitted at
      5 likes

      guesses
      comments 7
      olus2000 *known at the time as [author of #3] ¶

      i'm...a,BIG-SHOT


      LyricLy ¶

      i'm...a,BIG-SHOT


      Olivia ¶

      i'm...a,BIG-SHOT


      pii *known at the time as [author of #4] ¶

      i'm...a,BIG-SHOT


      razetime ¶

      i'm...a,BIG-SHOT


      Olivia *known at the time as [author of #1] ¶

      i'm...a,BIG-SHOT


      soup girl ¶

      i'm...a,BIG-SHOT


      post a comment


      DEAL.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
      "https://cg.esolangs.gay/24";API:"Entry";t=lambda*a,**f:type("",(),dict(a)|f);(
      l:=lambda*k:lambda*f:lambda*a:f[0](**dict(zip(k,a))));i=l("x")(lambda**_:_["x"]
      );c=l(*"fg")(lambda**_:lambda*a:_["f"](_["g"](*a)));C=lambda *f:__import__("f"+
      "unctools").reduce(c,f,i);d=lambda**f:__import__( "datacla" "sses").dataclass(t
      (("__annotations__", dict(filter(C( bool,getattr(1  ,"__"  "sub__"),callable,i,
      __import__("operator") .itemgetter (1)),f.items()))   ),  **f));s=l("n")(lambda
      **_:l("f")(lambda**___: lambda*aa :___["f"](*aa[_["n"     ]:]))  );D=l(*"n","f"
      )(lambda**_:i(  lambda*d  :''or  (lambda*a:_[ "f"](*[*   a,*d  ][:_["n"]]))));(
      g:=l(*"nk","d")( lambda*   __   ,**_:(_[ "d"])  if(_   ["n"   ]==None)else(g(_[
      "n"].l,_["k"],_[0  or"d"])    if((_[ "" "k"]<_[  ''   "n"    ].k))else(g(_["n"]
      .r,_["k"],_["\x64"   ])if((  _["n"].k   <_["k"]) +   10    ==0xa)else(_["n"].v)
      ))));u=l(*"spnikv"*    int(i   (1)))   (lambda**         _:setattr((_["p"])or(_
      ["s"]),"rl"[_["i"]],     N(_[    "   k".strip  (      "\40")],_["v"]))if(_["n"]
      ==None)else(u(_["s"],_[     ""      "n"],_["n"      ].l,1,_["k"],_["v"])if(_["\
      k"]<_["""n"""""].k)else(u     (_    ["\s"],_[      "n"],_["n"].r,False,_["k"],_
      ["v"])if(_["n"].k<_["k"]or(    _[     "n"].k     <_["n"].k))else(setattr(_["n"]
      ,"v",_["v"])))));N=d(k="??",v     =    "!!"     ,l=None,r=None);Entry=d(r=None,
      get=D(3,l(*"skd")(lambda**_:g(_    [    ""     "s"].r,_["k"],_["d"],)))(None,),
      insert=l("s",*"kv")(lambda**_:u(_             ["s"],None,_["s"].r,False,_["k"],
      _["v"])),__str__=l("s")(lambda**_             :"".join(map(str,filter(None,((((
      _["s"].r,)))))))));N.__str__=l("s")          (lambda**_:"".join(map(["({})","{"
      "}","({})"].__getitem__,J:=list(map         ((K:=list(map(getattr(_["s"],"__ge"
      "tattribute__"),"lvr"))).index,i(i(         i( i (filter)(None,K)))))))).format
      (*map(K.__getitem__,J)));HEY_THERE,            ="LOST_EVERYTHING_YOU_LOVED?",;(
      __annotations__:=t(__setitem__=   s         (1)(l("k","v")(lambda**_:globals().
      __setitem__(_["k"],_["v"]))))());[          *WELL_DO_I_HAVE_A_DEAL_FOR_YOU,]="\
      \U0001F4C8";YOU_LITTLE_SPONGE:"JUST         COMMENT_ON_THIS_ENTRY_SAYING_THIS:"
      '''i'm...a,BIG-SHOT''';__debug__==           False==print("run","unoptimised");
      JUST_DO_THAT_ONE_THING,AND,VOILA,             *_="EVERYTHING_WILL_BE_SOLVED","\
      THEY_WILL_LAUGH_AT_YOUR_JOKES                    ","YOU_WILL_NOT_BE_A_FAILURE";
      

      entry #2

      written by LyricLy
      submitted at
      3 likes

      guesses
      comments 2
      razetime ¶

      the writer of this submission has a huge johnson


      LyricLy *known at the time as [author of #2] replying to razetime ¶

      thank you


      post a comment


      entry.hs ASCII text
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      {-# LANGUAGE RankNTypes #-}
      
      module Entry where
      
      import Johnson
      
      type Entry k a = k -> (forall b. b -> (a -> b) -> b)
      
      round and round the merry go = round
      
      empty = sonj
      lookup = johnso johnso Just . johnso johnso Nothing . johnso ($)
      insert k v m = ohnsonj (\x -> if x == k then const else const id) v m
      
      johnson.hs ASCII text
      1
      2
      3
      4
      5
      6
      7
      8
      module Johnson where
      
      j o hns = o
      n j ohnson johnson = johnson j
      ohnson _ johnso _ njohnson = johnso njohnson
      johnso n john sonj = ohnson j (ohnson johnso n john sonj) ohnson john
      sonj = ohnson () j ohnson j
      ohnsonj oh ns on j = ohnson j (ohnson j (ohnson j oh (ns, on) j) () (ohnson (j, oh) n (sonj, oh) ns)) (on, j) (ohnson (j, oh, ns) on () j)
      

      entry #3

      written by olus2000
      submitted at
      2 likes

      guesses
      comments 1
      olus2000 *known at the time as [author of #3] ¶

      Oh for fucks sake. Feature request: preview which files I uploaded before stage 2 starts.


      post a comment


      Ef_sharp.fsx 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
      (* // Code by SoundOfSpouting#6980 (UID: 151149148639330304) *)
      
      (* The constructor is `Entry` instead of `Entry()`, otherwise as required *)
      
      type Color = Red | Black
      
      type Entry<'Key, 'Value when 'Key: comparison> =
          | Empty
          | Tree of smaller: Entry<'Key, 'Value> * key: 'Key * value: 'Value
                  * bigger: Entry<'Key, 'Value> * color: Color
      
          member this.TryFind (key: 'Key) : 'Value option =
              match this with
              | Empty -> None
              | Tree (s, k, v, b, _) ->
                  if k = key then
                      Some v
                  else
                      if key > k then b.TryFind key
                      else s.TryFind key
          
          member this.Add (key : 'Key) (value: 'Value) : Entry<'Key, 'Value> =
              match this.ChildAdd key value with
              | Tree (s, k, v, b, Red) -> Tree (s, k, v, b, Black)
              | other -> other
      
          member private this.ChildAdd (key : 'Key) (value: 'Value) : Entry<'Key, 'Value> =
              match this with
              | Empty -> Tree (Empty, key, value, Empty, Red)
              | Tree (s, k, v, b, c) ->
                  if k = key then Tree (s, key, value, b, c) else
                  ( if key > k then Tree (s, k, v, b.ChildAdd key value, c)
                    else Tree (s.ChildAdd key value, k, v, b, c) ).rebalance
          
          member private this.rebalance : Entry<'Key, 'Value> =
              match this with
              | Tree (Tree (Tree (a, x, xv, b, Red), y, yv, c, Red), z, zv, d, Black)
              | Tree (Tree (a, x, xv, Tree (b, y, yv, c, Red), Red), z, zv, d, Black)
              | Tree (a, x, xv, Tree (Tree (b, y, yv, c, Red), z, zv, d, Red), Black)
              | Tree (a, x, xv, Tree (b, y, yv, Tree (c, z, zv, d, Red), Red), Black) ->
                  Tree (Tree (a, x, xv, b, Black), y, yv, Tree(c, z, zv, d, Black), Red)
              | other -> other
      
      Husk_L.hs ASCII text, with no line terminators
      1
      -- // Code by SoundOfSpouting#6980 (UID: 151149148639330304)
      
      Oh_camel.cma 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
      (* // Code by SoundOfSpouting#6980 (UID: 151149148639330304) *)
      
      module type OrderedType =
        sig
          type t
          val compare: t -> t -> int
        end
      
      module type S =
        sig
          type key
          type +'a t
          val empty: 'a t
          val find_opt: key -> 'a t -> 'a option
          val add: key -> 'a -> 'a t -> 'a t
        end
      
      module Make(Ord: OrderedType) = struct
          type key = Ord.t
          type 'a t = (key * 'a) list
          let empty = []
          let rec find_opt x = function
              [] -> None
            | (k, v) :: r ->
                let c = Ord.compare x k in
                if c = 0 then Some v
                else find_opt x r
          let add x data assoc = (x, data) :: assoc
        end
      
      Pi_thone.py ASCII text
      1
      2
      3
      4
      5
      # // Code by SoundOfSpouting#6980 (UID: 151149148639330304)
      
      class Entry(dict):
      		def insert(self, key, val):
      				self[key] = val
      

      entry #4

      written by pii
      submitted at
      3 likes

      guesses
      comments 0

      post a comment


      24.zip Zip archive data, at least v2.0 to extract, compression method=store
      dir 24
      main.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
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      import os, json, ntpath, shutil
      
      class Node():
      	def __init__(self, key, data, path):
      		self.key = key # must be a string
      		self.data = data
      		self.path = path
      
      	def getLeft(self):
      		if os.path.isdir(self.path + "left/"):
      			p = self.path + "left/"
      			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
      			obj = json.load(open(f))
      			node = Node(obj["key"], obj["data"], obj["path"])
      			return node
      		return None
      
      	def getRight(self):
      		if os.path.isdir(self.path + "right/"):
      			p = self.path + "right/"
      			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
      			obj = json.load(open(f))
      			node = Node(obj["key"], obj["data"], obj["path"])
      			return node
      		return None
      
      	def getParent(self):
      		p = self.path.split('/')[1:-1]
      		if p[-1] != "tree":
      			p = f"/{'/'.join(p[:-1])}/"
      			f = [x for x in os.listdir(p) if x.endswith(".json")][0]
      			obj = json.load(open(f))
      			node = Node(obj["key"], obj["data"], obj["path"])
      			return node
      		return None
      
      	def write(self):
      
      		if not os.path.isdir(self.path): os.makedirs(self.path, exist_ok=True)
      		f = open(self.path + self.key + ".json", "w+")
      		payload = {"path": self.path, "key": self.key, "data": self.data}
      		json.dump(payload, f)
      		f.close()
      
      class Entry:
      	def __init__(self):
      		pass
      
      	def get(self, key, default=None):
      		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
      		while 1:
      			if not os.path.isdir(path):
      				break
      			else:
      				data = path + [x for x in os.listdir(path) if x.endswith(".json")][0]
      				fkey = ntpath.basename(data)[:-5]
      				if fkey == key:
      					obj = json.load(open(data))
      					return obj["data"]
      				elif key >= fkey: path += "right/"
      				else: path += "left/"
      		return default
      
      	def insert(self, key, value):
      		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
      		while 1:
      			if not os.path.isdir(path) or not len(ld := os.listdir(path)):
      				node = Node(key, value, path)
      				node.write()
      				return self
      			else:
      				data = path + [x for x in ld if x.endswith(".json")][0]
      				fkey = ntpath.basename(data)[:-5]
      				if fkey == key:
      					node = Node(key, value, path)
      					node.write()
      					return self
      				elif key >= fkey: path += "right/"
      				else: path += "left/"
      
      	def clean(self): # erases the "memory"
      		path = os.path.dirname(os.path.realpath(__file__)) + "/tree/"
      		shutil.rmtree(path)
      		os.mkdir(path)
      
      dir __MACOSX
      ._24 AppleDouble encoded Macintosh file
      1
      cg: couldn't decode file contents
      

      entry #5

      written by BeatButton
      submitted at
      2 likes

      guesses
      comments 0

      post a comment


      entry.py ASCII text
      1
      2
      3
      4
      5
      6
      7
      8
      9
      Entry = type(
          'Entry',
          (),
          dict(
              __init__=lambda self: (setattr(self, 'entries', list()), setattr(self, 'keys', dict())) and None,
              get=lambda self, key, default=None: self.entries.__getitem__(self.keys.__getitem__(key)) if key in self.keys else default,
              insert=lambda self, key, value: (lambda: self.entries.__setitem__(self.keys[key], value), lambda: (self.keys.__setitem__(key, len(self.entries)), self.entries.append(value)) and None)[0 if key in self.keys else 1](),
          ),
      )
      

      entry #6

      written by razetime
      submitted at
      1 like

      guesses
      comments 5
      razetime *known at the time as [author of #6] ¶

      [submission author]


      pii *known at the time as [author of #4] ¶

      [author of #4]


      soup girl *known at the time as [author of #8] ¶

      [author of #1]


      Olivia ¶

      [Author of #3]


      Olivia ¶

      fuck


      post a comment


      associative array, also known as a map or dictionary and often implemented as a hash table or search tree.py ASCII text
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      class Entry:
        def __init__(self):
      	self.keys = []
      	self.values = []
        
        def get(self, key, default=None):
      	for i in range(len(self.keys)):
      	  if len(str(self.keys[i])) == len(str(key)):
      		if self.keys[i] == key:
      		  return self.values[i]
      	return default
        
        def insert(self, key, value):
      	if key in self.keys:
      	  self.values[self.keys.index(key)] = value
      	else:
      	  self.keys.append(key)
      	  self.values.append(value)
      

      entry #7

      written by Olive
      submitted at
      2 likes

      guesses
      comments 1
      razetime *known at the time as [author of #6] ¶

      Hype for ALAN WAKE 2


      post a comment


      alan.py ASCII text
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      class Entry:
          '''An associative array. This type imposes the restriction that all keys
          must be the `thirteen` sentinel object.'''
          thirteen = object()
          def __init__(self):
              self.maybe = False
          def get(self, key, default=None):
              return self.value if self.maybe and key is self.thirteen else default
          def insert(self, key, value):
              if key is not self.thirteen: raise KeyError
              self.maybe = True
              self.value = value
      

      entry #8

      written by soup girl
      submitted at
      1 like

      guesses
      comments 2
      razetime ¶

      bigfoot is coming for u


      soup girl *known at the time as [author of #8] ¶

      I see


      post a comment


      leasteffortfulcgsolution.hs ASCII text, with CRLF line terminators
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      module Entry where
      import Prelude hiding (lookup)
      
      data Entry by lyric = The | Lyric by lyric (Entry by lyric)
      
      lookup at The = Nothing
      lookup to (Lyric is not lyric) = if is == to
                                     then Just not
                                     else lookup to lyric
      
      empty = The
      insert = Lyric