Skip to main content
added 312 characters in body
Source Link
Unrelated String
  • 23k
  • 3
  • 32
  • 55

Jelly, 2424 22 bytes

aŻƤSƇḢßoɓ@ooƑ?
Ṭ×),o,aŻƤSƇḢʋɗ@/oƑ/¿Sɗƒ0ç@ƒ0

Try it online!Try it online!

I still have the strangest feeling that something closer to Dennis's answer should beat this, but I haven't had any luck with that so far. I have twisted the first line into something that sounds like some kind of exploding can (from my original recursive solution; I thought it saved a byte but I didn't look at the output too carefully so it actually ties but it does look funnier).

  )        aŻƤSƇḢßoɓ@ooƑ?    Helper link: add a pre-positioned guest to the hotel

     For each guest value,
Ṭɓ         With reversed arguments (hotel left, guest right):
           oƑ? obtain a list ofUnless allboth zeroesarrays thenhave a onenonzero at thatthe indexsame location,
 ×                     o     and multiply thatreturn bywith the same guest value.
       placed in its empty room;
        ɓ  ɗƒ0    Starting with 0, reduceif thatthey bydo:
   ,      @        (guest left, hotel right)
a       Pair the accumulator with the guest.
       Overlay the guest's zeroes on the hotel.
 ŻƤ  oƑ/¿        While both paired arrays have aPrepend nonzeroanother atzero theto sameeach locationprefix,
          SƇḢ   ɗ@/           and lettake the first be on the right and the second onwith thea leftnonzero of:sum.
    o      ß           Call this link again with that overlayas the left's nonzero value on thenew right,guest
     ,      ʋ     o          and pair that with:
      athe hotel having the previous guest replace the new one.

Ṭ×)ç@ƒ0    Main link

  )     overlay the left's zeroesFor oneach theguest rightvalue,
       ŻƤ             obtain a list of all zeroes prependthen anothera zeroone toat eachthat prefixindex,
         SƇḢ       ×         and takemultiply thethat firstby withthe asame nonzeroguest sumvalue.
             ƒ0    Starting with 0, Sreduce that by
   ç@  After the loop, sum the corresponding elementshelper ofwith eachreversed arrayarguments.

Essentially just boots occupants out of their rooms in sequence until there's no collision, considering a new guest as equivalent to someone evicted from the last room they can't start in. A nice recursive formulation should beat than this pair-loop-reduce hack, but I'm struggling to pull it off.

Jelly, 24 bytes

Ṭ×),o,aŻƤSƇḢʋɗ@/oƑ/¿Sɗƒ0

Try it online!

I have the strangest feeling that something closer to Dennis's answer should beat this, but I haven't had any luck with that so far.

  )                         For each guest value,
Ṭ                           obtain a list of all zeroes then a one at that index,
 ×                          and multiply that by the same guest value.
                     ɗƒ0    Starting with 0, reduce that by:
   ,                        Pair the accumulator with the guest.
                oƑ/¿        While both paired arrays have a nonzero at the same location,
             ɗ@/            let the first be on the right and the second on the left of:
    o                       overlay the left's nonzero value on the right,
     ,      ʋ               and pair that with:
      a                     overlay the left's zeroes on the right,
       ŻƤ                   prepend another zero to each prefix,
         SƇḢ                and take the first with a nonzero sum.
                    S       After the loop, sum the corresponding elements of each array.

Essentially just boots occupants out of their rooms in sequence until there's no collision, considering a new guest as equivalent to someone evicted from the last room they can't start in. A nice recursive formulation should beat than this pair-loop-reduce hack, but I'm struggling to pull it off.

Jelly, 24 22 bytes

aŻƤSƇḢßoɓ@ooƑ?
Ṭ×)ç@ƒ0

Try it online!

I still have the strangest feeling that something closer to Dennis's answer should beat this, but I haven't had any luck with that so far. I have twisted the first line into something that sounds like some kind of exploding can (from my original recursive solution; I thought it saved a byte but I didn't look at the output too carefully so it actually ties but it does look funnier).

aŻƤSƇḢßoɓ@ooƑ?    Helper link: add a pre-positioned guest to the hotel

        ɓ         With reversed arguments (hotel left, guest right):
           oƑ?    Unless both arrays have a nonzero at the same location,
          o       return with the guest placed in its empty room;
        ɓ         if they do:
         @        (guest left, hotel right)
a                 Overlay the guest's zeroes on the hotel.
 ŻƤ               Prepend another zero to each prefix,
   SƇḢ            and take the first with a nonzero sum.
      ß           Call this link again with that as the new guest
       o          and with the hotel having the previous guest replace the new one.

Ṭ×)ç@ƒ0    Main link

  )        For each guest value,
          obtain a list of all zeroes then a one at that index,
 ×         and multiply that by the same guest value.
     ƒ0    Starting with 0, reduce that by
   ç@      the helper with reversed arguments.

Essentially just boots occupants out of their rooms in sequence until there's no collision, considering a new guest as equivalent to someone evicted from the last room they can't start in.

Source Link
Unrelated String
  • 23k
  • 3
  • 32
  • 55

Jelly, 24 bytes

Ṭ×),o,aŻƤSƇḢʋɗ@/oƑ/¿Sɗƒ0

Try it online!

I have the strangest feeling that something closer to Dennis's answer should beat this, but I haven't had any luck with that so far.

  )                         For each guest value,
Ṭ                           obtain a list of all zeroes then a one at that index,
 ×                          and multiply that by the same guest value.
                     ɗƒ0    Starting with 0, reduce that by:
   ,                        Pair the accumulator with the guest.
                oƑ/¿        While both paired arrays have a nonzero at the same location,
             ɗ@/            let the first be on the right and the second on the left of:
    o                       overlay the left's nonzero value on the right,
     ,      ʋ               and pair that with:
      a                     overlay the left's zeroes on the right,
       ŻƤ                   prepend another zero to each prefix,
         SƇḢ                and take the first with a nonzero sum.
                    S       After the loop, sum the corresponding elements of each array.

Essentially just boots occupants out of their rooms in sequence until there's no collision, considering a new guest as equivalent to someone evicted from the last room they can't start in. A nice recursive formulation should beat than this pair-loop-reduce hack, but I'm struggling to pull it off.

Dennis's answer with some simple golfs for fair comparison, and an explanation for those still wondering:

Jelly, 26 bytes

’⁹ḣ;⁸;ṫ@œṡ0Fɗð0ẋ;@
ç@ƒ0œr0

Try it online!

’⁹ḣ;⁸;ṫ@œṡ0Fɗð0ẋ;@    Helper link: add a guest on the left to the hotel on the right

             ð        Let the right argument to the rest of the link be
              0ẋ      zero repeated by the value of the guest
                ;@    concatenated to the end of the hotel.
 ⁹ḣ                   Take elements from that right argument numbering
’                     one less than the guest,
   ;⁸                 concatenate the guest,
     ;      ɗ         and concatenate:
      ṫ@              remove elements from that right argument numbering the guest value,
        œṡ0           split those remaining around the first zero,
           F          and flatten them back together.

ç@ƒ0œr0    Main link

ç@ƒ0       With the hotel starting as 0, add each guest to the hotel in sequence.
    œr0    Trim trailing zeroes.