23

3

This challenge is brought to you by real (and tragic) inspiration. Recently, the number row on my keyboard has been a bit sporadic. The keys `1-9`

work sometimes--but other times they have no result. As an avid programmer, this is horrible! (See that exclamation point? That's how you know they're working right now.) Not only do I often need the numbers themselves, but the symbols `!@#$%^&*(`

are completely ineffective half the time as well! As a C programmer, rather than take time off my busy schedule of doodling around with code to fix my laptop, I've been more interested in working around the problem. Over the course of the past few weeks, slowly, all of the number literals in my code have been replaced with hexadecimal so that I don't have to go hunting around for numbers to copy and paste. However, some numbers aren't easy to type without the keys `1-9`

. For example, the number `1`

cannot be written so simply in hexadecimal, and I've resorted to replacing `1`

s in my code with `0xF - 0xE`

. The only keys that are affected are `1-9`

, so I maintain full use of symbols like `+`

, `-`

, and `/`

. However, I cannot use multiplication or parentheses, as `*`

and `(`

are often broken. This leads to your challenge.

# Input

An integer, `n`

to stdin or your language's equivalent. If you wish, the integer may be preceded or followed by a new line or other whitespace character. Alternatively, you may receive input via a command line argument.

Your program should respond to negative input correctly, and be able to handle at least 32-bit signed integers.

# Output

Your program should output, in some observable form, the shortest (in non-whitespace characters) possible way to write the number `n`

as a sum, difference, or division of one or more hexadecimal values. There is more than one way to solve this problem, and there is no requirement that you favor any equal-length output over any other.

The output should be in the form `A % A % A...`

where `A`

is a hexadecimal value following `0x`

containing only digits `A-F a-f`

, and `%`

is one of of the symbols `-+/`

. Let `/`

describe integer division, not floating-point.

(Note that your output should result in `n`

when evaluating divisions first, left to right, and then additions and subtractions, left to right, as is convention.)

# Test Cases

Input Output

`1`

`0xF - 0xE`

(or`0xF-0xE`

or`0xB-0xA`

or`0xd - 0xc`

or`0xF/0xF`

)`15`

`0xF`

`255`

`0xFF`

`30`

`0xF + 0xF`

# Scoring and Rules

This is code-golf. Your preliminary score is the number of bytes in your source file.

You may NOT use any of the digits `1-9`

in your source.

You MAY use symbols `!@#$%^&*(`

in your source, but each comes at a penalty of +20 to your score.

Your program may be replaced by a function that takes `n`

as an argument as long as that function produces some form of human-readable output. Your function's return value does NOT count as output.

Standard loopholes are not allowed.

Lowest score wins! Good luck!

*Did I goof something up formatting/questioning/clarity-wise? Let me know! This is my first submission to this site!*

Is there an upper limit to the size of the integer? Also, will negative numbers be represented to some arbitrary precision (i.e. 32 bit)? – FryAmTheEggman – 2015-02-21T02:29:02.117

@FryAmTheEggman Edited the original post to clarify. Input may be negative, and your program should respond correctly to at least 32 bit input. Thanks! – BrainSteel – 2015-02-21T03:41:45.837

Related: http://codegolf.stackexchange.com/a/32114/21348

– edc65 – 2015-02-21T09:28:19.870This looks like a pretty solid spec to me, but if you'd like some feedback, I'd recommend posting it in the sandbox (for future challenges) so you can get feedback

– Martin Ender – 2015-02-21T10:10:03.057beforeyou post it on main and people start working on it.1Integer or floating point division? – edc65 – 2015-02-21T10:30:49.053

@edc65 Since the syntax of the output is largely based on C, I'll edit the post to specify integer division. – BrainSteel – 2015-02-21T16:47:21.693

@Martin Büttner Yes, functions will be allowed, but output cannot be in the form of a "return" or similar. Output must be to stdout, or another readable format. – BrainSteel – 2015-02-21T16:48:16.020