# 实际上是字母的数字

42

``````10

100

161

11259375

0
``````

2

SuperJedi224

Cyoce

@Cyoce可能有效，具体取决于您选择的语言
SuperJedi224 2015年

3

edc65

3

xnor

22

# Pyth，43-40 = 3个字节

``````?&K@J.HQG-JG"Mix"%"Only %sers"?K"lett""numb
``````

1

KaareZ

15

# Pyth，6个字节

``````!-.HQG

.HQ   # Converts the input to hexadecimal
-   G  # Deletes all letters
!       # If empty, output True, else False
``````

12

# 果冻，6个字节

``````b16>9P
``````

### 这个怎么运作

``````b16>9P  Input: z

b16     Convert the input to base 16.
>9   Compare each resulting digit with 9; return 1 iff greater.
P  Take the product of the resulting Booleans.
``````

CalculatorFeline

1

11

# TeaScript，11个字节13 15 16

``````xT(16)O(Sz)
``````

## 说明

``````        // Implicit: x = input, Sz = alphabet
xT(16)  // input -> hex
O(Sz)   // Only letters?
``````

3

Downgoat

2

23

10

## Python，24个字节

``lambda n:min('%x'%n)>'9'``

CompuChip 2015年

@CompuChip Python不会将字符或字符串视为数字。实际上，Python 2认为它们大于所有数字。
xnor 2015年

8

# MATL，10

``````i16YA1Y2mA
``````

### 例子

``````>> matl i16YA1Y2mA
> 240
0
>> matl i16YA1Y2mA
> 255
1
``````

### 说明

``````i       % input
16YA    % convert to string representation in base 16
1Y2     % predefined literal: 'A':'Z'
m       % true for set member
A       % all
``````

# 额外挑战：53-40 = 13

``````i16YA1Y2mXKA?'Only letters'}Ka?'Mix'}'Only numbers']]
``````

### 例子

``````>> matl
> i16YA1Y2mXKA?'Only letters'}Ka?'Mix'}'Only numbers']]
>
> 255
Only letters

>> matl
> i16YA1Y2mXKA?'Only letters'}Ka?'Mix'}'Only numbers']]
>
> 100
Only numbers

>> matl
> i16YA1Y2mXKA?'Only letters'}Ka?'Mix'}'Only numbers']]
>
> 240
Mix
``````

### 说明

``````i                       % input
16YA                    % convert integer to string representation in base 16
1Y2                     % predefined literal: 'A':'Z'
m                       % true for set member
XK                      % copy to clipboard K
A                       % all
?                       % if (top of the stack)
'Only letters'        % string literal
}                       % else
K                     % paste from clipboard K
a                     % any
?                     % if (top of the stack)
'Mix'               % string literal
}                     % else
'Only numbers'      % string literal
]                     % end
]                       % end
``````

2

2015年

@ Agawa001哈哈哈 排序

8

8

# C，46 43 37字节

``F(x){return(x%16>9)*(x<16?:F(x/16));}``

``F(x){return!x?:(x%16>9)*F(x/16);}``

``b;F(x){for(b=x;x;x/=16)b*=x%16>9;return b;}``

`F()`接受`int`并返回`0`（false）或非零（true）。

``````#include <stdio.h>

int main() {
int testdata[] = {10, 100, 161, 11259375, 0};
for (int i = 0; i < 5; ++i) {
int d = testdata[i];
printf("%d (0x%x) -> %s\n", d, d, F(d)?"yep":"nope");
}
}``````

@Neil `a?:b`是GNU扩展，其评估为`a`if `a`是真实值，否则为`b`。方便处理空指针之类的`send(message ?: "(no message)");`。我知道它不是可移植的，但是代码可移植性从来都不是代码高尔夫中的问题：）
Stefano Sanfilippo

@StefanoSanfilippo您可以`33`通过执行以下操作将其简化为字节：`F(x){x=(x%16>9)*(x<16?:F(x/16));}`这会滥用（GCC）错误，即如果函数中没有返回变量并且设置了main参数，则在某些情况下，它将自动返回main参数（根据所执行的逻辑），而这恰恰是其中一种情况！在线尝试：bit.ly/2pR52UH

8

# Python 3中，30 29个字节

``lambda n:hex(n)[2:].isalpha()``

7

# Perl 6、18个字节

``{.base(16)!~~/\d/} # 18 bytes``

``````# give it a name
my &code = {.base(16)!~~/\d/}

for 10, 100, 161, 11259375, 0 {
printf "%8s %6s %s\n", \$_, .base(16), .&code
}

10      A True
100     64 False
161     A1 False
11259375 ABCDEF True
0      0 False``````

7

## Mathematica，32个字节

