13
\$\begingroup\$

You are James and four of your friends (Bjarne, Eich, Rossum, Ada) are called for an interview. There are n interviewers, and they can each serve one person at a time, alphabetically. Each round of interview takes 20 min.

Let's take n = 2,

So, the first round started with Ada and Bjarne, takes 20 min (they're handled simultaneously). Then, interviewers call persons for next round, who are Eich and James, they took another 20 min.

Hence, finally you're out after 40 min.


Challenge

Given an array as input like ["yourName", [an, Array, Of, Friends], numberOfInterviewers], your task is to output the time it'll take for you to complete the interview, in minutes.

Feel free to take three arguments as input, instead of the array.

Sample I/O:

(In = Out format)

[ "James", ["Bjarne", "Eich"   , "Rossum", "Ada"  ], 2  ]   =   40
[ "Stark", ["Steve" , "Tchalla", "Banner", "Scott"], 3  ]   =   20
[ "spam" , ["bar"   , "eggs"   , "foo"   , "lorem"], 1  ]   =   100
[ "Oggy" , ["Jack"  , "DeeDee" , "Marky" , "Bob"  ], 10 ]   =   20

This is a , so fewest bytes will win!

\$\endgroup\$
8
  • 5
    \$\begingroup\$ Why can't you just do Alice, Bob, Carol, Dave, Eve? It makes the challenge significantly easier to understand. \$\endgroup\$
    – user96495
    Aug 9, 2020 at 12:22
  • \$\begingroup\$ @petStorm, I'd like to make it a bit interesting. \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 12:28
  • 1
    \$\begingroup\$ No @Shaggy, it's not possible now. Further, all 5 names are unique, to make the challenge legal. Also, number of interviewers could not be zero. \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 14:52
  • 1
    \$\begingroup\$ Bad? Okay, let me repair that example, just a sec. Also, all the names are one-word and in capitalized form. @user, edited the example. \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 15:14
  • 1
    \$\begingroup\$ @RahulVerma Thank you very much! That's not exactly what I meant - I was fine with the challenge being harder, but hopefully this will make it easier for people to focus on the core of the problem \$\endgroup\$
    – user
    Aug 9, 2020 at 15:17

19 Answers 19

8
\$\begingroup\$

Python 2, 40 39 bytes

-1 byte thanks to @JonathanAllan!

lambda s,l,n:~sum(x<s for x in l)/n*-20

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ lambda s,l,n:~sum(x<s for x in l)/n*-20 saves one :) \$\endgroup\$ Aug 9, 2020 at 17:53
7
\$\begingroup\$

JavaScript (ES6),  44  40 bytes

(s,a,n)=>-~(a.map(S=>k+=s>S,k=0),k/n)*20

Try it online!

\$\endgroup\$
5
\$\begingroup\$

R, 50 49 33 32 bytes

Edit: -1 byte thanks to Robin Ryder

function(y,f,n)sum(f<y,n)%/%n*20

Try it online!

\$\endgroup\$
2
4
\$\begingroup\$

Raku, 23 bytes

(*Xgt*).sum div*×20+20

Try it online!

Gets the number of other people before us in the queue, integer divides that by n, adds 1 and multiplies by 20.

\$\endgroup\$
4
\$\begingroup\$

Jelly, 11 bytes

ṭṢi³N:⁵×-20

A full program accepting arguments name, friends, and n which prints the result.

Try it online!

How?

ṭṢi³N:⁵×-20 - Main Link: name, friends
ṭ           - tack (friends to name)
 Ṣ          - sort
   ³        - 1st program arg = name
  i         - (1-based) index of (name in sort result)
    N       - negate
      ⁵     - 3rd program arg = n
     :      - integer division
        -20 - minus twenty
       ×    - multiply
            - implicit print
\$\endgroup\$
2
  • \$\begingroup\$ Do you mean n rather than ten in the explanation (talking about superscript 5)? \$\endgroup\$ Aug 11, 2020 at 23:09
  • \$\begingroup\$ @cairdcoinheringaahing I did, thanks. Force of habbit! \$\endgroup\$ Aug 11, 2020 at 23:56
