# 数字是多少？

13

7段数字可以使用`_|`字符以ASCII表示。以下是尺寸`1`位数：

``````   _  _       _   _   _   _   _   _
|  _| _| |_| |_  |_    | |_| |_| | |
| |_  _|   |  _| |_|   | |_|  _| |_|
``````

`````` ___    ___    ___    ___    ___    ___    ___
|   |  |          |  |          |  |   |  |   |
|   |  |          |  |          |  |   |  |   |
|___|  |___       |  |___    ___|  |   |  |___|
|   |  |   |      |      |      |  |   |      |
|   |  |   |      |      |      |  |   |      |
|___|  |___|      |   ___|   ___|  |___|   ___|
``````

## 目标

``````Digit  Height  Width (not counting newlines)
1      2N      1
2      2N+1    N+2
3      2N+1    N+1
4      2N      N+2
5      2N+1    N+2
6      2N+1    N+2
7      2N+1    N+1
8      2N+1    N+2
9      2N+1    N+2
0      2N+1    N+2
``````

## I / O实例

``````__
|
__|
|
__|
``````

``````2
``````

``````|
|
|
``````

``````0  //because it is of an invalid height.  Either 1 char too short or tall.
``````

``````|    |
|    |
|    |
|____|
|
|
|
|
``````

``````4
``````

`````` ___
|
|___
|   |
|___|
``````

``````0 //1 char too wide
``````

`````` _
|_|
| |
``````

``````0 //it's not a digit
``````

`````` __
|
|__
|
__|
``````

``````2
``````

`````` _  _
_| _|
|_  _|
``````

``````0  //both would be valid individually, but input should be a *single* digit
``````

`````` _
|_|
|_|
``````

``````1
``````

``````|
|
``````

``````1
``````

``````__|_
|
_ |
_
|__
``````

``````0
``````

@steveverrill实际上没有大小`0`数字之类的东西，是吗？除非您想出一种绘制它们的方法。
PhiNotPi

8

ETHproductions 2016年

PhiNotPi

@ETHproductions如果没有该要求，它将与codegolf.stackexchange.com/q/19548/15599
Level River St

1

# 红宝石250

``````->x{d=y=0
x.size.downto(0){|n|y=n
a=["|
"*2*n]
"XNRDqpm@A".bytes{|z|p=[?|,' ','']
h=s=""
(n*2).times{|i|
i%n<1&&(d=z>>i/n*3&7)&&h=[?_,' '][d/3%2]*n
s=p[d%3]+h+p[d/6]+"
"+s
h=' '*n}
z!=68&&s=' '*(1-d%3/2)+?_*n+"
"+s
a<<s};puts a
a.index(x)&&break}
y}
``````

`.`由于诊断原因，此版本使用空格代替。

``````#Encoding used for half-digits (radix 3,2,2 most significant digit at right)

#000    |_|  0

#100    ._|  1  . = space

#200    X_|  2  X = no space (for digits 3 and 7)

#010    |.|  3

#110    ..|  4

#210    X.|  5

#001    |_.  6

f=->x{d=y=0                                        #d and y required to be intialized for scoping reasons
x.size.downto(0){|n|y=n                          #Assume max possible size of character = length of input and iterate down through all possible sizes n
a=["|\n"*2*n]                                  #Make an array containing the digit 1 (different shape to others)
"XNRDqpm@A".bytes{|z|                          #Each character encodes the pattern for a digit. Iterate through them
p=['|','.','']                               #Possible components for left and right of digit
h=s=""                                       #h initialized for scoping reasons. s will contain the digit string
(n*2).times{|i|                              #For each row
i%n<1&&                                    #If i%n==1 we are at the bottom of a half digit
(d=z>>i/n*3&7)&&                           #so extract info from z and store in d
h=[?_,'.'][d/3%2]*n                        #h is the horizontal part of the half digit, either _ or spaces
s=p[d%3]+h+p[d/6]+"\n"+s                   #Build one row of digit, working upwards: left,middle,right
h='.'*n                                    #If row i%n!=0 (not bottom row of half digit)the middle section must contain spaces
}                                            #We now have both halves of the digit, only the top segment missing
z!=68&&s='.'*(1-d%3/2)+?_*n+".\n"+s          #If z!=68 (digit 4) add a top to the digit, with appropriate leading and trailing spaces
a<<s                                         #Add the completed digit of size n to a
}
#puts a                                        #Diagnostic: uncomment to print all the strings checked
a.index(x)&&break                              #If string x is in a, break

}
y                                                  #and return last value of n
}

# digit 7, size 2. Trailing newline required. Outputs 2
puts f[
"__.
..|
..|
..|
..|
"]
``````