6 kyu
Identify Ball Bearings
146 of 175Kacarott
Description:
Failure on the factory floor!! One box of 'deluxe' ball-bearings has been mixed in with all the boxes of 'normal' ball-bearings! We need your help to identify the right box!
Information
What you know about the bearings:
- 'deluxe' ball-bearings weigh exactly
11 grams
- 'normal' ball-bearings weigh exactly
10 grams
- Besides weight, both kinds of ball-bearings are identical
- There are (effectively) infinite bearings in each box
- Each box contains exclusively one type of bearing (either regular, or 'deluxe')
To help you identify the right box, you also have access to a Super Scale™ which will tell you the exact weight of anything you give it. Unfortunately, getting it ready for each measurement takes a long time, so you only have time to use it once!
Task
Write a function which accepts two arguments:
bearings
: A list of the bearing types contained in each 'box'. (length between1
and200
inclusive)
weigh
: a function which accepts any number of arguments, returning the total weight of all. Can only be used once!
Your function should identify and return the single 'deluxe' bearing sample from bearings
.
Example
def identify_bb(bearings, weigh):
a, b, c = bearings
if weigh(a, b) == 20:
# bearings 'a' and 'b' must both be 10, so 'c' must be deluxe
return c
if weigh(a) == 10: # Error: weigh has already been used!
return b
return a
Note: modules sys
and inspect
have been disabled.
Try some other riddle kata:
Riddles
Similar Kata:
Stats:
Created | Oct 21, 2021 |
Published | Oct 21, 2021 |
Warriors Trained | 867 |
Total Skips | 16 |
Total Code Submissions | 1149 |
Total Times Completed | 175 |
Python Completions | 146 |
C# Completions | 31 |
OCaml Completions | 5 |
Haskell Completions | 4 |
Total Stars | 22 |
% of votes with a positive feedback rating | 91% of 60 |
Total "Very Satisfied" Votes | 51 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 17 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |