Numbers that are actually letters

42

3

Given a non-negative integer input, write a program that converts the number to hexadecimal and returns a truthy value if the hexadecimal form of the number contains only the characters A through F and a falsey value otherwise.


Test cases

10
==> True (A in hexadecimal)

100
==> False (64 in hexadecimal)

161
==> False (A1 in hexadecimal)

11259375
==> True (ABCDEF in hexadecimal)

0
==> False (0 in hexadecimal)

Bonus: -40 bytes if your program prints Only letters for the challenge described above, Only numbers if the hexadecimal version of the number only contains the digits 0-9 and Mix if the hexadecimal number contains at least one number and at least one letter.


This is code golf. Standard rules apply. Shortest code in bytes wins. Either functions or full programs are allowed.

Arcturus

Posted 2015-12-12T19:09:01.350

Reputation: 6 537

2Currently drafting an answer in Golfical. – SuperJedi224 – 2015-12-12T20:42:01.847

My current idea: covert to base 16 string, then See if trying to parse that string as a base 10 number returns NaN – Cyoce – 2015-12-12T20:54:36.693

@Cyoce That may work, depending on your choice of language – SuperJedi224 – 2015-12-12T20:56:50.843

3Unrealistic bonus (once again): just the string MixOnlynumbersletters is 21 chars – edc65 – 2015-12-12T21:51:02.107

Never mind, a1 can't be parsed as base 10 either. – Cyoce – 2015-12-12T22:11:21.663

3You say "positive integer input", but 0 is a test case. – xnor – 2015-12-12T22:30:43.700

@edc65 Pyth (and I) say otherwise.

– isaacg – 2015-12-13T08:07:55.963

@isaacg Pyth (and you) would have been at ease with the original -25 bonus (which I was referring to)? WIth a score of 18 instead of Adnan's 6 – edc65 – 2015-12-13T11:03:25.127

@edc65 Thanks, I didn't realise the original bonus was lower. – isaacg – 2015-12-13T18:43:29.490

@SuperJedi224 Have you come up with a solution? Or have you already posted it and I missed it? – Arcturus – 2015-12-19T04:23:42.947

@Ampora Sorry about that. I kind of forgot. – SuperJedi224 – 2015-12-19T11:49:14.133

Answers

22

Pyth, 43 - 40 = 3 bytes

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

Test suite

This achieves the bonus. Only numbers and Only letters fortunately only differ by 4 letters. printf-style formatting is used with %.

The selection system is done by both taking the intersection of the hex with G, the alphabet, and subtracting out G. If neither ends up falsy, it's a mix, while if the intersection is falsy, it's numbers, and if the subtraction is falsy, it's letters.

isaacg

Posted 2015-12-12T19:09:01.350

Reputation: 39 268

1Damn this Pyth is weird. Would be very cool if you could get a negative score though. – KaareZ – 2015-12-14T20:55:10.120

15

Pyth, 6 bytes

!-.HQG

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

Test it here

Adnan

Posted 2015-12-12T19:09:01.350

Reputation: 41 965

12

Jelly, 6 bytes

b16>9P

Try it online!

How it works

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.

Dennis

Posted 2015-12-12T19:09:01.350

Reputation: 196 637

Isn't there a built in for 16 or is that not a thing? – CalculatorFeline – 2016-04-20T04:36:27.827

1There is now. This was one of the first Jelly answers... – Dennis – 2016-04-20T04:41:40.283

11

TeaScript, 11 bytes 13 15 16

xT(16)O(Sz)

Pretty simple. This uses TeaScript 2.0. You can get this version from the Github

Explanation

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

Try it online (slightly modified version that works on web)

Downgoat

Posted 2015-12-12T19:09:01.350

Reputation: 27 116

3Is the down-vote because this is long? Is there something else wrong with this answer that I'm not aware of? Or does someone just not personally like this answer? – Downgoat – 2015-12-12T19:32:58.277

2I wouldn't say 16 or 13 bytes is long! – Luis Mendo – 2015-12-12T19:37:19.433

23You have to admit that down-goating your posts is pretty tempting. – Dennis – 2015-12-12T19:57:20.600

10

Python, 24 bytes

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

Converts the input a hex string (without 0x prefix) with '%x'%n. Sees if all its chars are greater than '9' (which letters are) by seeing if the min is above '9'.

xnor

Posted 2015-12-12T19:09:01.350

Reputation: 115 687

I don't know how Python handles characters / numbers, but the ASCII code of '9' is 54. So if you can write ...>54 you can save a byte. – CompuChip – 2015-12-15T10:06:36.387

@CompuChip Python doesn't treat chars or strings as numbers. In fact, Python 2 considers them to be greater than all numbers. – xnor – 2015-12-15T10:27:15.017

8

MATL, 10

i16YA1Y2mA

Examples

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

Explanation

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

Bonus challenge: 53−40 = 13

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

Examples

>> 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

Explanation

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          

Luis Mendo

Posted 2015-12-12T19:09:01.350

Reputation: 87 464

2hmmm what is that ? seems like matlab got some nuc power now ! – Abr001am – 2015-12-12T20:12:33.673

@Agawa001 Hahaha. Sort of

– Luis Mendo – 2015-12-13T04:14:47.183

8

Python 3, 30 29 bytes

1 byte stripped thanks to sysreq and Python 3.

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

Simple lambda and slicing.

LeeNeverGup

Posted 2015-12-12T19:09:01.350

Reputation: 191

8

LabVIEW, 52-40 = 12 LabVIEW Primitives

Praise the built-ins!

enter image description here

Eumel

Posted 2015-12-12T19:09:01.350

Reputation: 2 487

8

C, 46 43 37 bytes

Now with more recursion! (Thanks Dennis):

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

Bonus: even shorter (33 bytes), but fails for x = 0:

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() takes an int and returns either 0 (false) or non-zero (true).

I didn't even try to achieve the bonus, "MixOnly lettersnumbers" takes 23 bytes alone, tracking the new condition would have required 9 additional bytes, printf() is 8 bytes, which adds up to 40, nullifying the effort.

Test main:

#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");
  }
}

Stefano Sanfilippo

Posted 2015-12-12T19:09:01.350

Reputation: 1 059

What's ?:? I had to replace it with || to get it to compile. Also, can you save a byte by replacing the * with an & thus avoiding the ()s on the left (although you then have to add a space)? – Neil – 2015-12-16T00:21:02.853

@Neil a?:b is a GNU extension that evaluates to a if a is a truthy value, otherwise to b. Comes handy to handle null pointers like send(message ?: "(no message)");. I know it's not portable, but code portability is never a concern in code golf :) – Stefano Sanfilippo – 2015-12-17T00:37:22.543

@StefanoSanfilippo you can get this down to 33 bytes by doing this: F(x){x=(x%16>9)*(x<16?:F(x/16));} this abuses a (GCC) bug where if there is no return variable in a function and the main argument was set, it will auto-return the main-argument in some cases (based on what logic was done), and this happens to be one of those cases! Try it online: http://bit.ly/2pR52UH

– Albert Renshaw – 2017-04-22T19:58:45.410

7

Mathematica, 32 bytes

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

Explanation:

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

LegionMammal978

Posted 2015-12-12T19:09:01.350

Reputation: 15 731

7

Julia, 18 bytes

n->isalpha(hex(n))

This is an anonymous function that accepts an integer and returns a boolean. To call it, give it a name, e.g. f=n->....

The input is converted to a hexadecimal string using hex, then we check whether its entirely comprised of alphabetic characters using isalpha.

Alex A.

Posted 2015-12-12T19:09:01.350

Reputation: 23 761

7

Perl 6, 18 bytes

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

usage:

# 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

Brad Gilbert b2gills

Posted 2015-12-12T19:09:01.350

Reputation: 12 713

7

Javascript, ES6, no regexp, 28 bytes

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

There's also this 27-byte version but it returns the inverse value.

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

zocky

Posted 2015-12-12T19:09:01.350

Reputation: 129

Nice! You could also rearrange it like this for 23 bytes: F=n=>!n||n%16>9&F(n>>4) – user81655 – 2015-12-14T13:52:45.297

@user81655 - Unfortunately, that version returns true for 0, so it's incorrect. – zocky – 2015-12-14T14:59:03.837

Oh right, I guess the shortest would be F=n=>n%16>9&&n<16|F(n>>4) then. – user81655 – 2015-12-14T21:56:55.330

@user81655 I'm pretty sure you need to short-circuit the ||, but I think you could get away with using & instead of && in that case. – Neil – 2015-12-16T00:13:04.283

@Neil Why's that? Did you test it? – user81655 – 2015-12-16T02:00:54.017

@user81655 OK so thinking about it again it doesn't matter which of the two operators short-circuits as long as one of them does. Sorry for the confusion. (I should really avoid commenting after midnight...) – Neil – 2015-12-16T22:51:24.870

6

JavaScript ES6, 29

No bonus

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

With the new value of -40 the bonus is nearer now ... but not enough. Bonus score 70 71 - 40 => 30 31

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

Test snippet (type a number inside the input box)

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

edc65

Posted 2015-12-12T19:09:01.350

Reputation: 31 086

-n-1=~n, right? – CalculatorFeline – 2016-04-22T05:42:46.497

@CatsAreFluffy if n is not numeric like 'A' (that's the whole point in this challenge), ~n == -1 while -n-1 == NaN – edc65 – 2016-04-22T08:53:51.537

4

GS2, 6 bytes

V↔i/◙s

The source code uses the CP437 encoding. Try it online!

How it works

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

Dennis

Posted 2015-12-12T19:09:01.350

Reputation: 196 637

4

Java, 46 44 38 bytes

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

Pretty simple one-liner that converts the integer to a hexadecimal string and uses regex to determine if all characters are letters.

-2 bytes thanks to @Eng.Fouad.

TNT

Posted 2015-12-12T19:09:01.350

Reputation: 2 442

"[a-f]+" would save 2 bytes. – Eng.Fouad – 2015-12-13T18:56:25.703

Fails for 516.. – CalculatorFeline – 2016-04-22T15:14:00.573

@CatsAreFluffy No it doesn't.

– TNT – 2016-04-22T15:23:39.743

Well now it determines if the string contains a hex letter, so remove the +–it's a waste of byte. – CalculatorFeline – 2016-04-22T15:53:23.983

@CatsAreFluffy No. matches returns true if the entire string can be matched by the given regex. [a-f] without the plus sign is incorrect since it doesn't match the entire string given that it contains more than one character; it would if and only if one valid character is present.

– TNT – 2016-04-22T16:28:49.047

Oh right. Ok then. – CalculatorFeline – 2016-04-22T17:17:54.443

4

Octave, 22 bytes

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

alephalpha

Posted 2015-12-12T19:09:01.350

Reputation: 23 988

3

CJam (9 8 bytes)

{GbA,&!}

Online demo

Peter Taylor

Posted 2015-12-12T19:09:01.350

Reputation: 41 901

2Equally short: {Gb$N<!} – Dennis – 2015-12-13T02:33:24.673

3

Perl, 69 - 40 = 29 bytes

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

ChicagoRedSox

Posted 2015-12-12T19:09:01.350

Reputation: 240

3

Ruby, 19 bytes

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

Ungolfed:

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

Usage:

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

With bonus, 70 - 40 = 30 bytes

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

Usage:

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

Vasu Adari

Posted 2015-12-12T19:09:01.350

Reputation: 941

Late, but '%x'%n!~/\d/ is a shorter check for solution one, and solution two has a raw byte count of 70, not 75. – Value Ink – 2017-01-26T19:39:10.580

2

Python 3, 28 bytes

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

0WJYxW9FMN

Posted 2015-12-12T19:09:01.350

Reputation: 2 663

2

Common Lisp, 40 bytes

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

Try it online!

Renzo

Posted 2015-12-12T19:09:01.350

Reputation: 2 260

2

SmileBASIC 3.2.1, 78 bytes

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

snail_

Posted 2015-12-12T19:09:01.350

Reputation: 1 982

I don't see any non-ASCII characters here (unless there are some); this counter is the definitive decider and it says 81.

– cat – 2015-12-12T21:08:21.993

1It doesn't matter that the implementation uses UTF-16 internally; to the rest of the world they may as well be UTF-8 chars in the range 0-127, thus your byte count is 81. – cat – 2015-12-12T21:10:05.980

Thanks for the feedback, wasn't sure if "bytes" meant I should count 2 per char. 81 it is. – snail_ – 2015-12-13T18:17:35.677

Actually, the current +10/-0 consensus (which, by the way, I now disagree with) is that we must always use the encoding that an interpreter uses. If you disagree, please post a dissenting opinion on that question.

– lirtosiast – 2015-12-13T18:25:04.443

@ThomasKwa pfft, okay, oops, now I know better. I didn't realise there was a consensus about that, and I spend a fair bit of time on meta. – cat – 2015-12-13T20:57:59.370

Can you not save 3 bytes by writing the entire conditional inside the IF statement? – Neil – 2015-12-16T00:17:10.330

@Neil Ah, you are indeed right. I'll fix that (as well as fixing my byte count.) – snail_ – 2015-12-19T04:15:12.997

@lirtosiast, I created a meta post asking how to score SmileBASIC here.

– redstarcoder – 2017-01-05T17:15:46.150

2

Ceylon, 55 bytes

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

Straightforward ... we format n as a hexadecimal number (which produces a string), call on each character of that string the .digit number (which returns true if it is a digit), then check whether any of them are true, then negate this.

The version with bonus has a lot higher score of 119 - 25 = 94:

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

I'm not sure how anyone could make a bonus version short enough to be better than the no-bonus version, even those strings alone have length 28 together. Maybe a language which makes it really hard to produce a truthy/falsey value.

Here is a formatted version:

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

Paŭlo Ebermann

Posted 2015-12-12T19:09:01.350

Reputation: 1 010

2

Seriously, 12 bytes

4ª,¡OkúOkd-Y

Hex Dump:

34a62cad4f6b
a34f6b642d59

Try It Online

It's the same as the other stack language answers. It would be only 7 bytes if Seriously supported string subtraction yet.

EDIT: Seriously now supports string subtraction and the following 7 byte solution now works:

ú4╙,¡-Y

Hex Dump:

a334d32cad2d59

Try It Online

quintopia

Posted 2015-12-12T19:09:01.350

Reputation: 3 899

111: 4╙,¡#S;ú∩S= (or or , lots of ways to spell :16: in two bytes :P) – Mego – 2015-12-14T01:06:06.833

I didn't know S I think. – quintopia – 2015-12-14T18:31:08.410

2

Rust, 70 bytes

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

Because, ya know, Java Rust.

It's actually quite elegant, though:

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
  )

But it's a shame the function definition boilerplate is so long.... :P

Doorknob

Posted 2015-12-12T19:09:01.350

Reputation: 68 138

I have an idea. More closures! – CalculatorFeline – 2016-04-22T15:18:33.490

2

CJam, 44 bytes - 40 bonus = 4 bytes

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

Try it here~

Lynn

Posted 2015-12-12T19:09:01.350

Reputation: 55 648

2

05AB1E, 2 bytes (non-competing)

Code:

ha

Ha! That is two bytes! Sadly non-competing because this language postdates the challenge :(

Explanation:

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

Try it online! or Verify all test cases!

Adnan

Posted 2015-12-12T19:09:01.350

Reputation: 41 965

1hdÔ©1åi•4?ŸâτΛ•}®0åi•4?ŸàpÕTà•}®g2Qi•²•}36B` for the bonus resulting in... 6 more! Wooooo bonuses! – Magic Octopus Urn – 2017-01-24T18:40:17.560

1

Ruby, 16 bytes

->n{/\d/!~'%x'%n}

Ruby, 70 bytes - 40 bonus = 30

f=->n{s="Only #{n%16<10?:Numbers:'Letters'}";n<16||s==f[n/16]?s:'Mix'}

histocrat

Posted 2015-12-12T19:09:01.350

Reputation: 20 600

Amazingly, the other Ruby poster miscounted their solution w/ bonus and they also have 30 as their final score. But hey, it's a different and unique solution! – Value Ink – 2017-01-26T19:45:56.817

1

PHP, 32 bytes

since rink.attendant.6 won´t react; I post my own.

echo+ctype_alpha(dechex($argn));

takes input from STDIN; prints 1 or 0; run with -R.

bonus attempt, 93 87-40=47
5 bytes saved by Jörg, 1 by me

echo(ctype_alpha($s=dechex($argn))+$d=ctype_digit($s))?"Only ".[lett,numb][$d].ers:Mix;

takes input from STDIN; run with -nR.

btw. ctype_xdigit would be an option for Mix and help serialize (though pi is the shortest alternative); but I guess it can´t get any shorter than Jörgs idea with my golfing.
The more you serialize, the longer it gets.

a partly serialized version for 101 100-40=60:
2 bytes saved and 1 byte fixed by Jörg

echo strtr([ctype_alpha($s=dechex($argn))=>_letters,ctype_digit($s)=>_numbers,Mix][1],[_=>"Only "]);

and fully serialized for 114 112-40=72:
-2 bytes inspired by Jörg

foreach([pi=>Mix,ctype_alpha=>lett,is_numeric=>numb]as$f=>$t)$f(dechex($argn))&&$s=$t<a?$t:"Only $t".ers;echo$s;

Titus

Posted 2015-12-12T19:09:01.350

Reputation: 13 814

wonderful I found a shorter approach echo ctype_alpha($s=dechex($argn))+($d=ctype_digit($s))?"Only ".[lett,numb][$d].ers:Mix; or echo ctype_alpha($s=dechex($argn))+($d=ctype_digit($s))?$d?"Only numbers":"Only letters":Mix; with the same byte count for the bonus version – Jörg Hülsermann – 2017-04-24T01:07:18.083

@JörgHülsermann Thanks. And another byte shorter if you place the parentheses differently. – Titus – 2017-04-24T05:59:23.773

1I found your old version more interesting! And you can save two Bytes if you change the order echo[ctype_alpha($s=dechex($argn))=>"Only letters",ctype_digit($s)=>"Only numbers",Mix][1]; Could you please add your old version as tip for PHP. And please add a closing ] in the partly serialized version – Jörg Hülsermann – 2017-04-24T09:16:15.893

1

PHP, 56 44 bytes

This isn't going to win, but might as well. Takes one command-line argument.

Thank you @Blackhole for reducing this by 12 bytes.

<?=ctype_lower(base_convert($argv[1],10,16))

// Previous attempt, 56 bytes
<?=preg_match('#^[a-f]+$#',base_convert($argv[1],10,16))

rink.attendant.6

Posted 2015-12-12T19:09:01.350

Reputation: 2 776

1

I'm pleased to introduce you the ctype_alpha() function ;).

– Blackhole – 2015-12-13T00:57:34.143

@Blackhole Ahh thank you. Gotta love PHP, functions for everything :) – rink.attendant.6 – 2015-12-13T06:01:42.793

dechex() saves 11 bytes. – Titus – 2017-01-25T22:14:16.197

1

Japt, 12 bytes

!UsG r"[a-f]

Try it online!

How it works

!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.

ETHproductions

Posted 2015-12-12T19:09:01.350

Reputation: 47 880

I think !!UsG r"\\d might work and save a byte – Downgoat – 2015-12-13T00:53:28.327

@Downgoat Good observation, but that returns true for any number that contains a letter. – ETHproductions – 2015-12-13T01:09:38.087

1

Haskell, 39 bytes

p n|mod n 16<10=0|n<16=1|1<2=p$div n 16

Returns 0 or 1. Usage example:

*Main> map p [10,100,161,11259375,0]
[1,0,0,1,0]

Haskell has neither built-in base conversion nor check for letters. Both functions are in modules where the imports alone would cost 36 bytes, so that's not an option. Instead I check the input number n for:

  1. if mod n 16 is less than 10 -> False
  2. if n is less than 16 -> True
  3. otherwise re-check with n/16.

nimi

Posted 2015-12-12T19:09:01.350

Reputation: 34 639

1

C, 132 bytes

int main(){int a=0,p=1;char b[256];scanf("%d",&a);sprintf(b,"%x",a);for(char*c=b;*c!='\0';c++)if(isdigit(*c)){printf("False");p=0;}if(p)printf("True");return 0;}

Detailed

int main()
{
    int a=0, p=1;
    char b [256];

    scanf("%d",&a); // read input as an integer
    sprintf(b,"%x",a); // read in Hex into string

    for(char * c=b; *c!='\0'; c++)
    {
        if(isdigit(*c)) // if it's a digit
        {
            printf("%x No",a);
            p=0;
        }
    }

    if(p) // if no digit was found
    {
        printf("%x Yes",a);
    }

    return 0;
}

Bonus, 232 - 40 = 192 bytes

int main(){int a=0, p=0,q=0;char b [256];scanf("%d",&a);sprintf(b,"%x",a);for(char * c=b; *c!='\0'; c++) if(isdigit(*c)) p=1; else q=1;if(p&&q) printf("Mixed");else if(p) printf("Only numbers");else printf("Only letters");return 0;}

Detailed

int main()
{
    int a=0, p=0,q=0;
    char b [256];

    scanf("%d",&a);
    sprintf(b,"%x",a);

    for(char * c=b; *c!='\0'; c++) if(isdigit(*c)) p=1; else q=1;

    if(p&&q) printf("Mixed");
    else if(p) printf("Only numbers");
    else printf("Only letters");

    return 0;
}

Khaled.K

Posted 2015-12-12T19:09:01.350

Reputation: 1 435

main() does not return void in standard C. – Peter – 2015-12-13T13:25:07.853

@Peter fixed it now, it's weird given I've read it in a book during my study. C89 turned out that you can write main() and the return type will be assumed as int – Khaled.K – 2015-12-13T13:56:00.527

1

Gema, 41 characters

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

There is no boolean in Gema, so it simply outputs “t” or “f”.

Sample run:

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

manatwork

Posted 2015-12-12T19:09:01.350

Reputation: 17 865

1

Perl, 24 bytes

$_=sprintf"%x",$_;$_=/\D/&/\d/?Mix:Only.$".(/\d/?numb:lett).ers

Code is 63 bytes, add 1 for the -p flag, and then subtract 40 for the bonus.

Grimmy

Posted 2015-12-12T19:09:01.350

Reputation: 12 521

1

Binary-Encoded Golfical, 50+1 (-x flag)=51 bytes

Noncompeting; the modulo instruction used here, although it was added to the specs, according the repo's revision history, on the same day this question was posted, was for some reason never implemented until earlier today.

Hexdump:

00 C0 03 15 14 14 1B 1A 14 08 01 14 17 00 10 14
00 01 0A 01 21 1E 2C 3D 14 53 2D 14 08 01 0A 01
1C 00 0A 00 10 17 0A 01 08 01 00 00 26 14 1E 1C
1D 14

This encoding can be converted back to the original graphical form using the included Encoder utility, or run directly by adding the -x flag.

Original image:

enter image description here

Magnified 50x:

enter image description here

Rough translation:

prompt *p
label A
push *p
*p%=16
if *p<10
 print 0
 exit
endif
*p=pop
*p/=16
if *p==0
 print 1
 exit
endif
goto A

SuperJedi224

Posted 2015-12-12T19:09:01.350

Reputation: 11 342

0

SmileBASIC, 52 50 bytes

INPUT V
H$=HEX$(V)WHILE""<H$P=@A<POP(H$)||P
WEND?P

Determines if each digit is a number or letter by comparing it with @A (the A doesn't matter since it would only look at it if the first characters were the same). @ is between the number and the letters in ASCII.

12Me21

Posted 2015-12-12T19:09:01.350

Reputation: 6 110

0

MATL, 7 bytes

1YAtk=~

Explanation:

1       % number literal
YA      % convert integer to string representation in given base (16)
t       % duplicate elements
k       % convert (the second) string to lowercase
=       % is equal?
~       % logical 'not' (element-wise)
        % (implicit) convert to string and display

For only letters to be in the base-16 representation, when the string is made lowercase every character must have changed, so the arrays should never be equal to each other, and only arrays of ones are truthy in MATL.

Bonus challenge, 47-40 = 7 bytes:

1YAtk=XK?'Only numbers'}Ka?'Mix'}'Only letters'

Essentially the same as the other MATL answer given, the same ending was used just without trailing ]] and with reordering the outputs.

B. Mehta

Posted 2015-12-12T19:09:01.350

Reputation: 763

0

Befunge (quirkster flavor), 34 bytes

&:44*%9`!#@ #. #0_44*/:!#@ #. #1_#

Befunge control flow loops around to the beginning when it hits the end, so a recursive solution is pretty natural. If the input is less than 9 modulo 16, print 0 (the only falsey value in Befunge) and exit. If not, divide the number by 16, rounding down. If it's now 0, print 1 and exit, otherwise recurse. In effect, this checks each hex digit from right to left.

histocrat

Posted 2015-12-12T19:09:01.350

Reputation: 20 600

0

Clojure, 35 bytes

#(every?(set"abcdef")(format"%x"%))

NikoNyrh

Posted 2015-12-12T19:09:01.350

Reputation: 2 361

0

tcl, 35

puts [string is alp [format %x $n]]

demo

sergiol

Posted 2015-12-12T19:09:01.350

Reputation: 3 055

0

Pushy, 16 bytes

$&16%v16/;OKT)P#

Try it online!

Essentially calculates all digits as numbers 0-16, and then checks they are all over 10.

                    \ Implicit: Input on first stack
$        ;          \ While input != 0:
 &16%v              \   Push input % 16 to second stack
      16/           \   Floordiv input by 16
          O         \ Go to second stack
           KT)      \ Map all numbers to boolean: bigger than 10?
              P     \ Get the product (only 1 if all values are 1)
               #    \ Print result.

FlipTack

Posted 2015-12-12T19:09:01.350

Reputation: 13 242

0

Excel, 121 bytes

=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(DEC2HEX(A2),"A",),"B",),"C",),"D",),"E",),"F",))=0

Nothing graceful about this one.

Wernisch

Posted 2015-12-12T19:09:01.350

Reputation: 2 534

0

CoffeeScript, 42 36 bytes

f=(x)->/^[a-f]+$/.test x.toString 16

// Previous attempt (42)
f=(x)->!x.toString(16).replace /[a-f]/g,''

JavaScript (ES6), 41 36 bytes

f=x=>/^[a-f]+$/.test(x.toString(16))

// Previous attempt (41)
f=x=>!x.toString(16).replace(/[a-f]/g,``)

rink.attendant.6

Posted 2015-12-12T19:09:01.350

Reputation: 2 776

2You can remove the f= from the javascript one. – Conor O'Brien – 2015-12-12T19:48:07.193

0

R, 34 bytes

!grepl("\\d",sprintf("%x",scan()))

scan() takes an integer from stdin, sprintf("%x",...) returns the hexadecimal representation of that integer (R's sprintf is equivalent to C's sprintf), then the regex checks if the string contains digits.

Usage:

> !grepl("\\d",sprintf("%x",scan()))
1: 100
2: 
Read 1 item
[1] FALSE
> !grepl("\\d",sprintf("%x",scan()))
1: 10
2: 
Read 1 item
[1] TRUE
> !grepl("\\d",sprintf("%x",scan()))
1: 161
2: 
Read 1 item
[1] FALSE
> !grepl("\\d",sprintf("%x",scan()))
1: 11259375
2: 
Read 1 item
[1] TRUE
> !grepl("\\d",sprintf("%x",scan()))
1: 0
2: 
Read 1 item
[1] FALSE

plannapus

Posted 2015-12-12T19:09:01.350

Reputation: 8 610

0

, 9 chars / 16 bytes

!ïⓧċ/[α]⌿

Try it here (Firefox only).

Regex aliases ftw!

Explanation

        // Implicit: ï = input
!       // logical-negate the result of the following code:
 ïⓧ    // convert ï to hex...
 ċ/[α]⌿ // and see if it has any letters
        // implicit output

Mama Fun Roll

Posted 2015-12-12T19:09:01.350

Reputation: 7 234

0

Pyke, 6 bytes

b16G-!

Try it here!

Or 10 bytes with the bonus

b16\9L>]0}DlRs*"Only numbers,Only letters,Mix"\,c@

Explanation:

b16                                                -      base_16(input())
   \9L<                                            -     map("9">char for char in ^)
       ]0                                          -    list(^)
         }                                         -   set(^)
          DlRs*                                    -  len(^)*sum(^)
                                                 @ - V[^]
               "Only numbers,Only letters,Mix"\,c  -  str.split(",")

Try it here!

Blue

Posted 2015-12-12T19:09:01.350

Reputation: 26 661