18
\$\begingroup\$

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.

\$\endgroup\$
11
  • 4
    \$\begingroup\$ 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... ;) \$\endgroup\$ Jun 21, 2021 at 9:22
  • 11
    \$\begingroup\$ 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". \$\endgroup\$
    – xnor
    Jun 21, 2021 at 10:08
  • 12
    \$\begingroup\$ @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. \$\endgroup\$
    – AviFS
    Jun 21, 2021 at 10:23
  • 6
    \$\begingroup\$ @AviFS 40 answers in a day is not a good sign. In fact it is a very bad sign. \$\endgroup\$
    – Wheat Wizard
    Jun 21, 2021 at 10:26
  • 9
    \$\begingroup\$ 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" \$\endgroup\$ Jun 21, 2021 at 10:28

52 Answers 52

50
\$\begingroup\$

Jelly, 177 bytes

Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.

Try it online!

Explanation thanks to caird coinheringaahing.

Never gonna give you up,                Helper Link; never called
Never gonna let you down,               Helper Link; never called
Never gonna run around and desert you.  Helper Link; never called
Never gonna make you cry,               Helper Link; never called
Never gonna say goodbye,                Helper Link; never called
Never gonna tell a lie and hurt you.    Main Link
Never gonna tell a lie and hurt yo      Random stuff that doesn't matter
                                  u     Undefined so everything before it gets trashed
                                   .    0.5

... yeah. Not that exciting when you see how it works.

\$\endgroup\$
9
  • 3
    \$\begingroup\$ Props for the Rick-roll... Well played... \$\endgroup\$ Jun 20, 2021 at 23:55
  • 3
    \$\begingroup\$ Got to love undefined behaviour and chain breaking... \$\endgroup\$ Jun 21, 2021 at 0:17
  • 1
    \$\begingroup\$ @hyper-neutrino The u at the end of you is undefined, which breaks the chain and ignores everything before it. Therefore, the only code that's executed is . \$\endgroup\$ Jun 21, 2021 at 1:36
  • 1
    \$\begingroup\$ @cairdcoinheringaahing well that explains why the h in hurt stopped d from causing issues with trying to divmod by 0... I thought I was losing my mind and forgetting how monadic 2,2 chaining worked lmao. \$\endgroup\$
    – hyper-neutrino
    Jun 21, 2021 at 1:56
  • 3
    \$\begingroup\$ Lyxal is going to be jealous of you.... \$\endgroup\$
    – Wasif
    Jun 21, 2021 at 2:00
28
\$\begingroup\$

Perl 5

Once upon a midnight dreary, while "I pondered", !weak and weary;
Over many a quaint and curious volume of for@gotten, @lore;
While I nodded, nearly napping, until /|there came a tapping|/;
As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;
"Tis some visitor", I-muttered, "tapping at my chamber door";
print unpack f, ${!this} and nothing x more

Try it online!

Ah, distinctly I remember it was in the bleak December; And each separate dying ember wrought its ghost upon the floor.

Explanation / Spoiler:

Perl has a feature called 'barewords', which allows alphanumeric sequences to automatically be parsed as strings. This means that something like

foo bar baz

Will parse as valid Perl, but give a runtime error. However, if we can avoid Perl evaluating it, we can avoid the runtime error. The following program will run without any error:

foo bar baz while 0

Now let's have a look line by line:

Once upon a midnight dreary, while "I pondered", !weak and weary;

"I pondered", !weak and weary evaluates essentially to ("I pondered", false) which is falsy so the stuff on the left hand side of the while loop does not get evaluated.

Over many a quaint and curious volume of for@gotten, @lore;

This is a for loop over the lists @gotten and @lore, which are empty, so the left hand side doesn't get evaluated.

While I nodded, nearly napping, until /|there came a tapping|/;

This is an until loop, where /|there came a tapping|/ is a regex matching against $_. Even though $_ is empty, the leading | matches against the empty string so the match becomes truthy so we don't evaluate the left hand side.

As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;

if is a keyword here. someone is a bareword which is truthy, so we evaluate ${!gently} = "rapping" ^ "rapOing at", which sets ${''} to the string "\0\0\0?\0\0\0 at". my $chamber, $door parses as a function call which is never evaluated, so there's no error.

"Tis some visitor", I-muttered, "tapping at my chamber door";

I and muttered are both barewords.

print unpack f, ${!this} and nothing x more

This parses as (print unpack f, ${!this}) and nothing x more. ${!this} is ${''}, which is our string from earlier. unpack f is a function that unpacks a single 32 bit float from a packed 4 byte representation. The first 4 bytes of ${''} are "\0\0\0?", which happens to be a valid representation of 0.5. The rest of the string is ignored.

Since (print unpack f, ${!this}) is truthy, the right hand side of the and is evaluated. x is the string repeat operator, and nothing and more are both barewords, so there's no error generated.

\$\endgroup\$
5
  • \$\begingroup\$ Wait, how does Perl 5 know how to parse the code from the rest of Edgar Allen Poe's prose? \$\endgroup\$ Jun 21, 2021 at 0:47
  • 1
    \$\begingroup\$ @EliseoD'Annunzio as a hint, have a look at the Perl keywords that are highlighted in blue. There's multiple kinds of syntax abuse here. \$\endgroup\$
    – Sisyphus
    Jun 21, 2021 at 1:46
  • \$\begingroup\$ I see those, but I'm not familiar with Perl's ability to abuse syntax. Any chance you can explain. This is something I've never heard of before, so I'm hoping to understand this more. \$\endgroup\$ Jun 21, 2021 at 1:48
  • \$\begingroup\$ @EliseoD'Annunzio I have edited in an explanation. \$\endgroup\$
    – Sisyphus
    Jun 21, 2021 at 2:41
  • \$\begingroup\$ That is absolutely brilliant... \$\endgroup\$ Jun 21, 2021 at 2:45
26
\$\begingroup\$

Raku, 5 bytes

π/τ

Try it online!

The constant Pi divided by Tau is, of course, 1/2. An alternative without the pesky unicode is to spell it out like pi/tau.

\$\endgroup\$
23
\$\begingroup\$

Python 3, 117 bytes

Try it online!

(lambda n:round(sum(__import__('random').random()for _ in range(n))/n,ord('B')-ord('A')))(ord('~')*ord('~')*ord('~'))

This takes the average of a bunch of random numbers in the range 0-1 then rounds it. There is a very small chance this does not evaluate to 0.5

\$\endgroup\$
1
  • 8
    \$\begingroup\$ Love it. It's rare to see non-deterministic solutions on challenges like this. \$\endgroup\$
    – user100690
    Jun 21, 2021 at 5:23
22
\$\begingroup\$

Vyxal, 122 bytes

H   H  AAAAA  L      FFFFF
H   H  A   A  L      F
HHHHH  AAAAA  L      FFFFF
H   H  A   A  L      F
H   H  A   A  LLLLL  ½

Try it Online!

You asked for half, so I've given you half in more ways than 1 (/2).

This relies on the fact that most things here are NOPS and that getting the length of a number works.

The real work comes when we get to the Ls in the bottom row: the first L is passed, 0, which has length 1. The next 4 Ls all return 1 because the length of 1 is 1. The ½ then divides that 1 by 2.

\$\endgroup\$
18
\$\begingroup\$

Jelly, "HALF OF ONE"

Yes, Jelly can output half of one with just . but did you know there is a secret verbose mode with a certain lexicon of reversed English?

ENO FO FLAH

Try it online!

How?

OK, so I lied.

ENO FO FLAH - Link: no arguments            (implicit 0)
E           - (implicit [0]) all equal?            -> 1
 N          - negate                               -> -1
  O         - ordinal (a no-op with numeric input) -> -1
    F       - flatten                              -> [-1]
     O      - ordinal (vectorises; again a no-op)  -> [-1]
       F    - flatten                              -> [-1]
        L   - length                               -> 1
         A  - absoulte value                       -> 1
          H - halve                                -> 0.5
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Wow, I really like this one! \$\endgroup\$
    – LorenDB
    Jun 21, 2021 at 18:36
16
\$\begingroup\$

Jelly, 1 byte

.

Try it online!

I know it isn't golf, but why be creative when the tools are provided for you?

. is a decimal literal in Jelly. When the values before the . is omitted, it defaults to 0 and after it defaults to 5. Therefore . is just 0.5

\$\endgroup\$
2
  • 19
    \$\begingroup\$ I feel like you just put a full stop to this challenge. \$\endgroup\$
    – Adám
    Jun 20, 2021 at 23:43
  • 1
    \$\begingroup\$ Polyglot with Vyxal: Try it Online! \$\endgroup\$
    – lyxal
    Jun 20, 2021 at 23:58
15
\$\begingroup\$

BQN

A.k.a "the worm".

=⊸÷⟜≠⌾‿⌾

