11
二乗差を最大化する
整数値の順列を検討1するがN。たとえば、次の例N = 4: [1, 3, 4, 2] このリストは循環的である1と見なし、そのように、および2隣接として扱われます。そのようなリストについて計算できる1つの量は、隣接する値の差の2乗の合計です。 (1-3)² + (3-4)² + (4-2)² + (2-1)² = 10 あなたの仕事は、正の整数を与えられて、この量を最大にする順列を見つけることNです。N = 4上記の例の場合、最適ではありません(実際、最小限です)。18次の順列(および他のいくつかの順列)の合計平方差を達成できます。 [1, 4, 2, 3] アルゴリズムは(のN)多項式時間で実行する必要があります。特に、すべての順列の差の合計を単純に計算することはできません。 プログラムまたは関数を作成し、STDIN(または最も近い代替)、コマンドライン引数または関数引数を介して入力を取得し、STDOUT(または最も近い代替)、関数の戻り値または関数(out)パラメーターを介して結果を出力できます。 出力は、任意の便利で明確なフラットリストまたは文字列形式にすることができます。0toのN-1代わりに1toの値を持つリストを返すことを選択できますN。 標準のコードゴルフ規則が適用されます。 テストデータ この問題に対する優れた分析ソリューションがあります。たとえば、すべての有効なソリューションN = 10は次のリストと同等です(巡回シフトおよび反転まで)。 [7, 5, 6, 4, 8, 2, 10, 1, 9, 3] 私は(それがパターンを把握する、おそらく十分ですが)それを超えてあまりにも明らかにし、その代わりに任意のより多くの例を与える、あなたは結果が与えられたため、次の総乗違いがあることを確認することができますしたくありませんN。 N Total squared difference 1 0 2 …
19
code-golf
array-manipulation
permutations
restricted-complexity
code-golf
geometry
grid
code-golf
string
sorting
code-golf
simulation
code-golf
string
code-golf
arithmetic
code-golf
sorting
code-golf
string
code-golf
sorting
code-golf
interpreter
code-golf
number
kolmogorov-complexity
natural-language
conversion
code-golf
random
internet
code-golf
board-game
code-golf
number
sequence
code-golf
math
number
code-challenge
image-processing
classification
test-battery
code-golf
ascii-art
code-golf
tips
code-golf
arithmetic
code-golf
tips
code-golf
tips
javascript
code-golf
array-manipulation
code-golf
ascii-art
code-golf
string
binary
code-golf
arithmetic
linear-algebra
matrix
code-golf
sequence
code-golf
math
number
arithmetic
code-golf
primes
code-golf
math
code-golf
array-manipulation
counting
code-golf
arithmetic
code-golf
quine
code-generation
polyglot
code-golf
math
kolmogorov-complexity
trigonometry
code-golf
string
encryption