272
\$\begingroup\$

As I'm applying for some jobs whose job advert doesn't state the salary, I imagined a particularly evil interviewer that would give the candidate the possibility to decide their own salary ...by "golfing" it!

So it goes simply like that:

Without using numbers, write a code that outputs the annual salary you'd like to be offered.

However, being able to write concise code is a cornerstone of this company. So they have implemented a very tight seniority ladder where

employers that write code that is b bytes long can earn a maximum of ($1'000'000) · b−0.75.

we are looking at (these are the integer parts, just for display reasons):

   1 byte  → $1'000'000       15 bytes → $131'199
   2 bytes →   $594'603       20 bytes → $105'737
   3 bytes →   $438'691       30 bytes →  $78'011
   4 bytes →   $353'553       40 bytes →  $62'871
  10 bytes →   $177'827       50 bytes →  $53'182

The challenge

Write a program or function that takes no input and outputs a text containing a dollar sign ($, U+0024) and a decimal representation of a number (integer or real).

  • Your code cannot contain the characters 0123456789.

In the output:

  • There may optionally be a single space between the dollar sign and the number.

  • Trailing and leading white spaces and new lines are acceptable, but any other output is forbidden.

  • The number must be expressed as a decimal number using only the characters 0123456789.. This excludes the use of scientific notation.

  • Any number of decimal places are allowed.

An entry is valid if the value it outputs is not greater than ($1'000'000) · b−0.75, where b is the byte length of the source code.

Example output (the quotes should not be output)

"$ 428000"            good if code is not longer than 3 bytes
"$321023.32"          good if code is not longer than 4 bytes
"  $ 22155.0"         good if code is not longer than 160 bytes
"$ 92367.15 \n"       good if code is not longer than 23 bytes
"300000 $"            bad
" lorem $ 550612.89"  bad
"£109824"             bad
"$ -273256.21"        bad
"$2.448E5"            bad

The score

The value you output is your score! (Highest salary wins, of course.)


Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, $X (Y bytes)

where X is your salary and Y is the size of your submission. (The Y bytes can be anywhere in your answer.) If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>$111111.111... (18 bytes)</s> <s>$111999 (17 bytes)</s> $123456 (16 bytes)

You can also make the language name a link, which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), $126,126 (13 bytes)

var QUESTION_ID=171168,OVERRIDE_USER=77736;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body.replace(/<(s|strike)>.*?<\/\1>/g,"");s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a1=r.match(SCORE_REG),a2=r.match(LANG_REG),a3=r.match(BYTES_REG);a1&&a2&&e.push({user:getAuthorName(s),size:a3?+a3[1]:0,score:+a1[1].replace(/[^\d.]/g,""),lang:a2[1],rawlang:(/<a/.test(a2[1])?jQuery(a2[1]).text():a2[1]).toLowerCase(),link:s.share_link})}),e.sort(function(e,s){var r=e.score,a=s.score;return a-r});var s={},r=1,a=null,n=1;e.forEach(function(e){e.score!=a&&(n=r),a=e.score,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.lang).replace("{{SCORE}}","$"+e.score.toFixed(2)).replace("{{SIZE}}",e.size||"?").replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);s[e.rawlang]=s[e.rawlang]||e});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){var r=e.rawlang,a=s.rawlang;return r>a?1:r<a?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SCORE}}","$"+o.score.toFixed(2)).replace("{{SIZE}}",o.size||"?").replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var LANG_REG=/<h\d>\s*((?:[^\n,](?!\s*\(?\d+\s*bytes))*[^\s,:-])/,BYTES_REG=/(\d+)\s*(?:<a[^>]+>|<\/a>)?\s*bytes/i,SCORE_REG=/\$\s*([\d',]+\.?\d*)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:520px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Score</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td><td>Size</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SCORE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SCORE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>


Edit: (rounded) maximum allowed score per byte count, for a quicker reference - text here:

enter image description here

\$\endgroup\$
9
  • 77
    \$\begingroup\$ This is one of the very few (imo) successful non-fixed-output no-input non-random challenge. Unique idea! \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 26, 2018 at 0:45
  • 4
    \$\begingroup\$ Nice challenge! Can we output a fully formatted currency value, if desired? Like $80,662.67 instead of $80662.6659? Your rules seems to preclude the comma, which means I couldn't use any built-in currency functions. \$\endgroup\$
    – BradC
    Commented Aug 27, 2018 at 19:07
  • 7
    \$\begingroup\$ I hope you don't mind, I've added a variation of the Leaderboard Snippet that sorts by score instead of bytes. Excellent first challenge! \$\endgroup\$ Commented Aug 27, 2018 at 19:27
  • 12
    \$\begingroup\$ Just noticed the new contributor tag. Well-constructed challenge, with such a high upvote and a vast amount of answers in only a few days, I wonder if this could be eligible for this years' Rookie of The Year ;) \$\endgroup\$ Commented Aug 28, 2018 at 11:21
  • 4
    \$\begingroup\$ I've nominated this challenge as a candidate for "Rookie of the Year - Challenges" category in Best of PPCG 2018 as I said back then. \$\endgroup\$ Commented Feb 8, 2019 at 8:22

147 Answers 147

1 2 3 4
5
1
\$\begingroup\$

Julia 1.0, $101937 (23 21 bytes)

print(:$,Int('𘸱'))

Try it online!

To obtain the magic value, I rounded down the maximum score for a solution with this byte count, then converted it to a Char.

-2 bytes thanks to amelies: print :$ instead of '/$'

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 21 print(:$,Int('𗏮')) \$\endgroup\$
    – amelies
    Commented Apr 2, 2023 at 21:40
1
\$\begingroup\$

GolfScript, 6 bytes, $255,255

"$\xFF").

Try it online!

The \xFF should be a literal 255-codepoint character, which is a fairly common technique in a lot of languages, however 255 specifically doesn't work. There are multiple different character sets with different characters for 255, and golfscript parses none of them correctly. In other words, pretend that \xFF is only one character long because it should be able to.

\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately Golfscript (or at least this interpreter) interprets strings as a ruby literal, which enforces utf-8 encoding. However, there are other interpreters written in other langs that might do what you're looking for \$\endgroup\$
    – Jo King
    Commented Apr 4, 2023 at 3:26
  • \$\begingroup\$ @JoKing I figured it was something like that \$\endgroup\$ Commented Apr 4, 2023 at 3:31
1
\$\begingroup\$

Forth (gforth), 33 bytes, $69696

CHAR , CHAR $ DUP EMIT OVER * * .

Try it online!

As much as I prefer jonesforth, gforth doesn't need trailing whitespace for . to work properly, so it saves a byte.

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

PHP, 18 Bytes $98301

Using the defined constants of php core.

$<?=E_ALL*SIGQUIT;

It's simple E_ALL = 32767 and SIGOUIT = 3

Output

$98301

**No restriction on use of defined constants :D

\$\endgroup\$
2
  • \$\begingroup\$ Gonna fix it (should not post from my phone) \$\endgroup\$ Commented Aug 27, 2018 at 16:07
  • \$\begingroup\$ Actually the ouytput is $98301 \$\endgroup\$ Commented Aug 27, 2018 at 16:32
0
\$\begingroup\$

brainfuck, 44 bytes, $57777

Omg, first time trying this thing.... I don't even know how I did it xD

+++++++++[>++++>+<<-]>.>[>++++++<-]>-.++....

Try it online!

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

plain TeX (using pdftex), $91126 (24 bytes)

\$\number`[\number`~\bye

Output is printed into a PDF.

