228
\$\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\$
  • 61
    \$\begingroup\$ This is one of the very few (imo) successful non-fixed-output no-input non-random challenge. Unique idea! \$\endgroup\$ – Mr. Xcoder Aug 26 '18 at 0:45
  • 2
    \$\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 Aug 27 '18 at 19:07
  • 6
    \$\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\$ – ETHproductions Aug 27 '18 at 19:27
  • 9
    \$\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\$ – Shieru Asakoto Aug 28 '18 at 11:21
  • 2
    \$\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\$ – Shieru Asakoto Feb 8 at 8:22

114 Answers 114

1
\$\begingroup\$

Befunge-93 (FBBI), $209024 (8 bytes)

",**.@G$

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Note that this beats the previous Befunge-93 answer because this interpreter doesn't follow spec on pushing a space when wrapping \$\endgroup\$ – Jo King Jun 29 at 1:57
1
\$\begingroup\$

Zsh, $127569, 15 bytes

];<<<\$$?${-%?}

Try it online!

Squeezing out a bit more than the Bash answer by abusing the default flags. By default, the $- parameter is set to 569X. ${ %?} removes the last character. We can actually get a lot further by manually controlling the flags:

zsh -178, $156789, 11 bytes

<<<\$${-%?}

Try it online!


If the exponent was slightly more favorable (-0.74 instead of -0.75), I could get quite the bonus: zsh +X5 -2378 '<<<\$$-' (7 bytes and $236789). Maybe management could be convinced next year...

\$\endgroup\$
  • \$\begingroup\$ I believe command-line arguments are included in the byte count. Good answer, though! \$\endgroup\$ – Purple P Oct 2 at 7:28
  • \$\begingroup\$ @PurpleP I like the reasoning of this meta post, but feel free to draw your own conclusions. :P \$\endgroup\$ – GammaFunction Oct 2 at 12:29
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\$
  • \$\begingroup\$ Gonna fix it (should not post from my phone) \$\endgroup\$ – Francisco Hahn Aug 27 '18 at 16:07
  • \$\begingroup\$ Actually the ouytput is $98301 \$\endgroup\$ – Francisco Hahn Aug 27 '18 at 16:32
0
\$\begingroup\$

Pip, $192,450 (9 bytes)

'$.A'𮿂

Try it online!

Boring "codepoint of Unicode character" answer. A more interesting (but slightly less lucrative) 9-byte approach is this:

'$.A'XPI

which gives $191,919 by string-repeating the codepoint of  (19) \$\pi\$ times (rounded down).

\$\endgroup\$
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
    \$\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\$ – Teal pelican Sep 4 '18 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\$
  • \$\begingroup\$ Isn't the max for 26 bytes $86850.03? Couln't you use a higher unicode value? \$\endgroup\$ – Jo King Nov 30 '18 at 12:29
  • \$\begingroup\$ This is actually 27 bytes. \$\endgroup\$ – Dennis Nov 30 '18 at 15:28
0
\$\begingroup\$

C, $82154 (28 bytes)

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

Try it online!

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

Canvas, $279936 (5 bytes)

$67^+

Try it here!

Note that the 6 & 7 there are full-width characters, not ASCII numbers.

\$\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\$

Ink, $56789, 43 bytes

$<>
-(o)~temp q=o+o+o+o
-(t){t+q}{t<=q:->t}

Try it online!

Explained

$<>               // Print a dollar sign and do not print a trailing newline.
-(o)              // Create a gather, and give it the label o. This creates a variable o, which keeps track of how many times this gather has been reached
                  // It is currently set to 1, and it will stay that way.
~temp q=o+o+o+o   // Create a variable q, containing the number 4.
-(t)              // Another label, another variable.
{t+q}             // print t + q, that is to say t + 4
{t<=q:->t}        // If t is not greater than q, jump to the gather labelled t
                  // (this automatically increments the t variable)

Alternative solution: $66666, 31 bytes, but

I did find a better solution, but I don't like it, because it abuses a bug in the interpreter:

-(n){|}$<>
-(t){t<n+n:{n+n}->t}

Try it online!

The {|} is a sequence - it outputs one string (the empty string, in this case) the first time the line is reached, and another string (which in this case is also the empty string) every subsequent time the line is reached.
This might not seem useful here, since we never return to that line. But in the current version of Inklecate, when a sequence occurs immediately after a labelled gather, the gather's readcount increments three times rather than the usual one.
This makes it easy to produce a 3, which we then use to print the number 6 five times.

\$\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\$

Runic Enchantments, 6 bytes, $255000

Thought I'd hit up a few challenges with the language I wrote a few days ago. TIO doesn't yet have an interpreter for it (coming soon I hope). Character set and execution is similar to ><>, but with an extended set of available commands, multiple IPs, and IP "energy" (some commands--such as o (sort)--require/consume mana and IPs with 0 mana are terminated).

'ÿY'$@

Try it online!

Explanation

>          Implicit entry (single line programs only; does not occupy a cell)
 'ÿ        push ÿ as a character
   Y       multiply by 1000 (implicit conversion to 255)
    '$     push $ as a character
      @    print entire stack and terminate the IP

An earlier attempt was e|$$$':* (push 15, reflect, push 15, multiply, duplicate, push $, print, print, print, (print: empty stack: IP terminated), resulting in $196196 however I realized that I could use @ instead of $$ which got me f|@$':* with a score of $225225, but further experimentation showed that I could get down to six characters starting from Pbp'$@ (push PI, push 11, power, push $, print and terminate), which was c5p'$@. But that ran into the issue of no digit characters allowed (ironically, both entries resulted in higher outputs).

2 IPs (because the language can): $148642 (max $155100)

>e'$@
FFm\>

Try it Online

Explanation

This will be a little hard to follow, but hopefully it makes sense. Instruction pointers wrap when they reach the edge of the program.

>
    >      Entry points (each IP begins with 10 mana)
----------------------
 e         Push 14
F          Fizzle
----------------------
  '        Enable single character read mode
 F         Fizzle
----------------------
   $       Push '$'
  m        Push current mana (8)
----------------------
    @      Print stack ($14) and terminate
   /       Reflect upwards
----------------------
   $       Pop and print (8)

----------------------

   /       Reflect right
----------------------
   $
mFF/       Push current mana (6), fizzle twice, reflect up
           At this point the IP is in a loop. It will terminate
           when it pushes a (2) and fizzles twice to end up with 0 mana
\$\endgroup\$
  • \$\begingroup\$ Note that non-competing doesn't apply to new languages anymore \$\endgroup\$ – Jo King Sep 23 '18 at 5:18
  • \$\begingroup\$ @JoKing Oh? I didn't find that on meta. \$\endgroup\$ – Draco18s Sep 23 '18 at 15:10
  • 2
    \$\begingroup\$ Note that you can't use numbers in your source (the 5 is illegal). \$\endgroup\$ – Spitemaster Sep 27 '18 at 2:27
  • \$\begingroup\$ @Spitemaster and updated. Both versions actually managed HIGHER outputs as a result. Heh. \$\endgroup\$ – Draco18s Sep 27 '18 at 20:26
  • \$\begingroup\$ If I'm reading the challenge correctly, 7 bytes only allows for a maximum of $232368 \$\endgroup\$ – recursive Oct 3 '18 at 23:38
0
\$\begingroup\$

Cascade, $177827, 10 bytes

^𫚣$
 #"

Try it online!

I'm lucky here in that 𫚣 counts as a letter variable, which allows me to fetch its ordinal value, with the cost that it is a multi-byte character.

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

Go, $84426

func f(){print("$",'𔧊')}

The character in the single quotes is the Unicode character with code point U+149CA, encoded as 4 bytes in UTF-8. The Unicode standard does not currently assign it a value, but it is nevertheless valid to place it in Go source code, earning me only 18 cents below the maximum for 27 bytes. If you prefer, the character U+14646 Anatolian Hieroglyph A530 is the nearest that is assigned, though it only gets me $83526.

\$\endgroup\$
-1
\$\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\$
  • 4
    \$\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 Aug 29 '18 at 20:16
  • 1
    \$\begingroup\$ Giuseppe: Is having the $ displayed not valid? \$\endgroup\$ – Selkie Aug 29 '18 at 20:16
  • 4
    \$\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 Aug 29 '18 at 20:17
  • 2
    \$\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\$ – Jonathan Frech Aug 29 '18 at 20:33
  • 2
    \$\begingroup\$ @JayCe Loopholes that may be applicable include this and this. \$\endgroup\$ – Jonathan Frech Aug 30 '18 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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