# Can you give me half? (No digits) [closed]

The task is to provide code that evaluates to 0.5 numerically, i.e. the output must be recognized by your chosen language as a numeric value (Number, float, double, etc), not as a string. The catch, the characters 0 through to 9 cannot be used.

PLEASE NOTE: This IS NOT a golfing challenge, this is a popularity contest, so creative answers are encouraged. The more obscure and convoluted answers are also encouraged.

One example that fits the brief would be the following:

((++[[]][[~~""]]<<++[[]][[~~""]]))**((--[[]][[~~""]])) which works out to 0.5 in JavaScript.

A bounty of 150 will be awarded as an added incentive for the most voted creative answer. Good luck!

Any questions, feel free to ask.

• TBH, @AviFS it surprises me that people forget there are more different categories of challenges than just code golf... I want my fellow golfers to embrace their inner goofball and provide more esoteric and convoluted answers based on their language of choice... And there was an objective, output half without numeric digits... ;) Jun 21, 2021 at 9:22
• It's not that the challenge is not code golf, it's that it's the blandest, most generic kind of popularity contest -- a trivial task where we're asked to be creative with "obscure and convoluted answers". At that point all pop cons might as be merged into one challenge that says "write whatever you want, upvote every answer".
– xnor
Jun 21, 2021 at 10:08
• @WheatWizard I haven't seen a challenge get 40 answers the day-of in a long time. I wonder if we're not missing pretty clear signs that this is the way to ramp up engagement. It's certainly more inviting, and the barrier to entry is less rigid. Perhaps we're elitists in our ivory towers to be demanding objectivity & strictly defined winners everywhere we go. Jun 21, 2021 at 10:23
• @AviFS 40 answers in a day is not a good sign. In fact it is a very bad sign. Jun 21, 2021 at 10:26
• Code trolling also caused a massive spike of activity back in 2014 @AviFS, that doesn't mean they were quality questions. More answers doesn't not equal a quality question. Pop-cons have been a controversial topic for years, but it is possible to run a pop-con that isn't just "Do this but creatively" Jun 21, 2021 at 10:28

# Desmos, 23 bytes


\frac{\{\}}{\{\}+\{\}}


(newline is required)

Looks crazy, but it really isn't once you figure out that \{\} is just 1.

The actual crazy part is that it doesn't render properly on Desmos, though it still outputs 0.5.

Try It On Desmos!

• Using forward slash: ¶\{\}/(\{\}+\{\}) (¶ is newline) Jun 21, 2021 at 6:30
• @fireflame241 Yes, I know that works, but I wanted to have more brackets in the code to make it look more crazy :P. Jun 21, 2021 at 6:46
• Oh it's a pop-con. Forgot to read the question, oh well. Jun 21, 2021 at 6:47

# RAMDISP, 19 bytes

[P[[[[]]][/[[]]];]]


RAMDISP is my own programming language, but i made it before this challenge, so i think it's allowed. [i also had to fix a bug i left in it, which i only found after trying to do this challenge]

explanation:

[P - pipes through the following array
[
[[[]]] - the value 2.
[/ - divide
[[]] - the value 1.
] - by the incoming number.
; - print the result
]
]


# Python 3, 25 bytes

print(len("l")/len("pr"))


Try it online!

Short, sweet, and with only 11 distinct bytes too.

