4 kyu

Prepare the Cocktails

17 of 26bledding

Description:

Laurence is on vacation at the tropics and wants to impress Juliet and her friends by making them the best cocktail he can from the island's bountiful fruits.

Taste and flavour

  • Each ingredient has a unique integer taste representing its sweetness (if positive) or bitterness (if negative).
  • The tastes of the ingredients sum up to the flavour of the cocktail.
  • Cocktails will also have a non-negative integer bittersweetness. Each unit of bittersweetness is given by a unit of sweetness in contrast with a unit of bitterness (i.e. it's the lowest between the total sweetness and the total bitterness of the ingredients).

The same ingredient may be added multiple times to the same cocktail.

Well balanced drinks are made with exactly five ingredients. Use no more and no less for any cocktails you prepare. Repeated ingredients are counted as much as the quantity added.

Example cocktails

          TASTE
  Liquor     -4
  Vodka      -2            FLAVOUR:   2
  Mint        1   ----->   BITTERSW:  6
  Pineapple   3
  Watermelon  4

  Mormodica  -6
  Vodka      -2            FLAVOUR:  -2
  Mint        1   ----->   BITTERSW:  6
  Orange      2
  Pineapple   3

Input and output

Your solution will be called once per cocktail with the following parameters:

  • The ingredients and their tastes as a dictionary of integers.
  • The friend's desired flavour as an integer.
  • The friend's desired bittersweetness as a non-negative integer.

Return an array of the ingredients used to make the cocktail. Order is irrelevant. Any answer respecting the criteria is valid. If it's impossible to make the cocktail you should return an empty array.

Test cases

Example test cases should be enough to confirm your output is correct. The real test cases will consist of the example test cases plus some randomized performance tests. These tests include datasets of size 26^2 and 26^4. The maximum sweetness/bitterness of ingredients is 26^5.

Algorithms
Functional Programming
Performance
Recursion
Set Theory

More By Author:

Check out these other kata created by bledding

Stats:

CreatedFeb 11, 2024
PublishedFeb 16, 2024
Warriors Trained785
Total Skips14
Total Code Submissions957
Total Times Completed26
Python Completions17
JavaScript Completions11
Total Stars43
% of votes with a positive feedback rating92% of 12
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
4 kyu
Ad
Contributors
  • bledding Avatar
  • dfhwze Avatar
  • Mednoob Avatar
Ad