# 拥抱计算

19

### 测试用例

``````0
1
2          15
3          10
4          10
5          11
6          12
7           7
8           5
9           6
10
11          7
12          6
13          6
14          7
15          9
16          5
17          7
18          4
19          5
20         15
26          8
60         12
69          3
128         3
150         9
200        15
32043       2
1234567890  3
``````

### 附加规则

• 您的代码必须适用于最多255个所有输入。

请注意，这涉及处理相当大的数字。20 15已经大于2 64

• 如果您打印结果，它后面可能会有换行符。

• 适用标准规则。

14

Aaron

1

xnor 2015年

4

# Pyth，16个字节

``````hf<9l{=+k^QTtS15
``````

### 说明：

``````hf<9l{=+k^QTtS15   implicit: Q = input number
k = empty string
tS15   the list [2, 3, 4, ..., 15]
f                 filter this list for elements T, which satisfy:
^QT          compute Q^T
+k             k + ^ (converts to string implicitly)
= k             save the result in k
l{  k             length of set of k (number of different chars)
<9                  test if 9 is smaller than ^
h                  print the first number in the filtered list
(throws error if empty)
``````

8

## Python 2，56

``f=lambda n,i=2,s='L':len(set(s))>10or-~f(n,i+1,s+`n**i`)``

``f=lambda n,i=2,s='':len({*s})>9or-~f(n,i+1,s+str(n**i))``

4

## Ruby，67个 65个字符

``````->n{s='';[*2..99].index{|i|(s+="#{n**i}").chars.uniq.size==10}+2}
``````

``````-> n {                         # define function with short lambda syntax
s = ''                       # the string we are storing the numbers in
[*2..99]                     # for all numbers from 2 to 99...
.index {|i|                # find index of the number `i` for which...
(s+="#{n**i}")           # after appending pow(n,i) to s...
.chars.uniq.size==10}  # num of uniq chars in s is 10 (each digit)
+ 2                          # add 2, because our index starts from 2
}
``````

3

# CJam，28个字节

``````LliG,2>f#{s+_&_}%:,A#)_)s\g*
``````

``````L     Push empty string, will be used for accumulating digits.
li    Get input and convert to integer.
G,    Build list of exponents [0 .. 15].
2>    Slice off first two values, to produce [2 .. 15].
f#    Apply power operator with all exponents to input.
{     Start loop over powers.
s     Convert to string. We care about the digits here.
+     Concatenate with previously found digits.
_&    Uniquify using set intersection of digit list with itself.
_     Copy for continued accumulation in next loop iteration.
}%    End of loop over powers. We'll have an extra copy of the last value here,
but it does no harm so we just keep it.
:,    Apply length operator to accumulated digit lists.
A#    Find 10 in the list. The search result will correspond to the first power
that resulted in 10 different accumulated digits. If not found, the result
will be -1. Note that 0 corresponds to power 2, since that was the first
power we used. So we need to add 2 to get the result, and check for -1.
)     Increment value. 0 now corresponds to no solution.
_     Copy this value. Will be used as multiplier to create empty string if 0.
)     Increment again, to get the +2 needed for the result.
s     Convert to string.
\     Swap once-incremented value to top, which is 0 for no solution, non-zero
otherwise.
g     Signum to get 0/1 for no solution vs. solution.
*     Multiply with result string, to get empty string for no solution.
``````

2

## Mathematica，103个字节

``````f=(d=DigitCount;x=1;y=d[0];For[n=0,!IntegerQ@Log10[#]&&MemberQ[y,0],++n,x*=#;y+=d[x]];Print[#,"\t",n])&
``````

``````1    0
2    15
3    10
4    10
5    11
6    12
7    7
8    5
9    6
10    0
11    7
12    6
13    6
``````

Sp3000

2

# JavaScript（ES6）188

``````f=n=>{for(p=1,d=[],v=n=[...n+''].reverse();++p<20;){v.map((a,i)=>n.map((b,j)=>r[j+=i]=a*b+~~r[j]),r=[],c=0),r=r.map(r=>(r+=c,c=r/10|0,d[r%=10]=r));v=c?[...r,c]:r;if(d.join``[9])return p;}}

// Less golfed
U=n=>{
// Arbitrary precision multiplication
M=(A,B,R=[],c=0)=>
(
A.map((a,i)=>B.map((b,j)=>R[j+=i]=a*b+~~R[j])),
R=R.map(r=>(r+=c,c=r/10|0,r%10)),
c?[...R,c]:R
);
v=n=[...n+''].reverse();
for(p=1,d=[];++p<20;)
{
v=M(n,v)

v.map(c=>d[c]=c)
if (d.join``[9])return p
}
}

// TEST
for(i=o='';++i<300;)o+=i+' : '+f(i)+'\n'
O.innerHTML=o

``````
``<pre id=O></pre>``

2

### PowerShell，94个字节

``````param(\$n,\$s='')
2..99|%{\$s+=[bigint]::Pow(\$n,\$_);if((\$s-split''|sort -U).Count-eq11){\$_;break}}

(As a single line)
``````

``````param(\$n,\$s='')                              # Take command line parameter.
2..99 |%{                                    # Loop from 2 to 99, inclusive.
\$s+=[bigint]::Pow(\$n,\$_)                 # \$n^Loopvar, concatenate to string.
if ((\$s-split''|sort -U).Count-eq11) {   # Convert to unique-characters-array; count.
\$_;break                             # Print current loopvar and quit.
}
}                                            # Otherwise, finish (silently).
``````

``````PS C:\> .\CUDDLE-of-n.ps1 10

PS C:\> .\CUDDLE-of-n.ps1 12
6

PS C:\> .\CUDDLE-of-n.ps1 255
5
``````

1

# gawk 4，73 + 5标志= 78字节

``{for(n=\$0;a-1023&&++i<15;j=0)for(\$0*=n;j++<NF;)a=or(a,2^\$j)}\$0=i<15?++i:_``

``echo 17 | awk -M '{for(n=\$0;a-1023&&++i<15;j=0)for(\$0*=n;j++<NF;)a=or(a,2^\$j)}\$0=i<15?++i:_' FS=``

```2：32043 32286 33144 35172 35337 35757 35853 37176 37905 38772 39147 39336 40545 42744 43902 44016 45567 45624 46587 48852 49314 49353 50706 53976 54976 55446 55524 55581 55626 56532 57321 58413 58455 58554 59554 60984 61984 61575 61866 62679 62961 63051 63129 65634 65637 66105 66276 67677 68781 69513 71433 72621 75759 76047 76182 77346 78072 78453 80361 80445 81222 81945 83919 84648 85353 85743 85803 85073 86073 87639 88623 89079 89145 89355 89523 90144 90153 90198 91248 91605 92214 94695 95154 96702 97779 98055 98802 99066
3：69 128 203 302 327 366 398 467 542 591 593 598 633 633 643 669 690 747 759 903 923 943 1016 1018 1027 1028 1028 1043 1086 1112 1182 1194 1199 1233 1278 1280 1282 1328 1336 1364 1396 14396 119 1459 1463 1467 1472 1475 1484 1499 1508 1509 1519 1563 1569 1599 1602 1603 1618 1631 1633 1634 1659 1669 1687 1701 1712 1721 1737 1746 1767 1774 1778 1780 1791 1804 1837 1844 1869 1889 1895 1899 1903 1903 1919 1921 1936 1956 1958 1960 1962 1973 1973 1984 1985 1991 1994 1996 2003 2017 2019 2030 2033 2053 2075 2123 2126 2134 2157 2158 2159 2168 2175 2183
4：18 54 59 67 71 84 93 95 97 108 112 115 132 139 144 147 148 152 152 157 159 169 172 174 178 179 180 181 182 184 195 196 196 213 214 215 216 221 221 223 227 228 232 232 234 235 239 241 241 242 248 265 266 267 270 272 273 279 281 285 287 294 298 299 306 311 312 314 315 316 323 326 329 332 336 338 342 343 353 354 356 361 362 364 365 368 369 379 388 391 393 395 396 397 403 412 413 414 416 419 431 434 439 442 443 444 448 451 452 453 454 455 457 459 463 466 469 472 473 477 479 479 482 484 486 489 493 494 494 496 503 507 508 509 509 515 517 523
5：8 16 19 27 28 38 44 47 55 57 61 77 79 80 82 83 86 87 91 92 103 106 113 116 117 118 121 123 125 126 129 131 133 136 136 138 140 141 142 143 145 146 151 154 158 158 160 161 165 167 173175176177183185185186187189189190191192193193197198204204218218224226229230231236240240243246249249255255257258259259261263268268269271271275276277278280280282282284288288289 293 304 309 322 328 331 341 344 345 346 347 348 349 352 357 359 367 371 372 373 374 375 377 380 381 384 387 387 389 402 407 408 408 409 411 417 418 422 427
6：9 12 13 22 23 24 33 36 37 39 42 43 45 46 49 51 53 58 62 66 72 73 75 78 81 88 90 94 98 105 107 109 114 119 120 122 127 130 134 137 149 153 155 162 163 164 164 168 168 170194199206211212217217220220222225233237238238244247252254256262264274291291295296301308317319321324325330333334337351351355358360370370376378378383383380390394399 401 404 405 406 415 420 421 424 425 429 430 433 435 438 446 450 460 471 476 478 488 490 498 498 504 504 506 510 513 514 519 519 530 539 548 556 578 620 628 631 634 636
7：7 11 14 17 29 31 32 35 41 48 52 56 63 64 70 74 85 89 96 99 102 104 110 111 135 171 188 201 202 205 208 245 251 290 297 303 305 307 310 313 318 320 335 350 363 392 410 465 465 475 480 483 485 485 501 518 520 521 560 582 584 595 601 630 640 682 700 736 740 786 798 850 890 952 956 965 975 982 990 999 1002 1005 1011 1020 1040 1054 1100 1110 1171 1219 1313 1331 1350 1379 1414 1447 1468 160 1710 1735 1748 2001 2010 2020 2050 2080 2450 2510 2534 2641 2745 2900 2914 2955 2970 3030 3050 3070 3100 3130 3136 3180 3193 3200
8：21 25 26 30 34 65 76 124 209 210 250 260 300 340 505 650 1004 1240 2002 2090 2100 2500 2600 2975 3000 3400 3944 4376 5050 6500 6885 7399 10040 12400 15483 20002 20020 20900 21000 25000 26000 296000 3750 34000 34000 43760 50500 65000 68850 73990
9：15 68101150 1001 1010 1500 10001 10010 10100 15000
10：3 4 40 400 4000 40000
11：5 50 500 5000 50000
12：6 60 600 6000 60000
15：2 20 200 2000 20000
```