Explanation: \number` prints the decimal place in the ASCII table of the following character.

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

PHP, $122122 (17 bytes)

$<?=$a=ord(z),$a;

first attempt, $80662, 25 bytes:

$<?=(M_PI**M_PI)**M_PI<<!A;

test script

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

Swift 4, $50653 (50 bytes)

let a=UnicodeScalar("%")!.value;print("$\(a*a*a)")

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Using your code you can golf this a bit (I have never done swift). Move the variable into the code itself and use a higher char for the unicode value and replace the aaa with a single call. tio.run/##Ky7PTCsx@f@/oCgzr0RDSSVGIzQvMzk/… \$\endgroup\$ Commented Sep 4, 2018 at 13:36
0
\$\begingroup\$

BASH, $82154 (28 bytes)

printf \\b!T|xxd -p|tr $[] $

Try it online.

This one requires an ASCII-capable machine, as \b, !, T must have code table positions 0x08, 0x21, 0x54 respectively. $[] is an empty arithmetic context whose result is 0.

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

Python 3, $78011 & 23 bytes

print("$",ord("𓂻"))

This is really simple, I just used the largest ordinal value I could find.

Try it online!

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

Backhand, $189642 (9 bytes)

""o@$*O}

Try it online!

This was a bit of a weird one. The unprintable in the middle has a char value of 24.

Explanation:

Note that the pointer typically moves three steps at a time

"            Starts a string literal
   @        Pushes some characters to the stack
             Bounces off the edge and go left
 "  $  O     Push some more chars and end the string literal
             Bounce off the edge and go right
  o          Output the $
     *       Multiply the O (79) by the unprintable (24) = 1896
        }    Step to the right, which bounces off the edge, so steps left instead
       O     Output the 1896
 "  $        Start another string literal and reflect
  o  *  }    Push chars and reflect
  o  *       Push more chars and reflect
 "           End string literal
    $  O     Swap the o and * and outputs the * as a number (42)
   @        Unprintable (ignored) and then terminates

Most of this was from accidentally using } (step right) instead of { (step left) as the last char, which led me to find out that this used the O (output number) twice, so I could avoid having to do too much more fiddling.

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

Lua, $74088 (32 bytes)

s='*'x=s:byte()print('$'..x*x*x)

Try it online!

How:

s:byte()returns an integer equivalent to string s ASCII value, '*' value is 42, 42^3=74088. I guess this is the optimal solution for the size of the code I managed to think of, feel free to prove me wrong.

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

Aheui (esotope), 30 bytes, $73636

밦밦따빠맣빠뱘휉망어

Try it online!


Explanation:

밦: push 6, move cursor right by 1(→).
밦: push 6, →
따: mul(push 36), →
빠: dup(push 36), →
맣: print as character(36 > '$'), →
빠: dup(push 36), →
뱘: push 7, move cursor right by 2(→→).
휉: end.
망: print as integer, →
어: move cursor left by 1(←).

Note: Print instruction moves cursor in reverse direction if current storage is empty.

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

C (gcc) - 26 bytes - $53159

main(){printf("$%d",'ϧ');}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Isn't the max for 26 bytes $86850.03? Couln't you use a higher unicode value? \$\endgroup\$
    – Jo King
    Commented Nov 30, 2018 at 12:29
  • \$\begingroup\$ This is actually 27 bytes. \$\endgroup\$
    – Dennis
    Commented Nov 30, 2018 at 15:28
0
\$\begingroup\$

C, $82154 (28 bytes)

main(){printf("$%x",'!T');}

Try it online!

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

cQuents, $177800 (10 bytes)

@$#t:tto۲

Try it online!

Explanation

@$          prepend $
  #t        output tenth term in sequence
    :       each term in the sequence equals
     tt       10 * 10 * 
       o۲               python ord("۲"), which is 1778
\$\endgroup\$
0
\$\begingroup\$

Perl 6, 18 bytes ($114431)

say '$'~ord '𛻿'
\$\endgroup\$
0
\$\begingroup\$

33, $139,968 (12 bytes)

"$"jcaaaxxpo

Explanation

"$"       p  | Prints '$'
   jca       | Loads 36 (ASCII value of '$') into the accumulator and counter
      aaxx   | Trebles it (108), then multiplies the result by 1,296 (139,968)
           o | Prints it
\$\endgroup\$
0
\$\begingroup\$

BRASCA, $165100 (11 bytes) $192100 (9 bytes)

'$o'ÀHgn

Try it online!

Explanation

'$o          - Print $
   'À        - Push 192
     H       - Push 100
      gn     - Concatenate and print
\$\endgroup\$
0
\$\begingroup\$

Pxem, 9 bytes (filename only), $192255.

  • Filename (escaped unprintables): $.p\300\377.n.n

Try it online!

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

Ly, $151515 (9 bytes) (11 bytes) (12 bytes)

'/' -::'$ouu

Try it online!

'/' -::'$ouu  # 
'/            # Push codepoint for "/" (47) on the stack
  '           # Push codepoint for " " (32) on the stack
   -          # Subtract yielding (15)
    ::        # Duplicate the top of the stack twice
      '$:o    # Push a "$" on the stack and print it as a char
          uu  # Print two entries on the stack as numbers (1515)

At the end of the code the stack contains 15 which is printed as a int by default, making the final concatenated output $151515.

\$\endgroup\$
3
  • \$\begingroup\$ Ah, I read the challenge wrong... I thought 4-9 chars was 353553. I'll rework the code... \$\endgroup\$
    – cnamejj
    Commented Jun 16, 2021 at 6:38
  • \$\begingroup\$ Fixed the code... \$\endgroup\$
    – cnamejj
    Commented Jun 16, 2021 at 6:57
  • \$\begingroup\$ ha! this challenge is going to make me insane. :) OK, back into the code. \$\endgroup\$
    – cnamejj
    Commented Jun 16, 2021 at 7:03
0
\$\begingroup\$

Rattle, 14 bytes, $122265

$|b<=@*~//*`*b