Try it!

Produces a 2-element list consisting of two built-ins (), then divides the rank (1) by the length (2).

Various superfluous parentheses and no-ops can be added for style:

(=÷≠)(⌾‿⌾)
=(⊸)(÷⟜≠)(⌾‿⌾)
⊣(=)(⊸)(÷⟜≠)(⌾‿⌾)
(=)(⊸)(÷)(⟜)(≠)(⌾‿⌾)

Or how about the chicken and the owl:

(≡÷≠)⊢⟨˙⋄˙⟩
(≡÷≠)⊢⟨⌾,⌾⟩

\$\endgroup\$
1
  • 6
    \$\begingroup\$ +1 for the cute smiley face of the worm 🐛 \$\endgroup\$ Jun 21, 2021 at 8:11
15
\$\begingroup\$

C (GCC, MIPS)

// A very mysterious function
float mystery()
{
    // A very mysterious string
    char whaaaaaa['?'] = "?";
    // A very mysterious cast
    return *(float *)whaaaaaa;
}

If you want to test it on a non-based x86 or ARM CPU, try htonl('?').

Explanation

The reason I choose MIPS is because I wanted it to be big endian.
The convenient thing about 0.5f is it is represented as 0x3f000000. 0x3f is ? in ASCII.
The string will be stored as 3f 00 00 00 ... in memory, and dereferencing it on a big endian machine will conveniently result in 0x3f000000.

\$\endgroup\$
2
  • \$\begingroup\$ Isn't MIPS bi-endian? This should work on any big-endian machine, right? \$\endgroup\$
    – Oskar Skog
    Jun 21, 2021 at 9:15
  • \$\begingroup\$ yes, the important thing is big endian. MIPS32 is usually big endian. \$\endgroup\$
    – EasyasPi
    Jun 21, 2021 at 15:30
14
\$\begingroup\$

Wolfram Language (Mathematica), 75 bytes

ElementData["Hydrogen","AtomicNumber"]/ElementData["Helium","AtomicNumber"]

The atomic numbers of hydrogen and helium are exactly 1 and 2, respectively. Atomic masses aren't exact (except for carbon-12's, by defintion, when expressed in daltons), but atomic numbers are, since they're simply the number of protons in the atoms of the element.

[Not sure how to get this working in TIO, or if solutions requring a server connection are allowed in popularity contests.]

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Loving this, the BSc from my university years took notice of this one! \$\endgroup\$ Jun 21, 2021 at 2:42
  • 2
    \$\begingroup\$ @EliseoD'Annunzio I find calling the Wolfram server from within a Mathematica notebook has become the easiest way to get basic data on elements and compounds. But in that case, unless I need something very specific, I'll prepend an = so I can use Wolfram Alpha's natural language input, to avoid the heavy syntax. E.g.: =molecular weight glucose instead of ChemicalData["DPlusGlucose", "MolarMass"] (or, even worse, MoleculeValue[Entity["Chemical", "DPlusGlucose"], {"MolarMass"}]). \$\endgroup\$
    – theorist
    Jun 21, 2021 at 8:19
13
\$\begingroup\$

JavaScript, 67 bytes

Abuses the fact that undefined is a valid identifier in JS.

undefined=>(undefined=>undefined/(undefined+undefined))(!undefined)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ What's the mechanism behind this? \$\endgroup\$
    – James Hyde
    Jun 21, 2021 at 13:35
  • 2
    \$\begingroup\$ @JamesHyde My (possibly incorrect or incomplete) understanding: It may be more readable as f = a=>((b=>b/(b+b))(!a)). When you call a function in JS with fewer arguments than declared, the rest are set to undefined, so when we call f(), a is set to undefined, so we have ((b=>b/(b+b))(!undefined)). !undefined is true in JS (because undefined is falsey(?)), so we have (true/(true+true)). doing arithmetic to true makes it behave as 1, so we have (1/(1+1)) == (1/2) == 0.5 \$\endgroup\$ Jun 22, 2021 at 0:03
13
\$\begingroup\$

Python 3, 420 bytes

from math import*
H=lambda n:int(n,int(sqrt(ord('Ā'))))
o=ord
print(round(sin(H('d')*pi/(H('d')-H('a')))*cos(H('d')*pi/(o('G')-ord('A')))-sin(H('b')*pi/(o('G')-ord('A')))*cos(-(H('f')-H('a'))*pi/(H('d')-H('a'))))/(round((sin(pi/(o('h')-o('a')))*(pi/(o('h')-o('a'))))+(sin((H('f')-H('a'))*pi/H('e'))*(H('f')-H('a'))*pi/H('e'))+(sin(sqrt(o('@'))*pi/((o('h')-ord('a'))))**(H('d')-H('a')))+(sin(sqrt(o('Q'))*pi/H('e'))))))#

