16
\$\begingroup\$

Image of Hex Conversion Table w/ counter

Hexadecimal is a base 16 counting system that goes from0 tof. Your job is to make a counter that will display these numbers.

Example:

$ python counter.py1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30

Rules:

  • The numbers may be separated by spaces, tabs, or new lines.
  • The minimum number you must go to is30 (48 in decimal).
    • You may also make the program print numbers forever until it is stopped.
  • Letters may be in uppercase or lowercase (A ora).
  • No built in functions allowed (that directly affect hexadecimal conversions/counting).
  • Leading zeros are allowed
  • It may start from1 or0
  • Shortest code wins!
askedJul 12, 2015 at 16:02
jado's user avatar
\$\endgroup\$
19
  • \$\begingroup\$@Sp3000 How built in are they? Converting decimal to hex?\$\endgroup\$CommentedJul 12, 2015 at 16:05
  • 5
    \$\begingroup\$How about general base conversion functions then?\$\endgroup\$CommentedJul 12, 2015 at 16:11
  • 1
    \$\begingroup\$@Sp3000 Sure (ignore this, 15 character limit)\$\endgroup\$CommentedJul 12, 2015 at 16:13
  • 1
    \$\begingroup\$@Mauris Yes! That sure is going to be interesting...\$\endgroup\$CommentedJul 13, 2015 at 17:29
  • 1
    \$\begingroup\$I was looking at the previous comments and it looked like you agreed togeneral base conversion functions when Sp3000 asked. Also does that includeprintf type functions?\$\endgroup\$CommentedJan 17, 2016 at 14:55

42 Answers42

7
\$\begingroup\$

PureBash, 26

Counts from 0x0 to 0x3F:

echo {0..3}{{0..9},{A..F}}

Try it online!

answeredJul 13, 2015 at 2:42
Digital Trauma's user avatar
\$\endgroup\$
6
\$\begingroup\$

CJam,21 14 bytes

A,_6,'Af++m*S*

Prints the numbers 00 to 9F.

Try it online in theCJam interpreter.

How it works

A,             e# Push [0 ... 9].  _            e# Push a copy.   6,          e# Push [0 ... 5].     'Af+      e# Add 'A' to each. This pushes "ABCDEF".         +     e# Concatenate. This pushes [0 ... 9 'A' ... 'F'].          m*   e# Cartesian product. This pushes [[0 0] ... [9 'F'].            S* e# Join, separating by spaces.
answeredJul 12, 2015 at 16:42
Dennis's user avatar
\$\endgroup\$
5
\$\begingroup\$

Pyth - 12 bytes

Uses cartesian product, and sorts at the end to get in correct order, then joins by spaces. Prints00-ff inclusive.

jdS^s+<G6UT2

Try it online here.

jd             Join by spaces S             Sort lexiographically  ^    2       Cartesian product repeat twice   s+          Append then concatenate entire list    <G6        First six of alphabet    UT         Range 0-9
answeredJul 16, 2015 at 2:08
Maltysen's user avatar
\$\endgroup\$
5
\$\begingroup\$

Python 2, 52

a=0for b in'0123456789ABCDEF'*4:print`a`+b;a+=b>'E'

Prints00 to3F. Takes advantage of the fact that the first digita is always a number in this range. Loops through four cycles of the second digitb, incrementinga whenever the second digit isF.

This is one char shorter than the more direct

for a in'0123': for b in'0123456789ABCDEF':print a+b
answeredJul 13, 2015 at 3:16
xnor's user avatar
\$\endgroup\$
6
  • \$\begingroup\$n ='0123' should save some chars\$\endgroup\$CommentedJul 13, 2015 at 13:45
  • \$\begingroup\$@Caridorc How exactly?\$\endgroup\$CommentedJul 13, 2015 at 20:10
  • \$\begingroup\$by writingthing in n + restofstring\$\endgroup\$CommentedJul 13, 2015 at 20:11
  • \$\begingroup\$@Caricord Not sure what you mean, it's longer to don='0123' for a in n: for b in n+'456789ABCDEF':print a+b\$\endgroup\$CommentedJul 13, 2015 at 20:12
  • 2
    \$\begingroup\$@Caridorc A metal shortcut I use is that saving to a variable costs 4 chars, so it needs >4 chars of saving to compensate, so saving 4 chars for0123 for something else isn't enough.\$\endgroup\$CommentedJul 13, 2015 at 20:15
5
\$\begingroup\$

JavaScript (ES6), 57 bytes

Same approach as the Python ones I suppose.

for(i of c='0123456789ABCDEF')for(j of c)console.log(i+j)
answeredJul 13, 2015 at 15:50
rink.attendant.6's user avatar
\$\endgroup\$
4
\$\begingroup\$

TI-Basic, 63 bytes

:For(I,0,4,16⁻¹:Disp sub(" 0123456789ABCDEF",1+16fPart(I),2:Output(7,1,int(I:End

This is 63 bytes, according to the memory management screen on my calculator, a TI-84+. Make sure to start the program with a partially filled home screen!

answeredJul 12, 2015 at 17:13
gengkev's user avatar
\$\endgroup\$
1
  • \$\begingroup\$Did you remember to subtract the length of the 9-byte header and the program name from the code length?\$\endgroup\$CommentedJul 13, 2015 at 2:58
4
\$\begingroup\$

Befunge-93, 57 bytes

<_v#-*44:+1,*84,g2:\,g2:\^ >$1+:9-!#@_00123456789ABCDEF

Prints numbers from00to8F. If you prefer your programs to run forever, the version below is non-terminating and will continually output all numbers from00 toFF.

<_v#-*44:+1,*84,g2:\,g2:\^ >$1+:35*`!*00123456789ABCDEF
answeredJul 13, 2015 at 14:41
Sok's user avatar
\$\endgroup\$
8
  • \$\begingroup\$You can save a couple bytes in -98 with <_v#-f:+1, ',g2:\,g2:\. Can't see many improvements beyond that.\$\endgroup\$CommentedJul 13, 2015 at 17:05
  • \$\begingroup\$0123456789ABCDEF01g::88+/2-0g,88+%0g,9,1+01p\$\endgroup\$CommentedJul 13, 2015 at 17:29
  • \$\begingroup\$That's 44 bytes. It loops forever, like your second solution, and prints wrong results past the second 1F. It requires an implementation (such as the reference implementationbef.c) that silently ignores unknown commands (ABCDEF).\$\endgroup\$CommentedJul 13, 2015 at 17:31
  • \$\begingroup\$(The OP mentions it's okay for a solution to "break" somewhere past hitting30 -- this one will slowly overflow the stack, so I suppose there's some point of termination. Also, output is tab-separated; the OP said this was fine.) Oh, the Befunge implementation you use should also initialize the whole 80x25 torus with spaces (ASCII0x20).\$\endgroup\$CommentedJul 13, 2015 at 17:37
  • \$\begingroup\$@Mauris Regarding your comment about the implementation needing to instantiate the entire torus with spaces, would this affect the byte count for my code presented? I only counted the necessary characters rather than filling in the corners with spaces.\$\endgroup\$CommentedJul 14, 2015 at 8:16
2
\$\begingroup\$

C,78 75 bytes

x(y){return y+48+y/10*7;}f(j){for(j=0;printf("%c%c ",x(j/16),x(15&j++)););}

We define a functionf() to be called with no arguments for printing, and a helper functionx(int). This breaks atFF.

Amazingly, this is one byte shorter than the more obvious:

char*s="0123456789ABCDEF";h(j){for(j=0;printf("%c%c ",s[j/16],s[15&j++]););}

Warning: it is not recommended to run this code outside of a debug environment...

Testing:

int main(int argc, char** argv) {    f();    return 0;}

Output:

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 (...)

Of course, the more robust (and cheat-y) approach is this 34-byte function:

g(i){for(i=0;printf("%x ",i++););}
answeredJul 12, 2015 at 17:08
BrainSteel's user avatar
\$\endgroup\$
3
  • 1
    \$\begingroup\$Started trying this but my answer was too similar. You can save several bytes by making the first %c into %d and omitting the function. It's only valid up to 9F then though.\$\endgroup\$CommentedJul 14, 2015 at 15:25
  • \$\begingroup\$return y+ could possibly bey+=.\$\endgroup\$CommentedAug 19, 2018 at 4:25
  • \$\begingroup\$67 bytes\$\endgroup\$CommentedNov 15, 2024 at 14:43
2
\$\begingroup\$

Pyth, 17 bytes

VJs++kUT<G6FYJ+NY

Try it here

How it works:

         <G6         # "abcdef"       UT            # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]      k              # an empty string (so + means concatenation, not addition)   s++               # join them all ("0123456789abcdef")  J                  # call this J V                   # for each N in J...            FYJ      # for each Y in J...               +NY   # print N and Y
answeredJul 12, 2015 at 18:05
Ypnypn's user avatar
\$\endgroup\$
1
  • \$\begingroup\$jb^+jkUT<G6 2 uses the cartesian product to do the same thing, still seems golfable...\$\endgroup\$CommentedJul 12, 2015 at 19:42
2
\$\begingroup\$

Javascript ES6,67 62 bytes

(x=''.replace.bind('0123456789ABCDEF',/./g))(n=>x(o=>' '+n+o))
answeredJul 12, 2015 at 19:05
George Reith's user avatar
\$\endgroup\$
2
\$\begingroup\$

J, 22 bytes

>{;~'0123456789abcdef'

Counts toff. Prints an extra newline between each block of0x10 numbers, like so:

...0d0e0f1011...
answeredJul 14, 2015 at 14:23
lynn's user avatar
\$\endgroup\$
2
\$\begingroup\$

Mumps - 65 bytes

S Q="0123456789ABCDEF" F I=1:1:16 F J=1:1:16 W $E(Q,I),$E(Q,J),!

Nope... Mumps ain't dead yet! :-)

answeredJul 15, 2015 at 12:47
zmerch's user avatar
\$\endgroup\$
2
\$\begingroup\$

CJam, 22 bytes

1{_GbA,6,'af++f=oNo)}h

This runs forever, and thus is probably one of the rare times where it's a good ideanot to include a permalink.

answeredJul 12, 2015 at 16:46
Sp3000's user avatar
\$\endgroup\$
1
  • \$\begingroup\$oNo is the same asn in TIO.\$\endgroup\$CommentedApr 27, 2017 at 19:01
2
\$\begingroup\$

TheC64Mini and Commodore BASIC (C64/128, PET, VIC-20, C16/+4) - 164 BASIC and Tokenized bytes used

 0 fOd=.to255:n=d:fOi=1to.stE-1:h%(i)=n/(16^i):n=n-(h%(i)*(16^i)):nEi:h$="" 1 fOi=1to.stE-1:ifh%(i)<10tHh$=h$+cH(48+h%(i)) 2 ifh%(i)>9tHh$=h$+cH(55+h%(i)) 3 nEi:?h$"  ";:nEd

Prints a double-space after the hex number to nicely align the printing at 40/80 columns as well as the 22 columns on the VIC-20.

Commodore Plus/4 Hex counter innit

answeredAug 12, 2019 at 13:12
Shaun Bebbers's user avatar
\$\endgroup\$
2
  • 1
    \$\begingroup\$85 bytes\$\endgroup\$CommentedNov 15, 2024 at 15:42
  • \$\begingroup\$@jdt very nice, good work.\$\endgroup\$CommentedNov 16, 2024 at 20:54
2
\$\begingroup\$

Malbolge, 900 bytes

To be improved...

D'``@"\7}|X9E1gwuR21=p(:9%IZYEg}eA/ya>O_)([Zvotm3qponmfN+Lbg`ed]\"CB^W\Uy<;WVONSLp3ONMLEDhH*)?>b%A@?87[;:9876/S3,P0/.-&J$)"'~D|{"y?}|utyr8potmrqpi/mfN+Lbg`e^$bDZ_^]VzZSXQVUTSLp3ONMLEDhH*)EDCB;@?8\6|:32V6v.32+O)o'&J*)i'&%|Bcb~w|u;yxwvutVrkj0nmfN+iKg`_%cE[`Y}@V[ZYXWPtT6LKJImM/KJIBAe(D=<A:98\[;{32V6v.-,P0).',%I)"!E%|#"y?w_{ts9Zvutsrkpi/mfNjihg`e^$b[Z~X]\[ZYRv98TSLKoO10FKDh+GFE>CB;_?>=}|49870/.R2+*Non&%I#"!&%${A!~}_u;yxqpo5mrqpoh.lkdibgf_%]\[!_XW{[ZYXQPt7SRQPOHGkKJIHAF?cC<;@?8\6;492V6v.-,P*p.'K+$j"'~D|#"y~wv<]yxqvutsrk1onmfN+cba`&d]#DZ_^]VzTSXQVOs65QJINGkE-IBAe(D=<A:98\654981Uv.32+*)M-,%k#(!E}$#"!x>v{t:xwputm3kpoh.fN+Lbg`ed]\"!Y^]VzZYXQVOsS54JImMFKJIHAe?>C<`@?87[;{32V05.-2+O)o-,+$H('&}Cdzy~wv<]sxqvonm3k1oQmf,jihgfeG]#a`_X|V[TxXQPUTMLp3ONMLEDhH*)ED=a;@?>76;4X816/43,P*).',%I#i!&}|Bcb~w|u;yxwputm3qSong-kjihgfH%]\a`_XW{UTYXQuUTMRKPOHlFKDhBAe?>=B;_9>=6Z:981Uv.32+*)M-,%k#(!E%$#c!x>|u;yxZpo5srqSi/z

Try it online!

answeredAug 12, 2019 at 13:48
Kamila Szewczyk's user avatar
\$\endgroup\$
2
\$\begingroup\$

brainfuck, 2902 bytes

Easy to outgolf, but worth giving a shot

+>+[<[>>+>+<<<-]>>[<<+>>-]>[[-]>>>>>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<<<[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[>+<<+>-]<[>+<-]<]>+<<+<<[>>->+<<<-]>>>[<<<+>>>-]<[->+<<[>>>-<<+<-]>[<+>-]>>[<->[-]]<[<<<+>>>-]<]>>[-]<<<<[>>+>+<<<-]>>[<<+>>-]>[[-]>>.>.>>>++++++++++++++++++++++++++++++++.[-]<<[-]<<[>>+<<<+>-]<[>+<-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[>>>-<<+<-]>[<+>-]>>[<->[-]]<[<<<+>>>-]<]>>[-]<<<<[>>+>+<<<-]>>[<<+>>-]>[[-]>>>>[-]<[>+<<<+>>-]<<[>>+<<-]>>>[<<<<+>>>>-]+>[<<<<<-<+>>>>>>-]<<<<<<[>>>>>>+<<<<<<-]>[>>>>-<<<<[-]]>>>>>>++++++<<<<<<+>>>>[<<<<[-]<+>>>>>-]<<<<<[>>>>>+<<<<<-]>[<<<[-]>[-]>>>>>>>>[<<<<<<<<+>+>>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>[-]]>>>>>>[-]<<<<<<]<<<[>>+>+<<<-]>>[<<+>>-]>[[-]<<<[-]>[-]>>]<<]

Try it online!

answeredAug 12, 2019 at 14:08
Kamila Szewczyk's user avatar
\$\endgroup\$
2
  • \$\begingroup\$This would be shorter if you just generated the characters0-F and then hardcoded the printing. How did you manage to make it so long?\$\endgroup\$CommentedAug 13, 2019 at 3:40
  • \$\begingroup\$@JoKing possibly, but I just wanted to have fun\$\endgroup\$CommentedAug 13, 2019 at 9:47
2
\$\begingroup\$

PowerShell 6, 40 bytes

($l=0..9+'A'..'F')|%{$1=$_;$l|%{"$1$_"}}

Try it online!

Starts at00 and counts up toFF.

answeredAug 13, 2019 at 14:24
mazzy's user avatar
\$\endgroup\$
2
\$\begingroup\$

MUMPS, 57 bytes

f i=1:1:48 w $tr(i\16,0),$e("0123456789abcdef",i#16+1),!

Output

>d ^xmsdgolf123456789abcdef1011..28292a2b2c2d2e2f30

Explanation

f i=1:1:48                     ; loop from 1 to 48w $tr(i\16,0)                  ; print i div 16, and ditch any zeros$e("0123456789abcdef",i#16+1)  ; extract the nth character from the string, where n is i mod 16 + 1!                              ; crlf
answeredFeb 27, 2020 at 6:00
Michael Donnelly's user avatar
\$\endgroup\$
2
\$\begingroup\$

AWK, 70 bytes

END{for(;i++<split("0123456789abcdef",a,X);)for(j in a)print a[i]a[j]}

Try it online!

31 bytes, probably against rules

END{for(;i++<48;)printf"%X ",i}

Try it online!

answeredNov 15, 2024 at 18:14
xrs's user avatar
\$\endgroup\$
1
\$\begingroup\$

Python 2,66 55 Bytes

This should really have been the most obvious approach to me..

a='0123456789ABCDEF'for x in a: for y in a:print x+y

Old (66 Bytes): Technically this causes an error afterFF, but it does reach30.

n=1;a='0123456789ABCDEF'while 1:print a[n/16]*(n>15)+a[n%16];n+=1

I assumed string formatting wasn't allowed since I'm pretty sure it would go through base conversion, but if it was allowed, this would be 29 bytes:

n=1while 1:print"%x"%n;n+=1
answeredJul 12, 2015 at 17:16
Kade's user avatar
\$\endgroup\$
1
\$\begingroup\$

Java, 104 bytes

char t[]="0123456789abcdef".toCharArray(),i;void f(){for(;i<99;)System.out.println(""+t[i/16]+t[i++%16]);}

If thei<99 is removed, it still reaches 30, but eventually crashes. I'm not sure if that's acceptable.

answeredJul 12, 2015 at 20:34
Ypnypn's user avatar
\$\endgroup\$
1
\$\begingroup\$

J, 47 bytes

'0123456789abcdef'{~([:|:2 256$(]#i.),256$i.)16

prints 00 to ff

answeredJul 13, 2015 at 12:01
gar's user avatar
\$\endgroup\$
2
  • 1
    \$\begingroup\$A much shorter way:>{;~'0123456789abcdef'\$\endgroup\$CommentedJul 13, 2015 at 16:43
  • \$\begingroup\$Wow, that's very good! But why didn't you post it as an answer, it's only 22 bytes!\$\endgroup\$CommentedJul 14, 2015 at 14:17
1
\$\begingroup\$

JavaScript747265 60

//for(i=0,a="0123456789ABCDEF";i++<49;)console.log(a[i>>4]+a[i%16])for(i=0;i++<48;)console.log((i>>4)+"0123456789ABCDEF"[i%16])

answeredJul 13, 2015 at 16:15
wolfhammer's user avatar
\$\endgroup\$
1
\$\begingroup\$

Perl 6, 34 bytes

The shortest that I can come up with that doesn't use any sort of conversion is:

put [X~] (|(0..9),|('A'..'F'))xx 2 # 34 bytes

prints00 ...FF space separated in order.
If you want more you can swap2 for a larger number.
(don't use a number bigger than 4 as it concatenates the values together before outputting anything, so it would use a significant amount of RAM )


Shortest that will never stop writing hex values

put [R~] (|(0..9),|('A'..'F'))[.polymod: 16 xx*]for 0..* # 56 bytes

Ifprintf were allowed

printf "%X ",$_ for 0..* # 24 bytes

If a base conversion function were allowed

put .base(16)for 0..* # 21 bytes
answeredJan 17, 2016 at 15:51
Brad Gilbert b2gills's user avatar
\$\endgroup\$
1
\$\begingroup\$

Matlab: 47 bytes

q=[48:57,97:102,''];fliplr(char(combvec(q,q)'))

I don't know if it would be considered as counter. The code generates vector of hex numbers from00 toff.q is a string'0123456789abcdef' indouble format. Combvec generates all possible pairs betweenq andq. Char converts it to string format andfliplr flips the columns to get:

0001...08090a0b0c0d0e0f1011...fdfeff
answeredJan 17, 2016 at 17:29
brainkz's user avatar
\$\endgroup\$
1
\$\begingroup\$

C++14 - 135

#include<string>#include<iostream>void f(){std::string a="0123",b="0123456789ABCDEF";for(char c:a)for(char d:b)std::cout<<c<<d<<" ";}
answeredJan 17, 2016 at 18:55
Yytsi's user avatar
\$\endgroup\$
3
  • \$\begingroup\$No, it's fine like it is. What compiler are you using? I get'string' is not a member of 'std' with mine.\$\endgroup\$CommentedJan 17, 2016 at 19:11
  • \$\begingroup\$@Dennis That's a good point. I always forget that it requires including string as it's own. Fixed.\$\endgroup\$CommentedJan 17, 2016 at 19:28
  • \$\begingroup\$1. I'm getting the same error forcout as well. I guess you neediostream too. 2. It prints the numbers without separation. The challenge requires spaces, tabs or newlines. 3. You should mention the required version of C++.\$\endgroup\$CommentedJan 17, 2016 at 22:11
1
\$\begingroup\$

jq 1.5:65 59 characters

(56 characters code + 3 characters command line option.)

[range(10)]+"a b c d e f"/" "|{a:.[],b:.}|"\(.a)\(.b[])"

Sample run:

bash-4.3$ jq -n -r '[range(10)]+"a b c d e f"/" "|{a:.[],b:.}|"\(.a)\(.b[])"' | head00010203040506070809

On-line test (Passing-r through URL is not supported – check Raw Output yourself.)

jq 1.5: 56 characters

(53 characters code + 3 characters command line option.)

[[range(10)]+"a b c d e f"/" "|"\(.[])\(.[])"]|sort[]

This produces correct output, however is not exactly a counter: it not generates the values in order, just sorts them after.

On-line test (Passing-r through URL is not supported – check Raw Output yourself.)

answeredJul 13, 2015 at 17:20
manatwork's user avatar
\$\endgroup\$
2
  • \$\begingroup\$your link for jq doesn't work, and when I fixed it it says there isn't an index file on github :P\$\endgroup\$CommentedJul 13, 2015 at 17:24
  • \$\begingroup\$Oops. Thank you @Phase. I was too concentrated on the character count.\$\endgroup\$CommentedJul 13, 2015 at 17:29
1
\$\begingroup\$

Dyalog APL, 12 bytes

       ∘.,⍨16↑⎕D,⎕A 00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E  0F  10  11  12  13  14  15  16  17  18  19  1A  1B  1C  1D  1E  1F  20  21  22  23  24  25  26  27  28  29  2A  2B  2C  2D  2E  2F  30  31  32  33  34  35  36  37  38  39  3A  3B  3C  3D  3E  3F  40  41  42  43  44  45  46  47  48  49  4A  4B  4C  4D  4E  4F  50  51  52  53  54  55  56  57  58  59  5A  5B  5C  5D  5E  5F  60  61  62  63  64  65  66  67  68  69  6A  6B  6C  6D  6E  6F  70  71  72  73  74  75  76  77  78  79  7A  7B  7C  7D  7E  7F  80  81  82  83  84  85  86  87  88  89  8A  8B  8C  8D  8E  8F  90  91  92  93  94  95  96  97  98  99  9A  9B  9C  9D  9E  9F  A0  A1  A2  A3  A4  A5  A6  A7  A8  A9  AA  AB  AC  AD  AE  AF  B0  B1  B2  B3  B4  B5  B6  B7  B8  B9  BA  BB  BC  BD  BE  BF  C0  C1  C2  C3  C4  C5  C6  C7  C8  C9  CA  CB  CC  CD  CE  CF  D0  D1  D2  D3  D4  D5  D6  D7  D8  D9  DA  DB  DC  DD  DE  DF  E0  E1  E2  E3  E4  E5  E6  E7  E8  E9  EA  EB  EC  ED  EE  EF  F0  F1  F2  F3  F4  F5  F6  F7  F8  F9  FA  FB  FC  FD  FE  FF
answeredSep 3, 2015 at 13:29
Adám's user avatar
\$\endgroup\$
1
  • \$\begingroup\$For once, APL matches Pyth.\$\endgroup\$CommentedSep 3, 2015 at 13:34
1
\$\begingroup\$

Ruby, 64 bytes

h='0123456789abcdef'.split //;h.each{|i|h.each{|j|print i,j,?\s}}

Explanation:

h = '0123456789abcdef'.split // # Split string of hex chars at                                # matches of //, returns array                                # splits array by characters h.each { |i|                    # loop 1  h.each { |j|                  # loop 2    print i,j,?\s               # print() can take multiple params,                                # and it is the same as printing                                # each one using a separate print().                                # ?x is the same as 'x', so ?\s is                                # the same as "\s", which is " ".  }}
answeredJul 16, 2015 at 6:48
clapp's user avatar
\$\endgroup\$
0
1
\$\begingroup\$

Zsh,44 29 bytes

-15, via GammaFunction  try it online!

h=({0..9} {a..f});echo $^h$^h

Original (44 bytes):g=0123456789abcdef;h=(${(s::)g});echo $^h$^h

answeredAug 13, 2019 at 2:40
roblogic's user avatar
\$\endgroup\$
2
  • 1
    \$\begingroup\$Instead of converting to array, you can start there:h=({0..9} {a..f}).29 bytes\$\endgroup\$CommentedAug 13, 2019 at 3:21
  • \$\begingroup\$Thanks! zsh is very golfable :)\$\endgroup\$CommentedAug 13, 2019 at 3:53

Your Answer

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.