gpt4 book ai didi

algorithm - Code Golf : Countdown Number Game

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:13:54 25 4
gpt4 key购买 nike

<分区>

挑战

这是受著名的英国电视游戏节目 Countdown 启发的任务。即使对游戏一无所知,挑战也应该很清楚,但请随时要求澄清。

如果您想观看该游戏的实际片段,请查看 this YouTube clip .它以 1997 年精彩的已故理查德·怀特利为主角。

You are given 6 numbers, chosen at random from the set {1, 2, 3, 4, 5, 6, 8, 9, 10, 25, 50, 75, 100}, and a random target number between 100 and 999. The aim is to use the six given numbers and the four common arithmetic operations (addition, subtraction, multiplication, division; all over the rational numbers) to generate the target - or as close as possible either side. Each number may only be used once at most, while each arithmetic operator may be used any number of times (including zero.) Note that it does not matter how many numbers are used.

Write a function that takes the target number and set of 6 numbers (can be represented as list/collection/array/sequence) and returns the solution in any standard numerical notation (e.g. infix, prefix, postfix). The function must always return the closest-possible result to the target, and must run in at most 1 minute on a standard PC. Note that in the case where more than one solution exists, any single solution is sufficient.

例子:

  • {50, 100, 4, 2, 2, 4},目标 203
    例如100 * 2 + 2 + (4/4) (精确)
    例如(100 + 50) * 4 * 2/(4 + 2) (精确)

  • {25, 4, 9, 2, 3, 10},目标 465
    例如(25 + 10 - 4) * (9 * 2 - 3) (精确)

  • {9, 8, 10, 5, 9, 7},目标 241
    例如((10 + 9) * 9 * 7) + 8)/5 (精确)

  • {3, 7, 6, 2, 1, 7},目标 824
    例如((7 * 3) - 1) * 6 - 2) * 7 (= 826; 减去 2)

规则

除了问题陈述中提到的,没有进一步的限制。您可以用任何标准语言编写函数(不需要标准 I/O)。一如既往的目标是用最少的代码字符数解决任务。

话虽如此,我可能不会简单地接受代码最短的答案。我还将关注代码的优雅性和算法的时间复杂度!

我的解决方案

当我找到空闲时间时,我正在尝试 F# 解决方案 - 有空时会在此处发布!


格式

为了便于比较,请按以下格式发布所有答案:

Language

Number of characters: ???

Fully obfuscated function:

(code here)

Clear (ideally commented) function:

(code here)

Any notes on the algorithm/clever shortcuts it takes.


25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com