32

# 平衡技术

1至9之间的3个整数。您可以输入整数，但是很方便，例如，元组，3个逗号分隔的值等。但是，您的程序必须能够处理以任何顺序输入的数字（即，假定值将不排序）。可以输入重复的数字（例如2,3,2）。

4,7,2

________7___42_______
^

7 * 2 = 4 * 2 + 2 * 3

_______24___7________
^

2 * 3 + 4 * 2 = 7 * 2

3,1,5

_____5________1__3___
^

5 * 5 = 1 * 4 + 3 * 7

____5________1_____3_
^

5 * 6 = 1 * 3 + 3 * 9

____5___________1_3__
^

5 * 6 = 1 * 6 + 3 * 8

• 这是因此以字节为单位的最短程序获胜
• 程序可以是独立程序，也可以是接受数字作为输入并返回字符串的函数。
• 在最后一行尾随换行符和空格是可选的
• 如果您不知道跷跷板是什么，它也被称为跷跷板或跷跷板。

samgak

11

xnor

2

13

# CJam，40 39 38字节

q~21Ue]e!{21,Af-Aest.*:+!}=0'_erNAS*'^

### 怎么运行的

q~                                     e# Read and evaluate the input.
21Ue]                                e# Append zeroes to achieve a length of 21.
e!                              e# Push all unique permutations.
{               }=            e# Find the first permutation such that:
21,                          e#  Push [0 ... 20].
Af-                       e#  Subtract 10 from each.
Aest                   e#  Replace the element at index 10 with the
e#  current time (ms since epoch) to push
e#  [-10 ... -1 <big number> 1 ... 10].
.*                 e#  Multiply each number of the permutation
e#  by the corresponding distance.
e#  The timestamp makes sure that this sum
e#  is non-zero for a non-zero element in
e#  the middle of the permutation.
!              e#  Push the logical NOT of the sum.
0'_er       e# Replace zeroes with underscores.
NAS*'^ e# Push a linefeed, ten spaces and a caret.

5

# CJam，46 44字节

'_21*q~K,Am3m*{___&=*Afm1\$.*:+!}=.{\t}NAS*'^

## 说明

'_21*   e# Push a string of 21 underscores.
q~      e# Read and eval input.
K,      e# Push the array [0 1 .. 19 20]
Am      e# Remove the 10. This is now an array of all valid positions on the seesaw.
3m*     e# Get all 3-tuples of valid positions.
{       e# Select the first tuple for which the following block yields a truthy result.
___   e# Make three copies of the tuple.
&=    e# Intersect the last two copies and check for equality with the first one.
e# This yields 1 if all positions are distinct, and 0 otherwise.
*     e# Repeat the original tuple that many times. That is, if the positions are
e# distinct, leave the tuple unchanged. Otherwise, replace it with an empty array.
Afm   e# Subtract 10 from each position to get its weight.
1\$    e# Copy the input digits.
.*    e# Take the pairwise product of weights and digits. If the weights are empty
e# (because they were not unique), this will just yield a list of the digits.
:+    e# Sum the weighted digits. If the weights were not unique, this will just sum
e# the digits and will always be positive.
!     e# Logical NOT - give 1 if the sum was 0, or 0 otherwise.
}=
.{\t}   e# For each pair of digit and position, replace that position in the underscore
e# string with the corresponding digit.
N       e# Push a newline.
AS*     e# Push ten spaces.
'^      e# Push a caret.

5

# Java中，519个414 321字节

static int f(int a,int b,int c){int i,j,k;for(i=-10;i<=10;i++)for(j=i+1;j<=10;j++)for(k=j+1;k<=10;k++){if(a*i+b*j+c*k==0&&i!=0&&j!=0&&k!=0){for(int q=0;q<21;q++){if(q==10+i)p(a);else if(q==10+j)p(b);else if(q==10+k)p(c);else p('_');}p("\n          ^\n");return 0;}}return 0;}static void p(Object a){System.out.print(a);}}

1

J阿特金

1

J Atkin

5

## Pyth， 675853 49个字节

V.c-KrT-011Z3FY.pQIqs*VNYZjkm?}dN@YxNd\_K+*dT\^.q

V.c-KrT-011Z3FY.pQIqs*VNYZjkm?}dN@YxNd\_K+*dT\^.q
Implicit: Q = eval(input())
rT-011                                            Create range from 10 to -10
K                                                  Store in K
-       Z                                           Drop 0 from the above
V.c         3                                          For N in (combinations of the above of size 3)
FY.pQ                                     For Y in (permutations of input)
*VNY                              Multiply each element in N by the corresponding element in Y
s                                  Take the sum
Iq     Z                             If it's equal to zero:
m           K              For d in K (K = [10, ..., -10])
?}dN                      Is d in N?
@YxNd                 If so, get corresponding value from Y
\_               Otherwise, get '_'
jk                           Join the resulting array into a string (implicit print)
+*dT\^        Join 10 spaces and '^', implicit print
.q      Break all loops and exit