• Taking advantage of the fact that int() returns 0, you can get 9 distinct bytes: print(~int()/~(~int()//~int())) Feb 8 at 12:25
• You can also get 18 bytes total, but it's not very interesting imo: print(-True/~True) Feb 8 at 12:26

# Charcoal, 57 bytes

Ｉ⁻Ｌα⊘Ｌ


• Interesting, though as I said, this isn't code golf, so whether you golf it down isn't the point... :) Jun 21, 2021 at 2:38
• @EliseoD'Annunzio Sorry, I'm so used to code golf...
– Neil
Jun 21, 2021 at 8:11
• No worries, I'm trying to come up with a doozy of a gold challenge over the next week or so. Watch this space. Jun 21, 2021 at 8:12
• @EliseoD'Annunzio Is this better?
– Neil
Jun 21, 2021 at 9:26
• I just "tried it online!" You got me... Really? XD Sep 11, 2021 at 2:20

# 05AB1E, 18 bytes

тT*;тT*·<ŸтT*/ΩΔ;t


Try it online!

Choose a random float in $$\[0.5, 2)\$$, and iterate $$\x\mapsto \sqrt{x \over 2}\$$ until convergence.

In theory the iteration converges to $$\0.5\$$ for all positive real numbers, but there might be floating point issues leading to results close to $$\0.5\$$.

# 05AB1E, 7 bytes

XΔNÌoz-


Try it online!

$$1-\sum^\infty_{k=2}{1 \over 2^k} = 1-{1 \over 2} = {1 \over 2}$$

X        # start at 1
Δ       # until the result doesn't change:
NÌ     #   iteration index N + 2
o    #   2 ** (N+2)
z   #   1 / 2**(N+2)
-  #   subtract this from the current value

• Estimating the sum with the first 100 terms would be enough with the floating point precision: тL>ozO
– ovs
Jun 21, 2021 at 9:03
• True, most languages tend to hit underflow by that number of iterations... Jun 21, 2021 at 9:44

## <>^v

≈:) :) :) :) :( :( :( )≈)?/;

≈    Duplicate top of stack (by default stack is [0])
then the :) and :( do nothing, because : executes only the next characted if the top two elements of the stack are not equal, so it skips over the parentheses.

) Increment top of stack -> stack is now [0, 1]
≈ Duplicate top of stack -> stack is now [0, 1, 1]
) Increment top of stack -> stack is now [0, 1, 2]
? Reverse stack -> stack is now [0, 2, 1]
/ Set top of stack to top of stack / second element of stack -> stack is now [0, 1, 0.5]
; Print top of stack


run online

• Not sure why, but looking at this code makes me smile.
Jun 24, 2021 at 13:08

# Barrel, 2 bytes

½


Evaluates to, and prints, 0.5. Not necessarily terribly imaginative, but probably one of the best solutions to this problem in Barrel.

# R, 57 bytes

function(+=function(x)as.double(as.roman(x)))+'I'/+'II'


Try it online!

As odd as it may sound, R has a partial support for Roman numerals.

So, in this code we:

• abuse the plus sign by turning it into a function accepting Roman numerals strings and returning the numeric value
• we aesthetically compute +I / +II (we actually calculate 1 / 2 because the abused plus sign act as a roman-to-double parser)
• then we return the result

# Red, 82 bytes

print divide length? next system/locale/days to-float length? system/locale/months


Try it online!

Divides the number of days in a week minus one to the number of months. The current Red built doesn't need to-float.

# R, 82 bytes

function()round(mean(runif(sqrt(exp(exp(pi)))) - rnorm(sqrt(exp(exp(pi))))),pi/pi)


Try it online!

Generates the mean of ($$\\sqrt{e ^ {e ^ \pi}}\$$ random uniform numbers in the range (0, 1) minus $$\\sqrt{e ^ {e ^ \pi}}\$$ random numbers from a normal distribution with mean 0 and standard deviation 1) and rounds it to 1 decimal place.

• characters 0-9 cannot be used. thats the whole point of the challenge
– user100752
Jun 21, 2021 at 7:00
• @EliteDaMyth oops fixed now Jun 21, 2021 at 7:19

# ZX Spectrum Basic, 8 bytes

PRINT SGN PI/INT EXP SGN PI

This is actually a well-known compression technique for numeric constants. Plain PRINT 0.5 would require 10 bytes (1 byte for the PRINT keyword, 3 bytes for the ASCII string 0.5, 6 bytes for the float constant)

• Which would be great if we were voting on bytes. This is a code popularity contest, not a code golf challenge. Jun 21, 2021 at 9:20
• @EliseoD'Annunzio Yes, I know. However, I consider my answer not too bad - in particular, because I independently "discovered" the SGN PI expression decades ago, when most programs I saw used PI/PI. And it is somewhat elegant as well. Jun 21, 2021 at 10:47

# Vyxal

\/C⌐\\C/-


#### Explanation:

\/C          . gets the codepoint of /
⌐         . 1 - x
\\C      . gets the codepoint of \
/     . division (to get -0.5)
-    . subtract from implicit 0


Try it Online!

# C# (Visual C# Interactive Compiler), 30 bytes

Console.Write('$'/(float)'H');  Try it online! Division of Ascii Codes: '$' = 36, 'H'(alf) = 72

# Python 3, 203 bytes

((True+True)*(True+True+True)**(True+True+True+True)*(True+True+True+True+True)/(True+True+True+True)-(True+True)**(True+True+True)*(True+True+True+True+True)**(True+True))/((True+True)*(True+True)+True)


Heh.

• This is invalid as it's a code snippet, not a full program or function Sep 10, 2021 at 22:18

# Python 3