3
\$\begingroup\$

Python 3, 53 45 44 43 bytes

lambda a,b,c:~sorted([a]+b).index(a)//c*-20

Try it online!

Adds your name to list of friends, sorts the list and calculates the answer from the index of your name in the sorted list.

Special thanks to Jonathan Allan for -1 byte

\$\endgroup\$
1
  • \$\begingroup\$ lambda a,b,c:~sorted([a]+b).index(a)//c*-20 saves one :) \$\endgroup\$ Aug 9, 2020 at 17:40
3
\$\begingroup\$

Ruby, 46 40 39 38 31 bytes

->a,b,c{~b.count{|i|i<a}/c*-20}

-5 -1 byte from petStorm.

-1 byte from Rahul Verma.

-7 bytes from Dingus.

Try it online!

Ruby, 83 bytes

->a,b,c{(b.push(a).sort.each_slice(c).map{|x|x.include?(a)}.find_index(true)+1)*20}

Try it online!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ 41 bytes \$\endgroup\$
    – user96495
    Aug 9, 2020 at 12:28
  • \$\begingroup\$ -1 byte \$\endgroup\$
    – Razetime
    Aug 9, 2020 at 12:31
  • \$\begingroup\$ Squeeze out a byte by using filter. \$\endgroup\$
    – user96495
    Aug 9, 2020 at 12:58
  • \$\begingroup\$ Another byte squeezed off! \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 13:04
  • 3
    \$\begingroup\$ You must be kidding me \$\endgroup\$
    – Razetime
    Aug 9, 2020 at 13:06
3
\$\begingroup\$

Rust, 56 55 bytes

|s,l:&[&str],n|20+l.iter().filter(|x|*x<s).count()/n*20

Try it online!

Special thanks to user and madlaina

This is my first ever code golf so I hope I have the format correct!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Try using Try it online. It counts your bytes and even generates Markdown for you \$\endgroup\$
    – user
    Aug 10, 2020 at 22:42
  • \$\begingroup\$ Ah nice, although I put the semi-colon in the footer \$\endgroup\$ Aug 10, 2020 at 22:46
  • \$\begingroup\$ You can expand the parentheses and save a byte: 20+l.iter().filter(|x|*x<s).count()/n*20 \$\endgroup\$
    – madlaina
    Aug 12, 2020 at 10:07
2
\$\begingroup\$

Io,  48  45 bytes

method(s,a,n,((a select(<s)size+1)/n)ceil*20)

Try it online!

Explanation

method(s,a,n,((      // Take 3 arguments.
    a select(<s)     // Take all items in the array a that is smaller than s
       size + 1)     // Take the size of that, and add 1
    /n)              // Divide it by n
ceil * 20)           // Take the ceiling of that, multiply by 20
\$\endgroup\$
2
\$\begingroup\$

J, 19 bytes

20*1+(<.@%~0 i.~/:)

Try it online!

How it works

 20*1+(<.@%~0 i.~/:)
                  /:  ascending indices for sorting
             0 i.~    find your name
           %~         divided by interviewers
        <.@           and floored
  20*1+               +1 then *20
\$\endgroup\$
1
2
\$\begingroup\$

05AB1E , 16 bytes