Try it online!

Directly from my math book. Solving it by bare hands was a big pain. But writing this answer from mobile was fun. oh plus got a nice byte count.

$$ \frac{\sin \frac{13\pi}{3}\cos \frac{13\pi}{6}-\sin \frac{11\pi}{6}\cos \left(-\frac{5\pi}{3}\right)}{ \sin^2\frac{7\pi}{3}+\sin^2\frac{5\pi}{14}+\sin^2\frac{8\pi}{7}+\sin^2\frac{9\pi}{4}}=0.5 $$

\$\endgroup\$
0
10
\$\begingroup\$

Jelly, 10 bytes

Ænɓ,ÆṛUÆrḢ

Try it online!

I already made an answer that fits with Jelly's ability to be short. How about an answer about Jelly's ability to have stupidly convoluted builtins?

We construct the polynomial \$4x^2 - 4x + 1\$, then solve it as equal to \$0\$, giving \$x = \frac 1 2\$

How it works

Ænɓ,ÆṛUÆrḢ - Main link. Takes no arguments
Æn         - Next prime after zero; 2
  ɓ        - New dyadic chain f(2,2):
   ,       - Pair; [2,2]
    Æṛ     - Construct the polynomial with the roots 2, 2: [4,-4,1]
      U    - Reverse; [1,-4,4]
       Ær  - Get the roots of this polynomial; [0.5, 0.5]
         Ḣ - Get the first element

Why use 1 byte when lot byte do trick?

\$\endgroup\$
1
  • \$\begingroup\$ Loving it, nice and convoluted! \$\endgroup\$ Jun 21, 2021 at 0:12
10
\$\begingroup\$

Ruby

Line number trickery.

p __LINE__ -
  __LINE__ **-
  __LINE__ *
  __LINE__ .
  to_f

Try it online!

Explanation

__LINE__ is a global constant which stores the current line number. As such, the program can be rewritten into one line as: p 1-2**-3*4.to_f, which just so happens to evaluate to 0.5. The .to_f is needed to cast the result to a float (otherwise (1/2) is printed).

\$\endgroup\$
1
  • \$\begingroup\$ Bravo! Love this train of thought! \$\endgroup\$ Jun 21, 2021 at 9:40
8
\$\begingroup\$

Dyalog APL

÷∊⊆⊂∪⊃⊢⊣⊥⍨⍲⍀∨\⍱⌿∧/↑↓⍎⍕⍋⍒⍸⍴⍪,⍉⊖⌽⌹|⌈⌊*¨⍟⍤○⍥!×+~-≢⍬⍝

EDIT: I've updated the picture & text, but not the link nor the explanation.

Try it online!

Uses as many unique primitives as I had the patience to cram in. Andvmany thanks to Adám for giving me a bunch more to cram in! It looks cooler with a proper APL font:

Code

