20
1
Code Golf Measurer © 2019
Hexdumps used with xxd
look something like this:
00000000: 666f 6f20 6261 7220 7370 616d 2065 6767 foo bar spam egg
00000010: 730a s.
Your task is to convert a hexdump in this form in to the number of bytes used.
Rules:
- Usual loopholes forbidden.
- This is code-golf, so shortest valid answer in bytes wins.
- You may or may not include the newline at the end of text (
0a
). This means that if the hexdump ends in a newline (0a
), that input may have it's output reduced by one. - An empty input (literally nothing: empty list/string/etc.) must output 0.
- Input can be taken in any form
- Input will be valid ASCII with no control characters
- The input must contain the whole hexdump
Test cases:
00000000: 4865 6c6c 6f2c 2077 6f72 6c64 2120 4865 Hello, world! He
00000010: 6c6c 6f2c 2077 6f72 6c64 210a llo, world!.
returns 28 or 27
00000000: 0a .
returns 1 or 0
00000000: 6368 616c 6c65 6e67 650a challenge.
returns 10 or 9
00000000: 4865 6c6c 6f2c 2077 6f72 6c64 21 Hello, world!
returns 13
returns 0 (This is literally nothing: empty list/string/etc.)
Explanations would be nice for non-standard languages.
May we assume the input is ascii? Can it contain control characters? What are the input rules? Some languages can't handle input over multiple lines. Can we pad the last line so that all lines are equally long? Why include the blank input? – Stewie Griffin – 2019-10-07T17:03:08.467
@StewieGriffin Yes; no; yes; because if
xxd
is fed an empty string, it outputs nothing. – gadzooks02 – 2019-10-07T17:05:57.8831@StewieGriffin You edited your comment while I was answering, so here's an expansion: Yes; No; it can be input however you want, provided the whole dump is included; See last answer; Yes; Because if xxd is fed an empty string, it outputs nothing – gadzooks02 – 2019-10-07T17:24:47.497
1@JonathanAllan Oh yes, well spotted. – gadzooks02 – 2019-10-07T17:41:12.277
1Counting a hexdump format that didn't include the ASCIIfied data at the right might be interesting. Everyone's going with just stripping the hex part and byte-counting the rest. If the challenge was to do this given only the last line of hexdump, that would force parsing the hex number (the position) as well as counting the number of hex digits on that line. (Like I do by hand when looking at
objdump
disassembly ornasm
listings for machine-code answers.) I guess I should post that in the sandbox... – Peter Cordes – 2019-10-08T18:29:25.450@PeterCordes Interesting idea! When you do, link it here; I'd definitely upvote it :). – gadzooks02 – 2019-10-08T18:34:24.743
May I assume the xxd dump use UNIX style line ending (LF)? An Windows version
xxd
(xxd V1.10 27oct98 by Juergen Weigert (Win32)
, comes with Vim) does output with CRLF line endings. – tsh – 2019-10-10T06:41:00.833@tsh Any consistent specification. (So yes, but it could be either) – gadzooks02 – 2019-10-10T16:06:38.763