Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Can you give me half?

+11
−0

Challenge idea taken from: Eliseo D'Annunzio

Task

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.

One example that fits the brief would be the following:

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

Scoring

This is a code challenge, where scoring is done in terms of number of unique characters used in the submission. Ties are broken by lowest bytecount.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Languages without built in float (2 comments)
Leaderboard scores (1 comment)

23 answers

+1
−0

[Extended] Dyalog APL, 4 bytes*

*10 bytes, 4 unique

'÷'÷⍥≢'÷÷'

This computes the length of the string '÷' divided by the length of the string '÷÷'

Alternate solution (extended only) (6 unique, 6 bytes)

⊢÷+⍨×∞

This computes

\[ \left(\lambda x.\frac{x}{x+x}\right) \mathrm{sign}\infty \]
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Golfscript, 8 6 bytes, 5 unique

!).!(?

Explanation:

! # negate , no value makes it 1
) # increment -> 2
. # duplicate 2
! # negate 2 = 0
( # decrement -> -1
? # exponentiate, 2^-1 = 1/2

Original solution:

!)""!((?
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Vyxal, 1 byte

.

Try it Online!

Very simple 1 byter

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Fig, 2 unique, 2 total

H!

Try it online!

Halves the negation of the empty string when no input is given.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+4
−0

C (gcc), 8 7 unique

cos(cos-cos)/(cos(cos-cos)-(-cos(cos-cos)))

Try it online!

-1 unique character thanks to @orthoplex‭

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

golf (2 comments)
+2
−0

J, 4 unique, 4 char

-:=_

How it works:

-: results in half of what's on the right
= results in signum of what's on the right
_ is infinity
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Lua 5.4, 3 unique characters

#'#'/#'##'

Try it online!

[...] scoring is done in terms of number of unique characters used in the submission.

  1. Hashtag #
  2. Single quote '
  3. Slash /
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+3
−0

Python 3, 5 unique bytes, 28 total

(()==())/((()==())+(()==()))

(, ), =, /, +

Uses (()==()) to get True with only 3 unique characters, as well as making the later grouping of (...+...) free.

Try it online!

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

MATL, 3 distinct, 3 total

lH/

Try it online!

Computes 1/2. Reserved labels for constants can be found here

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+3
−0

Clojure - 15 characters total, 5 unique

Inspired by the Embed ESCR solution above, I realized I could do something very similar in Clojure:

(/(*)(+(*)(*)))

This returns 1/2, which is a Ratio in Clojure.

(*) - * with no arguments returns 1.

(+...) - + returns the sum of its arguments

(/...) - / divides the first argument by the second, returning a Ratio.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+3
−0

Perl, 3 distinct, 12 bytes

s//yy//y/y//

Try it online!

Prepends yy to the start of $_, and then transliterates them, dividing the count of each.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+3
−0

J, 4 3 distinct, 6 bytes

-:_-:_

Half of _ -: _ which is asks if infinity matches infinity. Thanks to @xash in the APL farm discord for saving the 3 unique bytes and orthoplex for catching my blunder.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

`%#_ _` has unique 4 bytes, no? (2 comments)
+2
−0

JS, 15 bytes

!![]/(-~[]-~[])

Basically typed random characters into js console and it worked.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

This has less unique characters: `!![]/(!![]+!![])` (1 comment)
+4
−0

Ruby, 7 unique, 12 bytes

$$.fdiv$$+$$

Ruby, 8 unique, 13 bytes:

$$.fdiv $$+$$

Ruby, 9 unique, 22 bytes:

"i".size.fdiv"ii".size

Ruby, 9 unique, 24 bytes:

Math::E./Math::E+Math::E

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Julia 1.0, 16 bytes

(o=one(Int))/-~o

Try it online!

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Ruby, 10 distinct, 35 chars

t=/%/=~%/=%/
o=/%/=~%/==%/
t/o.to_f
History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Raku (also Perl polyglot), 5 unique, 13 bytes

!()/(!()+!())

() or empty list coerces to its length which is 0 in math operations and !0 is True which coerces to 1

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Scala, 15 bytes

'#'.toFloat/'F'

Try it in Scastie!

Characters in Scala kinda get casted to integers. This is usually annoying, but it's useful when golfing. # is 35 and F is 70, and the .toFloat prevents it from doing integer division and truncating to 0.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+4
−0

Embed ESCR, 6 unique characters, 19 bytes

[/ [*] [+ [*] [*]]]

Each [] pair of brackets encloses an in-line function. The first token in a function is the function name, and subsequent tokens, if any, the parameters. Functions can be nested.

The * function multiplies a series of numbers. The product is initialized to 1 before the first term. A side-effect is that just "*" without any parameter returns 1. The "+" function adds two 1s to make 2. The "/" function divides the first parameter by the second, so 1 divided by 2. The result is 1/2.

The spaces are enforced for readability, and to simplify the parsing rules. This NOT a golfing language.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

comment (1 comment)
+2
−0

Japt, 1 byte

½

Test it

Jelly, Vyxal, 1 byte

.

Try it online!

Yeah, golf langs still kind of kill this challenge.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

The Japt one _must_ work in a couple of other languages, surely? I'd be shocked if it didn't. (2 comments)
I think the second works in 05AB1E too (3 comments)

Sign up to answer this question »