``````Tr@DigitCount[#,16,0~Range~9]<1&
``````

``````                               &   A function returning whether
Tr@                                 the sum of elements of
DigitCount[ ,  ,         ]        the numbers of
0~Range~9          zeros, ones, ..., nines in
#                       the first argument
<1     is less than one.
``````

7

# Javascript，ES6，无正则表达式，28个字节

``F=n=>n%16>9&&(n<16||F(n>>4))``

``F=n=>n%16<10||n>15&&F(n>>4)``

user81655

@ user81655-不幸的是，该版本返回0的true，所以它是不正确的。
zocky 2015年

user81655

@ user81655我很确定您需要使短路`||`，但我认为您可以避免使用`&`而不是`&&`那种情况。

@Neil为什么呢？你测试了吗？
user81655

7

# 朱莉娅，18个字节

``n->isalpha(hex(n))``

6

# JavaScript ES6、29

``n=>!/\d/.test(n.toString(16))``

``n=>/\d/.test(n=n.toString(16))?1/n?'Only numbers':'Mix':'Only letters'``

``#I { width:50%}``
``````<input id=I oninput="test()"/><br>
Hex <span id=H></span><br>
Result <span id=R></span>``````

`-n-1`= `~n`，对吗？
CalculatorFeline

@CatsAreFluffy，如果n不是像“ A”这样的数字（这就是本次挑战的全部内容），`~n == -1``-n-1 == NaN`
edc65 '16

4

# GS2，6个字节

``````V↔i/◙s
``````

### 这个怎么运作

``````V       Evaluate the input.
↔      Push 16.
i     Perform base conversion.
/    Sort.
◙   Push [10].
s  Perform greater-or-equal comparison.
``````

4

# 八度，22字节

``````@(n)all(dec2hex(n)>64)
``````

4

# Java，46 44 38字节

``i->i.toHexString(i).matches("[a-f]+");``

`"[a-f]+"`将节省2个字节。

CalculatorFeline

@CatsAreFluffy 不，不是。
TNT 2016年

CalculatorFeline

TNT

3

# Ruby，19个字节

``````->n{!('%x'%n)[/\d/]}
``````

``````-> n {
!('%x'%n)[/\d/]
}
``````

``````f=->n{!('%x'%n)[/\d/]} # Assigning it to a variable
f[0]
=> false
f[10]
=> true
f[100]
=> false
f[161]
=> false
f[11259375]
=> true
``````

``````->n{'%x'%n=~/^(\d+)|(\D+)\$/;\$1?'Only numbers':\$2?'Only letters':'Mix'}
``````

``````f=->n{'%x'%n=~/^(\d+)|(\D+)\$/;\$1?'Only numbers':\$2?'Only letters':'Mix'}
f[10]
=> Only letters
f[100]
=> Only numbers
f[161]
=> Mix
``````

3

## Perl，69-40 = 29个字节

``\$_=sprintf"%X",<>;print s/\d//?\$_?"Mix":"Only numbers":"Only letters"``

2

## 锡兰，55字节

``Boolean l(Integer n)=>!any(formatInteger(n,16)*.digit);``

``String c(Integer n)=>let(s=formatInteger(n),d=s*.digit)(every(d)then"Only numbers"else(any(d)then"Mix"else"Only letters"));``

``````String c(Integer n) =>
let (d = formatInteger(n,16)*.digit)
(every(d) then "Only numbers"
else (any(d) then "Mix"
else "Only letters"));``````

2

## Rust，70个字节

``fn f(n:i32)->bool{format!("{:x}",n).chars().all(|c|c.is_alphabetic())}``

``````format!("{:x}", n)         // format n as hex (:x)
.chars()                 // get an Iter over the characters
.all(                    // do all Iter elements satisfy the closure?
|c| c.is_alphabetic()  // self-explanatory
)``````

CalculatorFeline

2

# CJam，44个字节-40个奖励= 4个字节

``````2,riGbAf/&:-"Only numbersOnly lettersMix"C/=
``````

2

## 认真地，12个字节

``````4ª,¡OkúOkd-Y
``````

``````34a62cad4f6b
a34f6b642d59
``````

``````ú4╙,¡-Y
``````

``````a334d32cad2d59
``````

1
11 ：（`4╙,¡#S;ú∩S=`或，`4ª`或用`8τ`很多方法`:16:`在两个字节中拼写：P）
Mego

quintopia

2

# 05AB1E，2个字节（非竞争）

``````ha
``````

``````h   # Convert input to hexadecimal
a  # is_alpha, checks if the value only contains letters
``````

1
`hdÔ©1åi•4?ŸâÏ„Î›•}®0åi•4?ŸàpÕTà•}®g2Qi•²`•} 36B`的奖金产生了...另外6个！太棒了！

2

# Python 3，28个字节

``lambda x:min(hex(x)[1:])>'@'``

2

# Common Lisp，40个字节

``````(every'alpha-char-p(format()"~x"(read)))
``````

2

# SmileBASIC 3.2.1，78字节

``````INPUT V FOR I=0 TO 9
IF INSTR(HEX\$(V),STR\$(I))>-1 THEN ?"FALSE"END
NEXT?"TRUE"
``````

1

snail_

lirtosiast 2015年

1

# Japt，12个字节

``````!UsG r"[a-f]
``````

### 这个怎么运作

``````!UsG r"[a-f] // Implicit: U = input integer, G = 16
UsG         // Convert U to a base-16 string.
r"[a-f] // Replace all lowercase letters with an empty string.
!            // Take the logical NOT of the result.
// This returns true for an empty string; false for anything else.
``````

Downgoat 2015年

@Downgoat很好的观察，但是对于包含字母的任何数字都返回true 。
ETHproductions 2015年

1

# Gema，41个字符

``````*=@c{@radix{10;16;*}}
c:<D>=f@end;?=;\Z=t
``````

Gema中没有布尔值，因此只输出“ t”或“ f”。

``````bash-4.3\$ echo -n '11259375' | gema '*=@c{@radix{10;16;*}};c:<D>=f@end;?=;\Z=t'
t
``````