All Expressions

Submit

Your name:
File:
Open code-statistics:

Language is selected by the extension of the file. See the list of supported languages to know the extension of your language.

Problem

Given a sequence of integers, generate all expressions that can be
made from the integers, addition (+), subtraction (-), multiplication
(*), and parentheses, without changing the order of integers.
Calculate the expressions and print the values in ascending order,
removing duplicates.

For example, if the sequence is "1, 9, 13", then possible expressions are:
(1 + (9 + 13))
(1 - (9 + 13))
(1 * (9 + 13))
(1 + (9 - 13))
(1 - (9 - 13))
(1 * (9 - 13))
(1 + (9 * 13))
(1 - (9 * 13))
(1 * (9 * 13))
((1 + 9) + 13)
((1 + 9) - 13)
((1 + 9) * 13)
((1 - 9) + 13)
((1 - 9) - 13)
((1 - 9) * 13)
((1 * 9) + 13)
((1 * 9) - 13)
((1 * 9) * 13)
plus those with redundant parentheses. And the output should be:
-116
-104
-21
-4
-3
5
22
23
117
118
130

Options

exec is denied

no deadline, the server will not save your submission

Sample input:_

1 9 13

Sample output:

-116
-104
-21
-4
-3
5
22
23
117
118
130

Sample input:_

101 3 19 17

Sample output:

-32320
-27472
-3333
-1633
-1599
-868
-273
-225
-219
-171
-20
-7
27
61
62
68
95
96
100
101
102
106
107
134
140
141
175
196
208
209
267
301
305
339
373
421
427
475
505
606
626
748
1070
1343
1445
1845
1879
1959
1989
1993
2091
2205
2239
2686
3528
3744
3939
4040
4828
5474
5740
5774
7474
10908
31654
32926
33592
37774
97869

Sample input:_

3 3 3 1 1 1

Sample output:

-27
-24
-21
-18
-17
-16
-15
-14
-13
-12
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42
44
45
46
48
51
52
53
54
55
56
57
60
63
72
81

Ranking

Ruby _

RankUserSizeTimeDateStatistics
1murky-satyr1270.43382009/10/30 21:20:400B / 59B / 57B
2fsystem1510.35832007/11/26 22:49:190B / ?B / ?B
3shinh2071.22022007/02/19 08:27:530B / ?B / ?B
4flagitious2070.79852007/12/17 02:58:200B / 94B / 81B

Perl _

RankUserSizeTimeDateStatistics
1tybalt89990.63482010/08/08 09:14:430B / ?B / ?B
2ySas1310.23152007/02/28 18:44:430B / 54B / 74B

Python _

RankUserSizeTimeDateStatistics
1hallvabo1540.12702015/09/20 04:13:090B / 88B / 60B
2mitchs1540.15102015/09/20 04:18:570B / 93B / 47B
3mskzzzz1740.36332007/06/16 01:27:540B / 107B / 47B
4rolf1750.40062013/01/04 03:57:110B / 104B / 52B
5recursive1770.12472010/03/31 03:03:330B / 101B / 60B
6SeeNoEvil2120.83652007/03/25 09:24:300B / 109B / 79B
7zeek21670.82852007/03/25 01:38:500B / 1045B / 365B

Python3 _

RankUserSizeTimeDateStatistics
1mitchs1520.25422015/09/20 04:20:150B / 94B / 43B

PHP _

RankUserSizeTimeDateStatistics
1o-cn1801.10432010/02/03 04:14:08105B / 44B / 30B
2mskzzzz2690.57092007/06/16 01:50:400B / 151B / 113B
3tanakh3780.82042007/02/15 08:16:040B / 173B / 200B

Scheme _

RankUserSizeTimeDateStatistics
1ma2321.84202007/03/05 19:06:280B / ?B / ?B
2blue3010.62112007/02/20 00:57:030B / 168B / 106B
3tanakh3041.26892007/02/15 17:45:440B / 181B / 105B

Common LISP _

RankUserSizeTimeDateStatistics
1kozima2141.05852007/05/23 09:36:210B / 101B / 94B

