The challenge
The shortest code by character count to output a best-case blackjack hand from the list of number-cards given.
Input is a list of numbers from 1 to 10 (inclusive) separated by space.
Output will be the best blackjack hand formed from that list of cards - the closest available combo to reach 21 by the sum of all card values without surpassing it. Cards can be removed but not added.
If a case where removing two or more cards in favor of one card to accomplish the same result (removing 5 or 4,1 to gain 21) removing the least cards is required.
If the equal amount of cards is to be removed (removing 1,4 or 3,2) the group with the minimum of the minimum will be removed (in the previous example, 1,4 will be removed as min(min(3,2), min(1,4))
belongs to that pair). In the case of duplicate cards, the first encounter should be removed.
Output will be formed as diamond cards, with input order preserved:
__________ __________ | || | | || /\ | | || \/ | | /\ || | | \/ || | | || /\ | | || \/ | |__________||__________| __________ __________ | || | | /\ || /\ /\ | | \/ || \/ \/ | | /\ || | | \/ || | | /\ || /\ /\ | | \/ || \/ \/ | |__________||__________| __________ __________ | || | | /\ /\ || /\ /\ | | \/ \/ || \/ \/ | | /\ || /\ /\ | | \/ || \/ \/ | | /\ /\ || /\ /\ | | \/ \/ || \/ \/ | |__________||__________| __________ __________ | || | | /\ /\ || /\ /\ | | \/ /\ \/ || \/ /\ \/ | | /\ \/ /\ || /\ \/ /\ | | \/ \/ || \/ /\ \/ | | /\ /\ || /\ \/ /\ | | \/ \/ || \/ \/ | |__________||__________| __________ __________ | /\ /\ || /\ /\ | | \/ \/ || \/ /\ \/ | | /\ /\ || /\ \/ /\ | | \/ /\ \/ || \/ \/ | | /\ \/ /\ || /\ /\ | | \/ \/ || \/ /\ \/ | | /\ /\ || /\ \/ /\ | |_\/____\/_||_\/____\/_|
Test cases
Input:
1 5 7 8
Output:
__________ __________ __________ __________
| || || || |
| || /\ /\ || /\ /\ || /\ /\ |
| || \/ \/ || \/ /\ \/ || \/ /\ \/ |
| /\ || /\ || /\ \/ /\ || /\ \/ /\ |
| \/ || \/ || \/ \/ || \/ /\ \/ |
| || /\ /\ || /\ /\ || /\ \/ /\ |
| || \/ \/ || \/ \/ || \/ \/ |
|__________||__________||__________||__________|
Input:
10 3 4 2 6
Output:
__________ __________ __________ __________
| /\ /\ || || || |
| \/ /\ \/ || /\ || /\ || /\ /\ |
| /\ \/ /\ || \/ || \/ || \/ \/ |
| \/ \/ || /\ || || /\ /\ |
| /\ /\ || \/ || || \/ \/ |
| \/ /\ \/ || /\ || /\ || /\ /\ |
| /\ \/ /\ || \/ || \/ || \/ \/ |
|_\/____\/_||__________||__________||__________|
Input
5 10 5 2 3
Output:
__________ __________ __________ __________
| /\ /\ || || || |
| \/ /\ \/ || /\ /\ || /\ || /\ |
| /\ \/ /\ || \/ \/ || \/ || \/ |
| \/ \/ || /\ || || /\ |
| /\ /\ || \/ || || \/ |
| \/ /\ \/ || /\ /\ || /\ || /\ |
| /\ \/ /\ || \/ \/ || \/ || \/ |
|_\/____\/_||__________||__________||__________|
Code count includes input/output (i.e full program).
1 5 7 8
? – Hermy1 10 8
would the answer be 1,10 or 1,10,8? Does 1 represent an ace? – Mannose1 10 8
will be1 10 8
... 19 is closer to 21 than 18 and does not surpass it. – LariosCards with a number 2 to 10 printed on them count as that value; the jack, queen, and king (also known as "face cards") count as 10; and the ace card can be either 1 or 11 at the player's choice.
– Mannose