Skip to main content
Post Reopened by Christiaan Westerbeek, Jonathan Allan, Ørjan Johansen, Giuseppe, JungHwan Min
added 10 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282
  • Given 4, 2 and 5 output 3, 2 cap the highest (cth), ko
  • Given 2, 4 and 5 output 2, 3 cth, ko
  • Given 3, 3 and 5 output 3, 2 or 2, 3 cap any of the highest (cath)
  • Given 4, 2 and 5 output 3, 2 cap the highest (cth), ko
  • Given 2, 4 and 5 output 2, 3 cth, ko
  • Given 3, 3 and 5 output 3, 2 cap any of the highest (cath)
  • Given 4, 2 and 5 output 3, 2 cap the highest (cth), ko
  • Given 2, 4 and 5 output 2, 3 cth, ko
  • Given 3, 3 and 5 output 3, 2 or 2, 3 cap any of the highest (cath)
deleted 54 characters in body
Source Link
  • Given 5, 4, 2 and 10 output 4, 4, 2 cth, ko
  • Given 2, 4, 5 and 10 output 2, 4, 4 cth, ko
  • Given 4, 4, 2 and 10 output 4, 4, 2 ncn, ko
  • Given 4, 2, 4 and 10 output 4, 2, 4 ncn, ko
  • Given 4, 4, 2 and 7 output 3, 2, 2 or 2, 3, 2 cth, cath, ko
  • Given 4, 2, 4 and 7 output 3, 2, 2 or 2, 2, 3 cth, cath, ko
  • Given 4, 4, 2 and 5 output 2, 2, 1 or any permutation (oap)
  • Given 2, 4, 4 and 5 output 1, 2, 2 oap
  • Given 4, 4, 2 and 4 output 1, 2, 1 oap
  • Given 2, 4, 4 and 4 output 1, 1, 2 oap
  • Given 70, 80, 90 and 10 output 3, 3, 4 oap
  • Given 5, 4, 2 and 10 output 4, 4, 2 cth, ko
  • Given 2, 4, 5 and 10 output 2, 4, 4 cth, ko
  • Given 4, 4, 2 and 10 output 4, 4, 2 ncn, ko
  • Given 4, 2, 4 and 10 output 4, 2, 4 ncn, ko
  • Given 4, 4, 2 and 7 output 3, 2, 2 or 2, 3, 2 cth, cath, ko
  • Given 4, 2, 4 and 7 output 3, 2, 2 or 2, 2, 3 cth, cath, ko
  • Given 4, 4, 2 and 5 output 2, 2, 1 or any permutation (oap)
  • Given 2, 4, 4 and 5 output 1, 2, 2 oap
  • Given 4, 4, 2 and 4 output 1, 2, 1 oap
  • Given 2, 4, 4 and 4 output 1, 1, 2 oap
  • Given 5, 4, 2 and 10 output 4, 4, 2 cth, ko
  • Given 2, 4, 5 and 10 output 2, 4, 4 cth, ko
  • Given 4, 4, 2 and 7 output 3, 2, 2 or 2, 3, 2 cth, cath, ko
  • Given 4, 2, 4 and 7 output 3, 2, 2 or 2, 2, 3 cth, cath, ko
  • Given 4, 4, 2 and 5 output 2, 2, 1 or any permutation (oap)
  • Given 2, 4, 4 and 5 output 1, 2, 2 oap
  • Given 4, 4, 2 and 4 output 1, 2, 1 oap
  • Given 2, 4, 4 and 4 output 1, 1, 2 oap
  • Given 70, 80, 90 and 10 output 3, 3, 4 oap
clarified the question which was the reason it was put on hold
Source Link
  • Given 4, 2 and 6 output 4, 2 no capping needed (ncn), keep order (ko)
  • Given 2, 4 and 6 output 2, 4 ncn, ko
  • Given 3, 3 and 6 output 3, 3 ncn
  • Given 3, 3 and 7 output 3, 3 ncn
  • Given 4, 4, 2 and 5 output 2, 2, 1 cth, koor any permutation (oap)
  • Given 2, 4, 4 and 5 output 1, 2, 2 cth, kooap
  • Given 4, 4, 2 and 4 output 1, 2, 1 or 2, 1, 1 cth, cath, kooap
  • Given 2, 4, 4 and 4 output 1, 1, 2 or 1, 2, 1 cth, cath, kooap
  • Both input and output are all about positive integers (>0)
  • The number of values in the input and output list are equal.
  • The sum of the output values is exactly equal to m or less than m only if the sum of the input values was already lower.
  • If the sum of the values in the input list is already lower then or equal to m, no capping is needed. (ncn)
  • Cap the highest values first (cth)
  • When multiple values are the highest value and equally high, it doesn't matter which you cap. (cath)
  • The capped values in the output list have to be in the same order as their original values in the input list. (ko)
  • When at some point (thinking iteratively) all values are equally high, it stops being important which you cap.
  • If there's no solution output an error or a falsy value.

The shortest valid answer - measured in bytes - wins.

Apart form the rules, I'm interested to see a program that keeps a value intact as long as possible. Consider the input values a plant each with the heights 10,2,10 and the maximum m=5, it would be a waste to cap the baby plant in the middle.

  • Given 4, 2 and 6 output 4, 2 no capping needed (ncn), keep order (ko)
  • Given 2, 4 and 6 output 2, 4 ncn, ko
  • Given 3, 3 and 6 output 3, 3 ncn
  • Given 4, 4, 2 and 5 output 2, 2, 1 cth, ko
  • Given 2, 4, 4 and 5 output 1, 2, 2 cth, ko
  • Given 4, 4, 2 and 4 output 1, 2, 1 or 2, 1, 1 cth, cath, ko
  • Given 2, 4, 4 and 4 output 1, 1, 2 or 1, 2, 1 cth, cath, ko
  • Both input and output are all about positive integers (>0)
  • The number of values in the input and output list are equal.
  • The sum of the output values is exactly equal to m or less than m only if the sum of the input values was already lower.
  • If the sum of the values in the input list is already lower then or equal to m, no capping is needed. (ncn)
  • Cap the highest values first (cth)
  • When multiple values are the highest value and equally high, it doesn't matter which you cap. (cath)
  • The capped values in the output list have to be in the same order as their original values in the input list. (ko)
  • If there's no solution output an error or a falsy value.

The shortest valid answer - measured in bytes - wins.

  • Given 4, 2 and 6 output 4, 2 no capping needed (ncn), keep order (ko)
  • Given 2, 4 and 6 output 2, 4 ncn, ko
  • Given 3, 3 and 6 output 3, 3 ncn
  • Given 3, 3 and 7 output 3, 3 ncn
  • Given 4, 4, 2 and 5 output 2, 2, 1 or any permutation (oap)
  • Given 2, 4, 4 and 5 output 1, 2, 2 oap
  • Given 4, 4, 2 and 4 output 1, 2, 1 oap
  • Given 2, 4, 4 and 4 output 1, 1, 2 oap
  • Both input and output are all about positive integers (>0)
  • The number of values in the input and output list are equal.
  • The sum of the output values is exactly equal to m or less than m only if the sum of the input values was already lower.
  • If the sum of the values in the input list is already lower then or equal to m, no capping is needed. (ncn)
  • Cap the highest values first (cth)
  • When multiple values are the highest value and equally high, it doesn't matter which you cap. (cath)
  • The capped values in the output list have to be in the same order as their original values in the input list. (ko)
  • When at some point (thinking iteratively) all values are equally high, it stops being important which you cap.
  • If there's no solution output an error or a falsy value.

The shortest valid answer - measured in bytes - wins.

Apart form the rules, I'm interested to see a program that keeps a value intact as long as possible. Consider the input values a plant each with the heights 10,2,10 and the maximum m=5, it would be a waste to cap the baby plant in the middle.

Post Closed as "Needs details or clarity" by Laikoni, Ørjan Johansen, NoOneIsHere, GamrCorps, xnor
added 1 character in body
Source Link
Loading
added 72 characters in body
Source Link
Loading
removed the no recursion requirement
Source Link
Loading
added 52 characters in body
Source Link
Loading
More cases to clarify the rules
Source Link
Loading
Source Link
Loading