Note: this challenge involves downloading and sifting through HTML webpages. If your language cannot handle this you might not want to participate in this challenge.


There are always discussions over in The Nineteenth Byte Chat about who leads the starboard. So, lets help everyone out and count the total amount of stars per user in the chat.


Given an positive integer N which is greater than zero, calculate the leader(s) of the starboard of the last N starred messages in the chat. These messages can be viewed here. Hint: each page has 50 starred messages. Output will be a list of the top 5 users by amount of starred messages. A bonus of -15% off your byte count will be granted if you can display the usernames of those users, but no penalty will be given if you simply display the user id numbers. Please note that there is profanity in some of the starred messages. If you are sensitive to this type of language, view the page with caution.

Examples (Image is current starboard as of writing this challenge):

enter image description here

  • (RED) Input: 5 Output (With bonus): [Geobits Sp3000 PhiNotPi Seadrus]
  • (BLUE) Input: 10 Output (Without bonus): [51024 17335 24697 116494 129255]
  • (GREEN) Input: 14 Output (Without bonus): [51024 116494 141697 17335 24697]

Extra stuff:

Ties in the top 5 will be sorted by lowest to highest user id number. If there is less than five users, just output the leaderboard with empty slots at the end. Input and output can be in any format. Output does not need to be capitalized. If input is greater than 50, you must still count the messages on page 2, page 3, etc. You may assume that input will always be under 2^31, and will also not be so large that it 1) is larger than the amount of starred messages that there is and 2) will not crash the program (by making arrays to big, running out of memory, etc.).

This is , shortest code in bytes wins!


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, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

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

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

var QUESTION_ID=62182,OVERRIDE_USER=36670;function answersUrl(e){return"http://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"http://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;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-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("{{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 SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;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>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></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>{{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>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

  • 3
    \$\begingroup\$ Thanks. I've been idly curious about this for a while now, and didn't want to bother writing something to find out. Now others will do it for me :) \$\endgroup\$
    – Geobits
    Commented Oct 30, 2015 at 3:26
  • 11
    \$\begingroup\$ Before anyone asks, chat does not have an official API. \$\endgroup\$
    – Alex A.
    Commented Oct 30, 2015 at 3:27
  • \$\begingroup\$ Does the URL have to count in the byte count? Just noticed that TeaScript / JavaScript will have issues with Cross-origin resource sharing \$\endgroup\$
    – Downgoat
    Commented Oct 30, 2015 at 4:01
  • 1
    \$\begingroup\$ @Vɪʜᴀɴ It would be hard to judge which characters to remove that are part of the url, do you think allowing everyone to remove 70 characters (roughly the length of the url) would help this problem? \$\endgroup\$
    – GamrCorps
    Commented Oct 30, 2015 at 4:12
  • 1
    \$\begingroup\$ I have been immortalized in this past :D \$\endgroup\$ Commented Oct 30, 2015 at 18:48

1 Answer 1

  • I' m so sorry for being slow but reading starred messages while coding was so hilarious and dilatory, this could have kept my mood up for a month.

  • Edit: Yes, I found it, the tie and duplicate ids issues are both fixed up harmonically. The trick is that the old code sorts the user-ids by descending number of stars, so I twisted some lines of my program in a way that it sorts users according to 99-n°_stars; since 99 is way bigger than the top hit star-cap (hopefully - I assumed), sorting the result by increasing number of stars kills both birds with one stone, descending stars with ascendant user-ids.

BrownRecluse, without bonus = 536 with bonus = 551-15% = 468 b

U=New(URL);P=New(Parser);L=New(Stack);t=New(Stack);v='http://chat.stackexchange.com/rooms/info/240/the-nineteenth-byte?tab=stars&page=';j=input();a=0;for i=1to j\50+1do begin U.Location=v+i;U.get;P.Parse(U.Data);x=New(RegEx);x.Data=U.Data;x.Mask='users/(\d*)/(\S*)".*?"times">(\d*?)<';while(x.Match)and(a<j)do begin L.Push(Format('%3d%9s%s',[99-x.Value[3],x.Value[1],x.Value[2]]));a=a+1;end;end;L.sort;i=0;for each L as y do if(not y.empty)and(not t.find(y.right(y.Length-12)))and(i<5)then begin y.delete(1,12);i=i+1;t.push(y);end;output(t.join(' '));




mego rainbolt alex-a lembik v




aditsu mego rainbolt alex-a lembik


  • This program (including bonus) doesnt support unicode characters - I'm sorry Vɪʜᴀɴ!

  • This program works based on the standard feature that each page contains almost 50 starred messages by default.

  • See clearly that 60 and 90 messages are contained within the first two pages, whilst the outputs differ.

  • This is the download page of this programming language in case it is not in your possession

  • In case needed, this is the bonusless program of 485 b

    U=New(URL);P=New(Parser);L=New(Stack);t=New(Stack);v='http://chat.stackexchange.com/rooms/info/240/the-nineteenth-byte?tab=stars&page=';j=input();a=0;for i=1to j\50+1do begin U.Location=v+i;U.get;P.Parse(U.Data);x=New(RegEx);x.Data=U.Data;x.Mask='users/(\d*)/(\S*)".*?"times">(\d*?)<';while(x.Match)and(a<j)do begin L.Push(Format('%3d%9s',[99-x.Value[3],x.Value[1]]));a=a+1;end;end;L.sort;i=0;for each L as y do if(not y.empty)and(not t.find(y.right(y.Length-3)))and(i<5)then begin y.delete(1,3);i=i+1;t.push(y);end;output(t.join(' '));




169713    107051    141888     94625    116494




50454    169713    107051    141888     94625

If there was incoherence between results my code isn't taking the blame!

  • 1
    \$\begingroup\$ Why are there two alex-as in the output? \$\endgroup\$
    – feersum
    Commented Nov 3, 2015 at 18:24
  • \$\begingroup\$ @feersum fixed. \$\endgroup\$
    – Abr001am
    Commented Nov 3, 2015 at 20:15

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.