R`©¸«{®QsôOƶ20*O

Explentation:

R`©¸«{®QsôOƶ20*O
R                    Reverse input
 `                   Push input to stack seperatly
  ©                  Store your name in register C
   ¸                 Listify
    «                Merge lists (add your name to the list of names)
     {               Sort
      ®              Push your name
       Q             For each element; is it equal to your name?
        s            Swap (n on top)
         ô           Split list of names into n chunks
          O          Sum each element
           ƶ         Lift a, multiplying each element by its index
            20*      Multiply by 20
               O     Sum for the result

Try it online!

\$\endgroup\$
5
2
\$\begingroup\$

APL (Dyalog Unicode), 11 bytes

20×⌈⎕÷⍨⊃⍋⍋⎕

Try it online!

Full program that takes the names and the value of n from stdin.

How it works

20×⌈⎕÷⍨⊃⍋⍋⎕
          ⎕  ⍝ Take first input (names)
        ⍋⍋   ⍝ Rank the names alphabetically; A E C B D → 1 5 3 2 4
       ⊃     ⍝ Extract the first number
   ⌈⎕÷⍨      ⍝ Take second input (n), divide above by n, and ceiling it
20×          ⍝ Multiply 20
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 13 bytes

Iײ⁰⊕÷ΣEη‹ιθζ

Try it online! Link is to verbose version of code. Explanation:

        η       Second input (array of friends)
       E        Map over array
          ι     Current friend
         ‹      Alphabetically precedes
           θ    First input (your name)
      Σ         Take the sum
     ÷          Integer divided by
            ζ   Number of simultaneous interviews
    ⊕           Incremented
 ×              Multiplied by
  ²⁰            Literal `20`
I               Cast to string
                Implicitly print
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 68 bytes

l;f(p,n)char**p;{for(l=0;p[++l]&&strcmp(*p,p[l])>0;);n=20+--l/n*20;}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Java (JDK), 54 bytes

(m,l,q)->l.filter(x->x.compareTo(m)<0).count()/q*20+20

Try it online!

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 10 bytes

ª{¹kI÷>20*

Try it online or verify all test cases.

Explanation:

ª           # Add the first (implicit) input-string to the (implicit) input-list
 {          # Sort the list alphabetically
  ¹k        # Get the 0-based index of the first input in the sorted list
    I÷      # Integer-divide it by the input-integer
      >     # Increase it by 1
       20*  # And multiply it by 20
            # (after which the result is output implicitly)
\$\endgroup\$
1
\$\begingroup\$

Scala, 29 23 bytes

Saved 1 byte thanks to Rahul Verma

y=>_.count(_<y)/_*20+20

Try it online!

Accepts (y)(a, n). y is a String representing your name, a is a List[String] with your competitors' "friends'" names, and n is an Int representing the number of interviewers. The function is pretty straightfoward - it just finds how many friends will go before you (plus 1 because you're going to go too), divides that by n (rounding up), and multiplies by 20 to get the total time.

\$\endgroup\$
3
  • \$\begingroup\$ The output is empty in TIO... (I don't know about Scala, btw) \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 15:46
  • 1
    \$\begingroup\$ @RahulVerma Those are just a bunch of assertions. Here's one with print statements \$\endgroup\$
    – user
    Aug 9, 2020 at 15:48
  • 1
    \$\begingroup\$ -1 byte \$\endgroup\$
    – vrintle
    Aug 9, 2020 at 15:52
0
\$\begingroup\$

Wolfram Language (Mathematica), 35 bytes

20⌈{#}~Union~#2~Position~#/#3⌉&

Try it online! Pure function. Takes the three arguments in order and returns {{x}}, where x is the desired number of minutes.

\$\endgroup\$
0
\$\begingroup\$

MathGolf, 9 bytes

èsl=j/üI*

Inputs in the order and format "myName" numberOfInterviewers "an","Array","Of","Friends".
Assumes the names only contains letters. Will delete and fix it if they can contain digits as well.

Try it online.

Explanation:

è         # Push all inputs as single string array
          #  i.e. "Oggy" 10 "Jack","DeeDee","Marky","Bob"
          #   → ['Oggy','10','Jack','DeeDee','Marky','Bob']
 s        # Sort this array alphabetically
          #  → ['10','Bob','DeeDee','Jack','Marky','Oggy']
  l       # Push the first input as string
          #  → ['10','Bob','DeeDee','Jack','Marky','Oggy'] and 'Oggy'
   =      # Get its 0-based index in the array
          #  → 5
    j     # Push the second input as float
          #  → 5 and 10.0
     /    # Divide the index by this float
          #  → 0.5
      ü   # Ceil it to an integer
          #  → 1
       I* # Multiply it by 20
          #  → 20
          # (after which the entire stack joined together is output implicitly as result)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.