5 kyu

Weighing on scales with pans (easy)

26 of 31zorl

Description:

Laura and Sarah Kraft are treasure hunter twins. After another successful journey, they obtained several pieces of gold ore and one large figurine covered with mystical writings.

They had with them electronic and mechanical scales. They weighed and found out the exact weight of each piece of gold ore, but the figurine was too large and could not be weighed on an electronic scale.

The mystical inscription on the figurine said that its weight is equal to the holy number N. Then the twins decided to check whether this statement was true using mechanical scales.

Help the twins set the pieces of ore on the scales in such a way that the scales come into balance after you place the figurine on the right pane (assuming that the figurine really weighs N).

Inputs:

  • weights - an array of weights for pieces of gold ore
  • N - the holy number, the weight of the figurine placed on the right pan

The output should be an array describing the pans: [left, right], the left and right are the weight arrays of the pieces of gold ore placed on the respective pan. Obviously, each piece can only be used once. Although not all pieces must be used.

For example, suppose that pieces of gold ore weigh [1, 2, 7]

for N = 3 the output should be [[1, 2],[]]

for N = 5 the output should be [[7],[2]]

If the scale cannot be balanced, an empty array should be returned.

For this (easy) version, the number of ore pieces is no more than 10. If you have done with this kata, try Weighing on scales with pans (advanced) version.

Fundamentals
Algorithms

Similar Kata:

More By Author:

Check out these other kata created by zorl

Stats:

CreatedJun 19, 2022
PublishedJun 19, 2022
Warriors Trained284
Total Skips69
Total Code Submissions211
Total Times Completed31
JavaScript Completions26
Python Completions8
Total Stars6
% of votes with a positive feedback rating100% of 13
Total "Very Satisfied" Votes13
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • zorl Avatar
  • dfhwze Avatar
Ad