Locked. This question and its answers are locked,因为该问题是题外话,但具有历史意义。它目前不接受新的答案或互动。








挑战

字符计数最短的代码,用于从给定的数字卡列表中输出最佳情况的二十一点牌。

输入是一个由1到10(含10)的数字列表,中间用空格隔开。

输出将是由该张牌列表构成的最佳二十一点牌-最接近的可用组合,通过所有牌值的总和达到21,而不会超过该值。卡可以删除,但不能添加。

如果需要移除两张或更多张卡,而只一张卡来完成相同的结果(移除5或4,1以获得21),则需要移除最少的卡。
如果要删除相等数量的卡(删除1,4或3,2),则删除具有最小数量的最小卡的组(在上一示例中,由于min(min(3,2), min(1,4))属于该对,因此将删除1,4) 。如果有重复的卡,第一次相遇应该被删除。

输出将形成为菱形卡,并保留输入顺序:
 __________  __________
|          ||          |
|          || /\       |
|          || \/       |
|    /\    ||          |
|    \/    ||          |
|          ||       /\ |
|          ||       \/ |
|__________||__________|
 __________  __________
|          ||          |
| /\       || /\    /\ |
| \/       || \/    \/ |
|    /\    ||          |
|    \/    ||          |
|       /\ || /\    /\ |
|       \/ || \/    \/ |
|__________||__________|
 __________  __________
|          ||          |
| /\    /\ || /\    /\ |
| \/    \/ || \/    \/ |
|    /\    || /\    /\ |
|    \/    || \/    \/ |
| /\    /\ || /\    /\ |
| \/    \/ || \/    \/ |
|__________||__________|
 __________  __________
|          ||          |
| /\    /\ || /\    /\ |
| \/ /\ \/ || \/ /\ \/ |
| /\ \/ /\ || /\ \/ /\ |
| \/    \/ || \/ /\ \/ |
| /\    /\ || /\ \/ /\ |
| \/    \/ || \/    \/ |
|__________||__________|
 __________  __________
| /\    /\ || /\    /\ |
| \/    \/ || \/ /\ \/ |
| /\    /\ || /\ \/ /\ |
| \/ /\ \/ || \/    \/ |
| /\ \/ /\ || /\    /\ |
| \/    \/ || \/ /\ \/ |
| /\    /\ || /\ \/ /\ |
|_\/____\/_||_\/____\/_|

Test cases

Input:
    1 5 7 8
Output:
     __________  __________  __________  __________
    |          ||          ||          ||          |
    |          || /\    /\ || /\    /\ || /\    /\ |
    |          || \/    \/ || \/ /\ \/ || \/ /\ \/ |
    |    /\    ||    /\    || /\ \/ /\ || /\ \/ /\ |
    |    \/    ||    \/    || \/    \/ || \/ /\ \/ |
    |          || /\    /\ || /\    /\ || /\ \/ /\ |
    |          || \/    \/ || \/    \/ || \/    \/ |
    |__________||__________||__________||__________|
Input:
    10 3 4 2 6
Output:
     __________  __________  __________  __________
    | /\    /\ ||          ||          ||          |
    | \/ /\ \/ || /\       || /\       || /\    /\ |
    | /\ \/ /\ || \/       || \/       || \/    \/ |
    | \/    \/ ||    /\    ||          || /\    /\ |
    | /\    /\ ||    \/    ||          || \/    \/ |
    | \/ /\ \/ ||       /\ ||       /\ || /\    /\ |
    | /\ \/ /\ ||       \/ ||       \/ || \/    \/ |
    |_\/____\/_||__________||__________||__________|
Input
    5 10 5 2 3
Output:
     __________  __________  __________  __________
    | /\    /\ ||          ||          ||          |
    | \/ /\ \/ || /\    /\ || /\       || /\       |
    | /\ \/ /\ || \/    \/ || \/       || \/       |
    | \/    \/ ||    /\    ||          ||    /\    |
    | /\    /\ ||    \/    ||          ||    \/    |
    | \/ /\ \/ || /\    /\ ||       /\ ||       /\ |
    | /\ \/ /\ || \/    \/ ||       \/ ||       \/ |
    |_\/____\/_||__________||__________||__________|

代码计数包括输入/​​输出(即完整程序)。

最佳答案

Golfscript-228个字符

' ':x/{~}%:h;9,{:r;h,2\?,{:m;h,,{2\?m&},{h\=}%}%1>{:j[{+}*.22<\j,j$j]}$)\;{:c;[x]3,{4\?'  \//\__'2/[11'?'*8'@'*'bb@BBbbbbbQY@AAQQQYYbfH@H@HbffYQD@D@DQQYfb@``bbbbfQY@PPQQQQQbf'8'?'*]']]'+10r*c+=@/3&=}%[x]++' _'1/7r&!=*}%'|':x;n}%
$ echo 10 9 8 7 6 5 | ../golfscript.rb black.gs
 __________  __________  __________
|          ||          ||          |
| /\    /\ || /\    /\ || /\    /\ |
| \/ /\ \/ || \/ /\ \/ || \/    \/ |
| /\ \/ /\ || /\ \/ /\ || /\    /\ |
| \/ /\ \/ || \/    \/ || \/    \/ |
| /\ \/ /\ || /\    /\ || /\    /\ |
| \/    \/ || \/    \/ || \/    \/ |
|__________||__________||__________|

231 Characters

' ':x/{~}%:h,2\?,{:m;h,,{2\?m&},{h\=}%}%1>{:j[{+}*.22<\j,j$j]}$-1=:h;9,{:r;h{:c;[x]3,{4\?'  \//\__'2/11'?'*8'@'*'bb@BBbbbbbQY@AAQQQYYbfH@H@HbffYQD@D@DQQYfb@``bbbbfQY@PPQQQQQbf'8'?'*']]'++++10r*c+=@/3&=}%[x]++' _'1/7r&!=*}%'|':x;n}%

工作原理
# parse input into a list
' ':x/{~}%:h
# create the powerset
 ,2\?,{:m;h,,{2\?m&},
# map the powerset onto the cards
{h\=}%}%
# trim the empty set from the powerset
1>
# sort the hands. most preferred hand will be last
{:j[{+}*.22<\j,j$j]}$
# take the preferred hand from the end of the list
-1=:h;
# for r in 0..8
9,{:r
...more to follow

关于language-agnostic - Code Golf:钻石二十一点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1843182/

10-12 19:50