(That is, as many primitives as I could use in a linear chain of execution without parentheses. I'm sure you can use every single one if you allow parentheses, as that opens up the dyadic functions.)

Explanation

÷        Inverse            ->  1/2
↑        Mix                ->  2
↓        Split              ->  2
⊃        First              ->  2
∪        Unique             ->  2
⊂        Enclose            ->  2
⊣        Same (left)        ->  2
⊢        Same (right)       ->  2
∨\       Scan with GCD      ->  2
∧/       Reduce with LCM    ->  2
⍸        Where              ->  [1,2]
⍴        Shape              ->  [1,1]
⍪        Table               ->  3
,        Ravel              ->  3
⍉        Transpose          ->  3
⊖        Horizontal flip    ->  3
⌽        Vertical flip      ->  3
|        Absolute value     ->  3
⌈        Ceiling            ->  3
⌊        Floor              ->  3
*        Exponent           ->  3.14159
¨        Map                ->  1.14472
⍟        Natural logarithm  ->  1.14472
⍤        Atop               ->  3.14159
○        Pi times           ->  3.14159
⍥        Over               ->  1
!        Factorial          ->  1
×        Direction          ->  1
+⍨       Add to itself      ->  2
~        NOT                ->  1
-        Negate             ->  0
∊        Enlist             ->  0
≢        Length             ->  0
⍬        Empty list         ->  []
\$\endgroup\$
3
  • \$\begingroup\$ can be #∩⍬ \$\endgroup\$
    – Adám
    Jun 21, 2021 at 12:37
  • \$\begingroup\$ can be ⊃⍣= \$\endgroup\$
    – Adám
    Jun 21, 2021 at 12:40
  • \$\begingroup\$ So many symbols ⍤ \$\endgroup\$
    – DLosc
    Jun 21, 2021 at 20:09
6
\$\begingroup\$

Perl 6

say ½

Try it online!

Doesn't need explanation, does it?

\$\endgroup\$
6
\$\begingroup\$

Pyth, 4 bytes

cTyT

Try it here!

Divides ten by twice ten.

\$\endgroup\$
6
\$\begingroup\$

C (gcc), 30 bytes

float f(){float x=' ';x/='@';}

Try it online!

Because \$x\$ is a float the characters ' ' (\$32\$) and '@' (\$64\$) get converted to floating point numbers. Then the GCC trick of returning the last calculation is used to return \$\frac{1}{2}\$.

\$\endgroup\$
5
\$\begingroup\$

APL (Dyalog Extended)

#÷⍥≢⍬⍬

Try it online!

Divides the length of a reference to the root namespace (1) by the length of [[],[]] (2).

\$\endgroup\$
1
  • \$\begingroup\$ I'm sure you were going for creative, rather than golfy, but here it is golfed! \$\endgroup\$
    – AviFS
    Jun 21, 2021 at 7:07
5
\$\begingroup\$

APL (dzaima/APL)

⎕←⌈∘○⍢÷*≢~≢⍬

Try it online!

 the empty list; []

 its length; 0

~ logical NOT; 1

*e to the power of that; 2.71828…

⍢÷ while inverted; 0.36787…

∘○ multiply by π; 1.15572…

 round up; 2

Then we "un-invert"; 0.5

\$\endgroup\$
5
\$\begingroup\$

Desmos, 686 bytes

f\left(x\right)=\frac{\frac{\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}{\left(\sin x\right)\left(\sin x\right)}-\frac{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\sin x\right)\left(\sin x\right)}{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\cos x\right)\left(\cos x\right)}}{\sin\left(\arcsin\left(\left(\cos x\right)\left(\cos x\right)-\cos\left(x+x\right)+\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\right)\right)+\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}

Or rendered properly:

\$f\left(x\right)=\frac{\frac{\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}{\left(\sin x\right)\left(\sin x\right)}-\frac{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\sin x\right)\left(\sin x\right)}{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\cos x\right)\left(\cos x\right)}}{\sin\left(\arcsin\left(\left(\cos x\right)\left(\cos x\right)-\cos\left(x+x\right)+\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\right)\right)+\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}\$

Try it online! Defines a function f that will return 0.5 no matter what you put into it, pretty much. It will barf on multiples of π/2 though. Sorry if Desmos lags a bit.

\$\endgroup\$
2
  • \$\begingroup\$ Tried \$f(0)\$ and got undefined... \$\endgroup\$
    – Aiden Chow
    Jun 21, 2021 at 5:04
  • \$\begingroup\$ @AidenChow Most inputs. tan barfs on 0, sec barfs on π/4, etc. \$\endgroup\$
    – emanresu A
    Jun 21, 2021 at 5:42
5
\$\begingroup\$

Desmos, 14 7 bytes

e/(e+e)

Try it on Desmos!

\$\endgroup\$
5
\$\begingroup\$

Python 3, 71 bytes

from http import HTTPStatus
print(HTTPStatus.OK/HTTPStatus.BAD_REQUEST) # 200/400
\$\endgroup\$
2
  • 2
    \$\begingroup\$ # 200/400 number spotted /s \$\endgroup\$
    – EasyasPi
    Jun 21, 2021 at 21:08
  • \$\begingroup\$ Another creative solution! Excellent!! \$\endgroup\$
    – Nate T
    Jun 21, 2021 at 23:06
4
\$\begingroup\$

Wolfram Language (Mathematica), 35/12 bytes

Limit[(-I*I-Cos[x])/(x*x),x->I/∞]

The starting point for this is the following limit:

$$\lim_{x\rightarrow 0}\frac{1-\cos(x)}{x^2} = \frac{1}{2}$$

To eliminate the numbers, I then replaced 0 with ⅈ/∞, 1 with –ⅈ^2, and x^2 with x*x:

$$\lim_{x\rightarrow i/\infty}\frac{-i^2-\cos(x)}{x*x} = \frac{1}{2}$$

Or, less fancy:

-I*I/Floor@E

$$\frac{-i*i}{\lfloor e \rfloor} = \frac{1}{\lfloor \approx 2.718 \rfloor} =\frac{1}{2}$$

[Wasn't sure if the etiquette is to combine this with my previous answer or post separately but, following Caird's example, I did the latter.]

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think this is my favorite. Just straight math. \$\endgroup\$
    – Alec
    Jun 21, 2021 at 16:05
4
\$\begingroup\$

JSFuck, 2443 bytes

[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[!+[]+!+[]])+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]])()((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[!+[]+!+[]+!+[]]]+[+[]]+(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+([+[]]+![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[!+[]+!+[]+[+[]]])

Quite big

\$\endgroup\$
0
4
\$\begingroup\$

Factor + math.unicode

½ .

Try it online!


Or, slightly more interesting: since Factor has a ton of constants and helper words named a, b, c, etc. in private vocabularies, I thought it would be fun to see how far down the alphabet I had to go before arriving at a solution. Turns out not very far. I struck gold with the word a from the math.finance.private vocabulary which is defined as : a ( n -- a ) 1 + 2 swap / ; inline Or, in math terms: \$a(n)=\frac{2}{n+1}\$. Then, I just had to find a value of \$3\$ which turns out to be defined in checksums.md5.private as CONSTANT: d 3 inline. So:

Factor + math.finance.private checksums.md5.private

d a .

Try it online!

\$\endgroup\$
3
\$\begingroup\$

J, 11 bytes

_"_-:@-:_"_

Try it online!

  • In J, -:, as a dyadic verb, means "do the two things match?" and, as a monadic verb, means "half".
  • _ is the literal symbol for infinity. Adding "_ turns it into a verb of infinite rank that always returns the value infinity. This is required syntactically for the right version of _"_, and we add it to the left one for symmetry.
  • Now, for any argument, the verb checks if _ is equal to _, and always returns 1. And half of 1 is 0.5.
\$\endgroup\$
2
  • \$\begingroup\$ Though of course %#_ _ would do. \$\endgroup\$
    – Adám
    Jun 21, 2021 at 0:01
  • 1
    \$\begingroup\$ Sure, but not as pretty :) \$\endgroup\$
    – Jonah
    Jun 21, 2021 at 0:01
3
\$\begingroup\$

APL (Dyalog Unicode)

(+-÷)⍨⍣(×≡#⍬)≢⍬

Try it online!

 the empty list; []

 its length; 0

() compute:

#⍬ a literal; [reference-to-root-namespace,[]]

 the depth (nestedness) of that; -1 (maximum depth is 1, but negative value indicates raggedness)

 apply the following tacit function that many times (i.e. find an argument to the following function such that the result is 0 (from the length of the empty list above)

()⍨ apply this function with its sole argument as both left and right argument:

  +-÷ the sum minus the ratio

Effectively solves \$x+x-x÷x=0\$ or \$2x-1=0\$ which gives \$x=1÷2=0.5\$.

\$\endgroup\$
3
\$\begingroup\$

Ly, 23 bytes

<<'<::+/u':':'u/+::<'<<

Try it online!

A reversible one just for fun...

<<                       # Shift stack left twice
  '<                     # Push "<" on the stack
    ::                   # Duplicate top of stack twice
      +/                 # Add then divide to get 0.5
        u                # Print as a number
                         # The rest of the code winds up being ignored...  The code just
                         # has to be valid and not generate output.
         ':':'u          # Push "::u" onto the stack
               /+::      # Divide, add, then duplicate top of stack twice
                   <     # Shift stack left
                    '<   # Push "<" on the stack
                      <  # Shift stack left (to an empty stack)

And another one that's a mirror image around a central point.

Ly, 21 bytes

<<'<::+/'upu'\+::>'>>

Try it online!

\$\endgroup\$
3
\$\begingroup\$

QBasic (QB64)

X = Y = Z
PRINT ATN(X) / ATN(X / Y)

All variables in QBasic are initialized to 0. The first line is X = (Y = Z), where the first = is assignment but the second = is comparison. Truthy is -1 in QBasic, so now X is -1. QB64 allows division by 0, returning floating point infinity (or in this case, negative infinity); \$\arctan(-1) = -\frac \pi 4\$, and \$\arctan(-\infty) = -\frac \pi 2\$.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.