# 创建不同的总和

10

## 细节

• 您应该至少能够处理该范围`-32768 .. 32767`（包括该范围）的输入。
• 如果您的数据类型不能处理任意整数，那很好，但是从理论上讲，您的算法应适用于任意大小数。

## 例子

``````1 => 6 -5
2 => -2 4
15 => 20 -5

Incorrect, as `-5` is used in two outputs.
``````

``````-5 => -15 10
0 => 0 0
1 => 5 6
2 => -5 7

Incorrect, as `5 + 6` isn't `1`.
``````

``````-1 => -1 0
0 => 6 -6
2 => 1 1

Can be correct if other outputs doesn't collide.
``````

FUZxxl

@FUZxxl我的错，那是我的意图。固定。
randomra 2015年

mathmandan

9

# Pyth，8个字节

``````_J^Q3+QJ
``````

``````Q=input()
J=Q**3
print -J
print Q+J``````

``````-5 (125, -130)
-4 (64, -68)
-3 (27, -30)
-2 (8, -10)
-1 (1, -2)
0 (0, 0)
1 (-1, 2)
2 (-8, 10)
3 (-27, 30)
4 (-64, 68)
5 (-125, 130)
``````

`,`一开始不需要，似乎允许两行。
Maltysen

@Maltysen我尝试将其删除，但仅打印第二个数字。也许`J`作业抑制了打印？
xnor

Maltysen

`-`在pyth中，它不是一元否定运算符`_`，因此它`_J^Q3+QJ`按预期工作。

@Maltysen实际上，那行得通，我只需要`J`不要在外面。感谢您为此给我打招呼。
xnor

8

# 雪人0.1.0，101个字符

``````}vg0aa@@*45,eQ.:?}0AaG0`NdE`;:?}1;bI%10sB%nM2np`*`%.*#NaBna!*+#@~%@0nG\]:.;:;bI~0-NdEnMtSsP" "sP.tSsP
``````

``````}vg0aa          // get input, take the first char
@@*45,eQ.       // check if it's a 45 (ASCII for -) (we also discard the 0 here)
// this is an if-else
:               // (if)
?}0AaG        // remove first char of input (the negative sign)
0`NdE`        // store a -1 in variable e, set active vars to beg
;
:               // (else)
?}1           // store a 1 in variable e, set active vars to beg
;bI             // active variables are now guaranteed to be beg
%10sB           // parse input as number (from-base with base 10)
%nM             // multiply by either 1 or -1, as stored in var e earlier
2np`*`          // raise to the power of 2 (and discard the 2)
%.              // now we have the original number in b, its square in d, and
//   active vars are bdg
*#NaBna!*+#     // add abs(input number) to the square (without modifying the
//   input variable, by juggling around permavars)
@~%@0nG\]       // active vars are now abcfh, and we have (0>n) in c (where n is
//   the input number)
:.;:;bI         // if n is negative, swap d (n^2) and g (n^2+n)
~0-NdEnM        // multiply d by -1 (d is n^2 if n is positive, n^2+n otherwise)
tSsP            // print d
" "sP           // print a space
.tSsP           // print g
``````

1

1

6

# Pyth，15个 11字节

4个字节感谢@Jakube

``````*RQ,hJ.aQ_J
``````

``````0  -> 0, 0
1  -> 2, -1
-1 -> -2, 1
2  -> 6, -4
-2 -> -6, 4
``````

5

# APL，15个字节

``````{(-⍵*3)(⍵+⍵*3)}
``````

2

# Pyth- 11 10个字节

``````*CGQ_*tCGQ
``````

xnor

@xnor添加到提示列表。

2

# O，17 15 9字节

`Q3 ^ .Q + p_p`

`[i＃.Z3 ^ * \ Z3 ^）_ *] o`

1

kirbyfan64sos 2015年

@ kirbyfan64sos虽然不及Pyth小，但在某些情况下可以击败CJam和GolfScript。它非常强大，可以击败与数组有关的任何事情。

1

# Python 3、29 27

## 编辑：不符合第二个“详细信息”项目符号中的要求

``````lambda n:[99999*n,-99998*n]
``````

``````(lambda n:[99999*n,-99998*n])(arg)
``````

*感谢@ vioz-提出建议。

``````>>> (lambda n:[99999*n,-99998*n])(1)
[99999, -99998]
>>> (lambda n:[99999*n,-99998*n])(2)
[199998, -199996]
>>> (lambda n:[99999*n,-99998*n])(0)
[0, 0]
>>> (lambda n:[99999*n,-99998*n])(-1)
[-99999, 99998]
>>> (lambda n:[99999*n,-99998*n])(-2)
[-199998, 199996]
>>> (lambda n:[99999*n,-99998*n])(65536)
[6553534464, -6553468928]
``````

1

1
“ ...您的算法在理论上应该适用于任意大小的数字。” 显然`(lambda n:[99999*n,-99998*n])(99999)``(lambda n:[99999*n,-99998*n])(-99998)`它将在理论上和实践上发生冲突。
mathmandan

@mathmandan您说得对，我将编辑我的帖子以明确表明它不符合要求。我会尝试编写和测试新代码，但是我在远离计算机的移动设备上使用。
monopole 2015年

0

``````f x=(-x^3,x^3+x)