Without using numbers, get the highest salary you can. But don't exaggerate!

  • 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


    This is one of the very few (imo) successful non-fixed-output no-input non-random challenge. Unique idea!

    would `$ 119 126` be valid output?

    @ovs not according to the rules, no. sorry

    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.

    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!

    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 ;)

    Congratulations on acquiring 2 gold badges!

    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.

  • bash, $127127





    x;echo \$$?$?


    Try it online!



    Since the x command doesn't exist, it errors and sets the exit code to 127.



    Then, the code outputs a dollar sign followed by $? twice. The $? variable stores the exit code of the previous command, so this outputs $127127 in 13 bytes.


    Funnily enough if you're on Mac and you have XQuartz installed, this won't work because `x` _does_ exist. As a bonus, it crashed when trying to open it, so I got `$11` instead!

    Use `]` instead of `x`, the former is less likely to exist.

    @numbermaniac Also, such commands were found for installing on ubuntu 19.04: e, q, r. But `w` is a thing (close to `who`) and exit successfully, so you get $00 for it!

  • Java 8, $131,199.00 (15 bytes)





    v->"$"+'e'*'ԓ'


    Try it online.



    Explanation:



    v->            // Method with empty unused parameter and String return-type
    "$"+ // Return a dollar sign, concatted with:
    'e'*'ԓ' // 131199 (101 * 1299)


    \$131,199.00 < 131,199.31\$



    I used a program to generate a printable ASCII character in the range [32, 126] which, when dividing 131199, would have the lowest amount of decimal values. Since 101 can divide 131199 evenly, resulting in 1299, I'm only 31 cents short of my maximum possible salary based on my byte-count of 15.


    Dang, impressively efficient score!

  • CJam, (5 bytes) $294204.018...



    '$PB#


    Try it online!



    Explanation:



    I derived it from Dennis' answer, but looked for combinations of numbers which would yield a higher result. I almost gave up, but I saw that P is the variable for \$\pi\$, and that \$\pi^{11} \approx 294000\$. The letter B has a value of 11 in CJam, giving the code above.


    Since your score is your salary, you should mention it in the header. This answer is currently winning. :)

  • CJam, 5 bytes, $262'144



    '$YI#


    Try it online!



    How it works



    '$     Push '$'.
    Y Push 2.
    I Push 18.
    # Pop 2 and 18 and perform exponentiation, pushing 262144.

  • R, 20 bytes, $103540.9





    T=pi+pi;cat("$",T^T)


    Try it online!



    The max for 20 bytes is $105737.1, so this is quite close to the salary cap!



    This would be a nice raise, and if I get paid to do code golf......


    might be a way to combine `pi` with a dataset's sum... would require a programmatic approach to evaluate various combination of operators/datasets/pi to get as close to the max as possible. No time for this now but it sounds like a nice challenge in itself.

  • GS2, (5 bytes) $292,929


    •$☺↔A

    A full program (shown here using code-page 437). (Maximum achievable salary @ 5 bytes is $299069.75)


    Try it online!


    Builds upon Dennis's GS2 answer...


    •$☺↔A                             []
    •$ - push '$' ['$']
    ☺ - push unsigned byte:
    ↔ - 0x1d = 29 ['$',29]
    A - push top of stack twice ['$',29,29,29]
    - implicit print $292929

    That's 11 bytes, even if it is 5 characters.

    @dotancohen: `0x0724011d41` is 5 bytes by my count...

    @eggyal: I missed the bit about code-page 437. Nice touch!

    Dear down-voter, could I have some feedback please; I don't see what is incorrect, not useful, or unclear.

  • R, 21 bytes $99649.9



    cat("$",min(lynx^pi))

    Try it online!


    A different R approach - see also Giuseppe's answer


    Very close to the maximum of $101937 for this bytecount.


    Bonus: object.size()


    R, 24 bytes $89096



    cat("$",object.size(ls))

    Try it online!


    This is probably system-dependent, but when I ra this on TIO I got $89096 - close to the limit of 92223 for 24 bytes.


    neat! I thought about trying to pick a good dataset but I can't figure out where to look to find them...I guess the `datasets` package makes a lot of sense.

    @Giuseppe I'm just trying `prod` and `sum` randomly... but prod increases too fast !

    `sum(volcano)` is `690907` but that would have to be about 1 byte to work, haha

    Great idea using datasets !

    @Giuseppe good catch I had completely overlooked that! duh.

    @digEmAll another thing would be the `quantile` functions for common distributions...but I have not found a way to do it golfily. might not be such a good idea.

    Other usable functions include sd and var but I did a quick brute force search on all the datasets and I didn't find any interesting "value"... but surely I missed something. The problem here is that `cat("$",)` leave us with 10 free characters at most, so a lot of datasets are unusable :(

    @digEmAll Perhaps `max`?

    I tried also max/min, but no single value is near 100K :( ... Another approach could be concatenating two numbers in cat, but that would require sep='' which takes other bytes...

    You can try ^pi or *pi combined with sum, min, max for 3 lette dataset @digEmAll

    There is only 1 letter dataset `lh`, and four 3-letters : `BOD,co2,CO2,npk` but 2 of them have numbers in the name. Also, npk contains factors so sum/max etc does not work. For BOD and lh I couldn't find any useful combination. (PS: probaly you know it but you can get all datasets names using `ls("package:datasets")` )

    @digEmAll is there a way to print only the first decimal digits of pi (excluding 3)?

    @JayCe: mmh, I'm not aware of any function doing that...

    @digEmAll asking as I am really bad at sprintf, formatC, etc... I tried several ways but none worked

  • Self-modifying Brainfuck, 16 bytes, $124444



    <.<++.+.++..../$


    Try it online!


    You didn't end up using the `:`, so you can remove it and add another `+` for $124444.

    @Nitrodon Ah right, thanks.

    After printing the `1`, why not count to `3` and then print only `3`s? You would save a byte and print a higher number.

    @12431234123412341234123 You'd need to save two bytes. Otherwise, with 15 bytes, you're only allowed up to $131199, $133333 is too much.

  • JavaScript (ES6), 19 bytes, $109,839





    _=>atob`JDEwOTgzOQ`


    Try it online!



    \$109839\$ is the highest integer \$\le 109884\$ which does not produce any digit when prefixed with '$' and encoded in base64.






    Without atob() (Node.js), 26 bytes, $86,126





    _=>'$'+Buffer('V~').join``


    Try it online!



    The concatenation of '$' with the ASCII codes of 'V' (86) and '~' (126).


    Wow `Buffer`. First time ever to acknowledge this class ;')

    @user71546 It could be done in 24 bytes for $91,126 if thousand separators were allowed. But apparently, they're not... :(

    `Buffer` constructor is deprecated, so that will get longer in future versions

    @mcfedr We don't care for code golf, as long as a working version of the interpreter is properly specified.

  • PHP, $131116 (8 bytes)


    Didn't see one for php and wanted to throw one up. I know someplace in php is a bad typecast that would cut this in half but I can't find it right now.


    $<?=ERA;

    This just takes advantage of PHP short tags and the PHP built in constants.


    Try it online!


    Ha I’ll switch it out for something else tomorrow

    Instead of `

    @IsmaelMiguel nice thanks! Got it down to 8 bytes but didn't take long enough to figure out how to get the other ~70k of my salary.

    That is quite a nice constant! Really wasn't aware of it. Also, it is usual to leave the old version, so people can still see it. But it is fine, you did a nice job!

    @Arnauld thanks! I updated the link :)

    Note that you can click on the 'Link' button in TIO and select 'Markdown' to get a link that can be pasted right away within the submission. Or even 'Code Golf submission' for a full TIO-based answer. Nice first answer, BTW!

    wow didnt knew about this constant, but I couldnt find in docs, can any one help on this?

    @Rafee it's actually not documented any place that I can find. It's a language constant that was added 17 years ago https://github.com/php/php-src/commit/f1364ebf3ead89f145af573e3b90f3503898b0ad. I found it by dumping all available constants and then just starting to grep for the shortest ones. It seems to be provided by the OS seen here https://www.gnu.org/software/libc/manual/pdf/libc.pdf on page 195.

    I think that `ERA` might be for the Japanese Emperor era data, which is about to change at Q2 next year. The D_T/D/T format constants seem to suggest that.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM