8 kyu

Closest elevator

7,774 of 16,648wildhamster26

Description:

Given 2 elevators (named "left" and "right") in a building with 3 floors (numbered 0 to 2), write a function accepting 3 arguments (in order):

  • left - The current floor of the left elevator
  • right - The current floor of the right elevator
  • call - The floor that called an elevator

It should return the name of the elevator closest to the called floor ("left"/"right").

In the case where both elevators are equally distant from the called floor, choose the elevator to the right.

You can assume that the inputs will always be valid integers between 0-2.

Examples:

left right call   result
  0    1     0    "left"
  0    1     1    "right"
  0    1     2    "right"
  0    0     0    "right"
  0    2     1    "right"
Algorithms

More By Author:

Check out these other kata created by wildhamster26

Stats:

CreatedJan 10, 2019
PublishedJan 16, 2019
Warriors Trained24872
Total Skips389
Total Code Submissions64620
Total Times Completed16648
JavaScript Completions7774
Python Completions6250
C Completions839
Kotlin Completions938
PureScript Completions32
Ruby Completions466
PHP Completions605
Racket Completions40
Java Completions243
NASM Completions7
Total Stars235
% of votes with a positive feedback rating93% of 2401
Total "Very Satisfied" Votes2084
Total "Somewhat Satisfied" Votes280
Total "Not Satisfied" Votes36
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • wildhamster26 Avatar
  • donaldsebleung Avatar
  • JohanWiltink Avatar
  • Madjosz Avatar
  • mitron6 Avatar
  • rowcased Avatar
  • kdmatrosov Avatar
  • mregazzi Avatar
  • FArekkusu Avatar
  • qkleinfelter Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • user8436785 Avatar
  • akar-0 Avatar
Ad