Arc _

RankUserSizeTimeDateStatistics
1murky-satyr1535.30512009/12/02 08:54:580B / 66B / 65B

JavaScript _

RankUserSizeTimeDateStatistics
1FizzyTea1840.67872016/08/02 05:44:370B / 88B / 94B
2nn2120.45852009/12/26 15:36:050B / 117B / 83B
3murky-satyr2410.79492008/07/03 05:47:440B / 130B / 101B
4xulapp2610.24562010/03/27 15:25:170B / 139B / 115B
5mskzzzz3090.18732007/06/20 03:44:260B / 167B / 131B

Smalltalk _

RankUserSizeTimeDateStatistics
1murky-satyr2391.29042008/07/16 03:45:210B / 141B / 82B

Prolog _

RankUserSizeTimeDateStatistics
1mskzzzz1790.43422007/05/28 22:25:580B / 105B / 63B

Erlang _

RankUserSizeTimeDateStatistics
151b2850.96702007/10/11 04:29:160B / 114B / 164B
2mskzzzz5322.20892007/06/02 18:38:090B / 281B / 237B

J _

RankUserSizeTimeDateStatistics
1I., S.1650.57992010/12/17 19:56:270B / 38B / 120B

C _

RankUserSizeTimeDateStatistics
1hinoe2650.09452007/05/05 05:29:345B / 111B / 145B
251b3310.08862007/09/23 01:08:140B / 152B / 178B

D _

RankUserSizeTimeDateStatistics
151b2180.06132008/03/28 15:24:090B / 129B / 85B

OCaml _

RankUserSizeTimeDateStatistics
1ksk2821.16602009/07/21 00:45:480B / 143B / 124B

Haskell _

RankUserSizeTimeDateStatistics
1henkma1330.06012011/09/03 10:01:370B / 79B / 43B
2rst761340.03372010/05/07 22:26:010B / 89B / 35B
3tanakh1360.51682007/02/15 17:05:210B / 79B / 46B
4_1360.22762007/02/18 00:53:560B / 79B / 46B
5blue1420.08762007/02/15 18:54:280B / ?B / ?B
6aljee1440.51972007/02/13 18:14:58?B / ?B / ?B

AWK _

RankUserSizeTimeDateStatistics
1nn3590.47622008/07/26 21:01:370B / 170B / 178B

Bash _

RankUserSizeTimeDateStatistics
1yamaya1621.09882010/09/16 23:04:440B / 62B / 83B

Postscript _

RankUserSizeTimeDateStatistics
1ySas1111.56232007/07/09 21:05:0447B / 40B / 23B
2yshl(bin)1681.25472007/07/28 07:15:4257B / 62B / 44B
3yshl2811.27562007/07/28 07:15:330B / 198B / 38B

GolfScript _

RankUserSizeTimeDateStatistics
1irori701.19402008/01/03 02:23:370B / 10B / 60B

goruby _

RankUserSizeTimeDateStatistics
1murky-satyr1030.82592009/10/30 21:27:220B / 43B / 54B

Groovy _

RankUserSizeTimeDateStatistics
1nn1506.97192010/08/22 22:11:550B / 82B / 64B
2murky-satyr1528.13532010/08/22 21:16:570B / 77B / 68B

Language Ranking_

RankLangUserSizeScore
1GolfScriptirori7010000
2Perltybalt89997070
3gorubymurky-satyr1036796
4PostscriptySas1116306
5Rubymurky-satyr1275511
6Haskellhenkma1335263
7Groovynn1504666
8Python3mitchs1524605
9Arcmurky-satyr1534575
10Pythonhallvabo1544545
11Bashyamaya1624320
12JI., S.1654242
13Prologmskzzzz1793910
14PHPo-cn1803888
15JavaScriptFizzyTea1843804
16Common LISPkozima2143271
17D51b2183211
18Schemema2323017
19Smalltalkmurky-satyr2392928
20Chinoe2652641
21OCamlksk2822482
22Erlang51b2852456
23AWKnn3591949

Referer

Note that, they may contain spoilers.

return top