[1,1,1] ->
1__________1_______1_
^

[2,9,5] ->
2____5_________9_____
^

[9,8,5] ->
5____8______________9
^

4

## C- 237228字节

i,j,k;f(a,b,c){char o[]="_____________________\n          ^";for(i=-10;i<9;i+=i+1?1:2){for(j=i+1;j<11;j+=j+1?1:2){for(k=j+1;k<11;k+=k+1?1:2){if((a*i+b*j+c*k)==0){o[i+10]=a+48;o[j+10]=b+48;o[k+10]=c+48;printf("%s",o);return;}}}}}

f(4,7,2):
4_____________7_2____
^

f(3,1,5)
3____1___________5___
^

3

## Python 2.7 235226 219字节

def s(n,p=__import__("itertools").permutations):
l=["_"]*21
for p,q in[[(a,x+10),(b,y+10),(c,10-z)]for a,b,c in p(n,3)for x,y,z in p(range(1,11),3)if x!=y and a*x+b*y==c*z][0]:l[q]=`p`
return`l`[2::5]+"\n"+" "*10+"^"

(1, 1, 1)
_______1___11________
^
(1, 2, 1)
_____1_____12________
^
(3, 1, 5)
________5__3_____1___
^
(4, 7, 2)
_2_________47________
^

"".join(l) -> 'l'[2::5]是短一个字节（用引号引起来的引号）。

@samgak哎呀。不好，以为我没看错问题。还有2个字节：(
Kamehameha 2015年

@ Vioz-很棒的提示。不知道repr。:)
Kamehameha 2015年

3

# PHP，278字节

\$p=explode(',',\$argv[\$i=1]);for(;\$i<=10;\$i++)for(\$j=1;\$j<=10;\$j++)
for(\$k=1;\$k<=10;\$k++)if(\$j-\$k)for(\$l=0;\$l<3;\$l++){\$q=array_shift(\$p);
if(\$i*\$q==\$j*\$p[0]+\$k*\$p[1]){\$o=str_repeat('_',21);\$o[10-\$i]=\$q;\$o[10+\$j]=\$p[0];
\$o[10+\$k]=\$p[1];echo(\$o."\n          ^\n");}array_push(\$p,\$q);}

\$ php seesaw.php 9,2,1
_________9_2_____1___
^
_________9__2__1_____
^
_________9_1__2______
^
________9_____2_____1
^
________9______2__1__
^
________9_____1__2___
^
________9___1_____2__
^
_______9_________1__2
^
____2______9_1_______
^
___2_______9___1_____
^
__2________9_____1___
^
_2_________9_______1_
^

3

# 朱莉娅，154个字节

f(a,b,c)=(x=replace(join(first(filter(p->p⋅[-10:-1,1:10]==0,permutations([a,b,c,zeros(Int,17)])))),"0","_");print(x[1:10]*"_"*x[11:20]*"\n"*" "^10*"^"))

function f(a,b,c)
# Create a 20-element array of the input with 17 zeros
z = [a,b,c,zeros(Int,17)]

# Get the set of all permutations of z such that the dot product
# of the permutation with the distances is 0
d = filter(p -> p  [-10:-1,1:10] == 0, permutations(z))

# Join the first element of d into a string and replace all of
# the zeros with underscores
x = replace(join(first(d)), "0", "_")

# Print the output
print(x[1:10] * "_" * x[11:20] * "\n" * " "^10 * "^")
end

2

# C，252（214）个字节

e=48;main(_,v,x,y,z,a,b,c)char**v;{char s[]="_____________________\n          ^";x=*v[1]-e;y=*v[2]-e;z=*v[3]-e;for(a=-1;a+11;--a)for(b=-10;b-11;++b)_=a*x+b*y,!b|b==a|_%z?0:(c=-_/z,c&c<11&c>-11?s[a+10]=x+e,s[b+10]=y+e,s[c+10]=z+e,puts(s),exit(0):0);}

a,b,c;f(x,y,z){char s[]="_____________________\n          ^";for(a=-1;a+11;--a)for(b=-10;b-11;++b)!b|b==a|(a*x+b*y)%z?0:(c=-(a*x+b*y)/z,c&&c<11&&c>-11?s[a+10]=x+48,s[b+10]=y+48,s[c+10]=z+48,puts(s),b=10,a=-b:0);}