8
1
Introduction
Output all the numbers in specific base that would appear in an adapted version of the game of seven.
Challenge
Your task is to output all the numbers in a given base in a given range, skipping the ones matching certain conditions.
You will be given four inputs: base
elim
start
and end
. The roles of the four variables are as follows:
base
specifies what base we are using for the other three variables, and also for output. One way to express it is using a single character that is '8', '9' or a capital letter from 'A' to 'Z', using 'A' for decimal system, and 'G' for hexadecimal system. The bases expected to be supported are 8 to 35 (inclusive). This is just my suggested way to express thebase
and I will use it in the Example Input and Output section, but it is also fine to use your own way to express it. For example, you may choose to formatbase
as its usual decimal representation.start
andend
are two strings that specify the range of numbers to be output, expressed in the givenbase
. Ifbase
isG
andstart
is10
andend
is1F
, you need to output10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
, but you also need to eliminate some out them based on whatelim
is, to be explained soon.elim
is a single character and must be a valid digit in the givenbase
. All numbers containing the digitelim
or are multiples ofelim
should be eliminated from the list to generate the final output.
In the case above, if elim
is 7
, then 17
need to be eliminated because it contains the digit 7
. 15
and 1C
also need to be eliminated because they are multiples of 7
. So the final output would be 10 11 12 13 14 16 18 19 1A 1B 1D 1E 1F
Test Cases
Input -> Output
G,7,10,1F -> 10 11 12 13 14 16 18 19 1A 1B 1D 1E 1F
A,3,1,100 -> 1 2 4 5 7 8 10 11 14 16 17 19 20 22 25 26 28 29 40 41 44 46 47 49 50 52 55 56 58 59 61 62 64 65 67 68 70 71 74 76 77 79 80 82 85 86 88 89 91 92 94 95 97 98 100
G,A,96,C0 -> 97 98 99 9B 9C 9D 9E 9F B0 B1 B2 B3 B5 B6 B7 B8 B9 BB BC BD BF C0
The third test case is added after the original post. All the answers posted before the edit has been tested and passed the third test.
Specs
The input will always be valid so don't worry about exception handling.
This is code-golf, the lowest number of bytes wins.
You can take input and provide output through any standard form, and you are free to choose the format.
As usual, default loopholes apply here.
This is based on the (real-life version of) the game of sevens.
I require
base
to be at least 8 purely due to personal taste. I just don't want to see the number of digits in the sequence grow too fast.
Scoreboard
Snippet taken from this question. Run the snippet to get the scoreboard.
var QUESTION_ID=154147,OVERRIDE_USER=77134;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;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} /* font fix */ body {font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;} /* #language-list x-pos fix */ #answer-list {margin-right: 200px;}
<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>
You state a preference that we only support bases
>=8
but you should really explicitly specify the upper and lower bounds of the range of bases we need to support. – Shaggy – 2018-01-26T16:54:54.617@Shaggy I thought one can figure it out from the requirement that
base
is a single character but anyway I have updated the question. Thank you for your feedback. – Weijun Zhou – 2018-01-26T16:57:36.07311
Welcome to PPCG! This is a nice first post, but I have few recommendations: Avoid very strict Input / Output formats (
– Mr. Xcoder – 2018-01-26T17:01:06.500base,elim,start,end
, 'A' for decimal system, 'G' for hexadecimal system), try to format your test cases in a way that is easy to use and consider using the Sandbox in order to receive feedback prior to posting to the main site. Overall, this is a good first challenge!@Mr.Xcoder Thank you for your advice. I will edit it and maybe you can take a look a while later? – Weijun Zhou – 2018-01-26T17:04:00.127
1
@WeijunZhou Sure, I’ll try to take a look at it later. Also feel free to reach us in chat if you encounter difficulties while editing and / or want tips.
– Mr. Xcoder – 2018-01-26T17:06:12.0031@Mr.Xcoder I have finished the edit. You can also directly edit the question to make it better and I will try to learn from your edit. – Weijun Zhou – 2018-01-26T17:10:06.927
1@WeijunZhou I'd also suggest making the input formats for
start
,end
andelim
more lenient. – Erik the Outgolfer – 2018-01-26T17:17:23.520@EriktheOutgolfer Not sure about this ... especially for
elim
. I expect it to be a valid digit ... using something like the decimal representation for it is somewhat confusing ... – Weijun Zhou – 2018-01-26T17:24:21.1635For the
"G,7,10,1F"
input a fully flexible approach would allow, for example,[16,7,16,31]
as input and[[1,0],[1,1],[1,2],[1,3],[1,4],[1,6],[1,8],[1,9],[1,10],[1,11],[1,13],[1,14],[1,15]]
as output. (Note that the first answer assumed some of this had been allowed already, since it's pretty standard - but it is totally up to you). – Jonathan Allan – 2018-01-26T17:27:14.617In Jelly, I estimate I can get it to ~14 bytes using decimal inputs and representing the digits in the output in decimal, and I estimate that I'll need at least ~30 bytes to be able to get input in the current format in the post, and I feel that's an unnecessary complication to the challenge. – Erik the Outgolfer – 2018-01-26T17:35:23.233
@EriktheOutgolfer Accepted. You can use that format of input and output. – Weijun Zhou – 2018-01-26T17:36:57.773
Would a trailing or leadin delimiter in the output be permitted? – Shaggy – 2018-01-26T18:02:09.613
1@Shaggy As I have relaxed a lot on the input and output format since the original post, the answer is now yes. – Weijun Zhou – 2018-01-26T18:04:21.260