len('check')/len('check-mate')
# Output: 0.5

• NICE!!! Definitely creative. The only one so far to use string manipulation to arrive at the result. Jun 21, 2021 at 23:17
• This is invalid as it's a code snippet, not a full program or function Sep 10, 2021 at 22:18

# Ruby, 27 bytes

->{($.**=$.).to_f/($.<<$.)}


Try it online!

Using the variable $. which is initially set to zero, and the interesting property 0⁰==1. # Python 3, 14 bytes d=True;d/(d+d)  True is basically just 1 in Python, so this is basically just 1/(1+1)  which obviously evaluates to 0.5. • Welcome to the site! Your program should output the value, so you should include print(..) in your answer Jun 21, 2021 at 17:23 # JavaScript (Node.js), 61 bytes ~[] / ~~(Math[SQRT${-~-~[]}] * Math[SQRT\${-~-~[]}]) * ~[]


Try it online!

The ~~ just before the Math.SQRT2 multiplication is needed because Math.SQRT2 * Math.SQRT2 = 2.0000000000000004.

# Python 3

Not very creative but ehh

ord('!')/ord('B')


edit: as pointed out by EasyasPi (thanks), doesn't work for python 2

• Python 2 would do integer division here. Jun 21, 2021 at 3:19
• Python 0.66667?
Jun 21, 2021 at 8:34

# Dyalog APL, 5 bytes

÷⌊*≡⍬


Not very creative, but golfy! Try it online.

÷       Inverse              ->   1/2
⌊       Floor                ->   2
*       Exponent [1]         ->   2.71828
≡       Depth                ->   1
⍬       Empty list           ->   []

[1]: Default base is e, so e^1

• It sure is. Thanks @Sisyphus! Jun 21, 2021 at 7:28
• Inverse of log natural to int... I'd say that's pretty creative. Clever, at the very least! Jun 21, 2021 at 23:23
• Or that isnt it, is it? Your solution uses e. Muh bad. Make way, noob stumbling through. XD Jun 21, 2021 at 23:29
• @NateT Thanks! I was actually outgolfed though by Adám, although it's less interesting: ÷≢⍬⍬. But it means this is neither as golfy, nor as creative, as it could be. This post can't really decide what it wants to be! Jun 21, 2021 at 23:31
• Haha, no worries! Any attention (read validation) is good attention : ) Jun 21, 2021 at 23:31

# JAVA

As a simple java project. I haven't looked at the others, so it is entirely possible (and likely) that this is the umpteenth answer to contain this solution. This code, placed inside src/Run.java of a fresh project, will return o.5.

The actual algorithm is only 2 (sorry, two XD) lines; The rest is just getting it to print. I know you asked for whimsical, but I was impressed with the simplicity of this, so I used it, for better or worse....

This algorithm takes advantage of the fact that any number, when divided by (itself plus itself) will give one half.

public class Run {

public static void main(String[] args) {
double x = Math.random();
double y = x/(x+x);
System.out.println(y);

}


}

Btw, Im not sure how to do the giant text in md, so I just used a title hash. Ill be back to fix once I figure it out.

EDIT: Although I guess using java for this two line solution is a bit whimsical! LOL

• This is invalid, the code throws a syntax error; If that is fixed Math.random can output 0, throwing an error. Sep 10, 2021 at 22:15
• @emanresu Didnt realize it needed to be fail proof. I was going on the impression that this was more of a "battle of the concepts" type of thing. I wrote this in about 45 seconds just as a way to have fun and blow off steam. didn't realize we were giving points for "most robust." I'll fix it though. Which IDE threw the syntax error. I believe I compiled in STS 4.7? I won't use Intellij products. anything else and I'll pull it up. What is the error? Sep 11, 2021 at 1:28
• The { after public class Run is unmatched, and Math.random can return 0, meaning that you get (0+0)/0. Sep 11, 2021 at 1:34
• @emanresu The { was a copy paste error, and as far as the divide by zero error, I believe that is why I put it as a double.. When run, x goes 12 digits past the decimal point (0.000000000001 precision). Yes, if all 12 of those digits end up zeroes, then it will error out, so I added the if block just in case. Just for you. Sep 11, 2021 at 1:48
• You still have to have it completely deterministic. You could use something like 'a'.length() or similar. Please test this, as I don't know Java very well. Sep 11, 2021 at 1:59

# JavaScript

t=true;
console.log((t) / ((t) ^ (t + t) ^ (t)) ** (t));


JavaScript works well, here is a simple numerically deficient example getting you the half or it.