Try it online!

Try to outgolf this in Rattle!!!!!

Explanation

|                 takes anything to the left of it as input ("$")
 b                adds "$" to the print buffer
  <               moves the pointer left (wraps around to pointer = 99)
   =@             sets the value on top of the stack to the pointer ( = 99 )
     *~           multiplies this value by 10 ( = 990 )
       //         divides by two, twice ( = 247.5 )
         *`       multiplies this value by its rounded self ( = 247.5 * 247 = 61132.5)
           *      multiplies this value by 2 ( = 122265)
            b     adds this value to the print buffer, prints and clears buffer implicitly 

Note that this works in the current version of Rattle, but the data tape may eventually be expanded past 100 slots (the TIO link here is permanent for the current Rattle version, 1.1.2)

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

Pip, $192,450 $202,020 (9 8 bytes)

O'$t+tMh

Try it online!

Explanation

          Preset variables used: t = 10, h = 100
O'$       Output a dollar sign with no trailing newline
   t+t    10 + 10
      Mh  for each digit in 100
          The result is the list [20;20;20]
          Output, concatenating items together (implicit)
\$\endgroup\$
0
\$\begingroup\$

Risky, $200000 (8 bytes)

\*\!/**+:}!_\*+

Try it online!

Explanation:

       +         ;  Join
   !             ;    Pair of
\*\              ;      "$" (6 * 6)
    /**          ;      "2" (5 * 10)
           _     ;    Fill
        :}!      ;      [1, 0, 2, 0, 1] (100 in base 3)
            \*+  ;      "0" (6 * 8)
\$\endgroup\$
0
0
\$\begingroup\$

Thunno KJ, $93,648.04 (7 bytes)

AwaA^'$

Attempt This Online!

Explanation

Aw       # Push pi
  aA     # Push 10
    ^    # Push pi ** 10
     '$ '# Push "$"
         # The flags concatenate them
         # (Because of the way Thunno's
         # stack works, the "$" gets
         # put in front of the number)
         # Implicit output
\$\endgroup\$
0
\$\begingroup\$

Alice, 16 bytes, $124992

'$o'ག' */ o @

Try it online!

The trailing whitespace of the program is required

\$\endgroup\$
-2
\$\begingroup\$

Excel, $260847, (6 Bytes)

(Max of 260847.43 at 6 bytes)

=Row()

In cell A260847 (or any other cell in the row), simply have =Row(). Row returns the row of the reference in question, and when nothing is given, simply returns the row of the cell that the formula is in.

We can then use Excel's Accounting formatting to insert the $ for us (or any other type of custom formatting).

This makes us extremely efficient and effective!

\$\endgroup\$
9
  • 6
    \$\begingroup\$ Welcome to PPCG! While this is a clever idea, it is unfortunately not valid as you need to output the $ as well! \$\endgroup\$
    – Giuseppe
    Commented Aug 29, 2018 at 20:16
  • 1
    \$\begingroup\$ Giuseppe: Is having the $ displayed not valid? \$\endgroup\$
    – Selkie
    Commented Aug 29, 2018 at 20:16
  • 6
    \$\begingroup\$ Yep, the requirements are for a program/function that outputs a text containing a dollar sign ($, U+0024) and a decimal representation of a number (integer or real) -- I missed this my first time as well! \$\endgroup\$
    – Giuseppe
    Commented Aug 29, 2018 at 20:17
  • 3
    \$\begingroup\$ One could also argue that the six bytes in 260847 (the cell's position) have to be included, since it is information available to the program. \$\endgroup\$ Commented Aug 29, 2018 at 20:33
  • 2
    \$\begingroup\$ @JayCe Loopholes that may be applicable include this and this. \$\endgroup\$ Commented Aug 30, 2018 at 10:14
1 2 3 4
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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