Extension of the Game of Sevens

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 the base 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 format base as its usual decimal representation.

  • start and end are two strings that specify the range of numbers to be output, expressed in the given base. If base is G and start is 10 and end is 1F, you need to output 10 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 what elim is, to be explained soon.

  • elim is a single character and must be a valid digit in the given base. All numbers containing the digit elim or are multiples of elim 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 , 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>

Weijun Zhou

Posted 2018-01-26T16:44:07.027

Reputation: 3 396

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.073

11

Welcome to PPCG! This is a nice first post, but I have few recommendations: Avoid very strict Input / Output formats (base,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 – 2018-01-26T17:01:06.500

@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.003

1@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 and elim 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.163

5For 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.617

In 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

Answers

10

Emojicode, 141 116 bytes

thanks to @NieDzejkob for 25 bytes!

abcdi⏩c➕1d❎0i b☁️i ab ai a

Try it online!

				
  a b c d		 4 arguments of type  (integer)
   i  ⏩ c  ➕ 1 d 		 for i in range(c, d+1)
      			   if cond_a and cond_b
      ❎  0   i b		     cond_a: i%b != 0
      ☁️   i a   b a	     cond_b: i in base-a doesnt have b in base-a
    				   then
        i a			     print i in base-a
    
  

betseg

Posted 2018-01-26T16:44:07.027

Reputation: 8 493

3-1 for language choice ಠ_ಠ – Rod – 2018-01-26T18:13:45.600

3You can just post a closure, which is the emojicode equivalent of a lambda. This should save you some bytes. – NieDzejkob – 2018-01-26T18:17:14.223

5

Jelly,  12  11 bytes

-1 thanks to Erik the Outgolfer (use of "order" in place of divisible with swapped arguments, ḍ@)

r/ọÐḟ⁵bċÐḟ⁵

A full program taking three inputs as command line arguments, all of which employ decimal notation - a list [start, end], and two numbers, base and elim - which prints the Jelly representation of a list of lists, where each represents the digits of a number in base and each digit is a decimal number (e.g. 1043 in base 20 would be [2,12,3], i.e. 2×202+12×201+3×200).

Try it online!

A small note: this won't work for ranges that include negative values, but the linked challenge starts from 1 and counts up.

How?

r/ọÐḟ⁵bċÐḟ⁵ - Main link: list, [start, end]; number, base
 /          - reduce [start, end] with:
r           - inclusive range => [start, start+1, ..., end]
   Ðḟ       - filter discard if:
     ⁵      -   program's 5th argument (the 3rd input), elim
  ọ         -   order (how many times the element is divisible by elim, or 0 if not)
      b     - convert to base "base"
        Ðḟ  - filter discard if:
          ⁵ -   program's 5th argument (the 3rd input), elim
       ċ    -   count (0 if elim is not a digit)

Jonathan Allan

Posted 2018-01-26T16:44:07.027

Reputation: 67 804

ḍ@ can be ;) (btw I'd have posted rọÐḟ⁶b⁵ċÐḟ⁶...) – Erik the Outgolfer – 2018-01-26T17:45:10.863

Ah yeah, never used the sixth arg! – Jonathan Allan – 2018-01-26T17:49:29.717

1As usual, would you mind expanding it and elaborating how it works? – Weijun Zhou – 2018-01-26T17:51:01.520

An alternative for ọÐḟ could be %Ðf – Mr. Xcoder – 2018-01-26T17:59:50.503

2

Julia 0.6, 69 bytes

f(b,e,r,g=filter)=g(z->!contains(z,base(b,e)),base.(b,g(x->x%e>0,r)))

Inputs are base, elim, start:end where start:end is a UnitRange. as base 10 integers. Outputs a list of strings of the numbers in the given base. Filters for divisibility in integer form, uses base. to elementwise convert to strings, then filters on digit containment. Called example: f(10,3,1:100)

Try it online!

gggg

Posted 2018-01-26T16:44:07.027

Reputation: 1 715

1I hadn't thought of using defaults in a signature to alias subroutines, I'll have to remember that for future Perl 6 posts. – Brad Gilbert b2gills – 2018-01-27T17:55:19.497

1

Japt, 16 bytes

Hastily rewritten after the spec was changed to allow decimal input so can probably be improved upon.

Takes input in the order start, end, base, elim and outputs an array of numbers in the given base.

òV kvX msW køXsW

Try it


Explanation

                   :Implicit input of integers U=start, V=end, W=base & X=elim
òV                 :[U,V]
   k               :Remove
    vX             :  elements divisible by X
       m           :Map
        sW         :  Convert to base-W string
           kø      :Remove elements containing
             XsW   :  X converted to a base-W string
                   :Implicit output of resulting array

Shaggy

Posted 2018-01-26T16:44:07.027

Reputation: 24 623

For values of elim that are larger than 10, yet smaller than the base, this will fail to remove elements that contain the digit. For example for 0,35,12,11 the output erroneously contains 23=(1,11)base12 – gggg – 2018-01-26T22:59:02.227

@gggg, it looks like the spec was changed since I posted this; originally, elim was specified to be a single digit (i.e., 0-9) rather than a single character in the input base. – Shaggy – 2018-01-26T23:07:56.450

Fair enough, I found the spec to be super confusing. – gggg – 2018-01-26T23:17:16.273

By "single digit" I mean a digit in the corresponding base. Hence "A" (or if you prefer to express it as a 10) is a digit in a hexadecimal base. Sorry about the confusion. – Weijun Zhou – 2018-01-27T09:21:36.780

Would you be kind enough to modify the code upon the above clarification? Thank you and sorry again for the confusion. – Weijun Zhou – 2018-01-27T09:25:33.963

@gggg Thank you for offering a test case. I will retest all existing answers. And sorry for the confusion. – Weijun Zhou – 2018-01-27T09:28:12.153

@WeijunZhou: Updated. Will update my JS one later. – Shaggy – 2018-01-27T15:07:48.927

Please accept my heartfelt gratitude. – Weijun Zhou – 2018-01-27T15:11:13.553

@Shaggy Would you mind updating the explanation? – Weijun Zhou – 2018-02-09T19:20:26.080

1@WeijunZhou: Done – Shaggy – 2018-02-09T19:30:33.113

1

Python 2, 102 94 bytes

lambda b,e,l,u:[i for i in range(l,u+1)if i%e*x(i,b,e)]
x=lambda n,b,e:n<1or(e-n%b)*x(n/b,b,e)

Try it online!

Input and output is in base 10.

ovs

Posted 2018-01-26T16:44:07.027

Reputation: 21 408

1

JavaScript, 82 bytes

A quickie before I hit the boozer! Takes input in base-10 in the order base, elim, start & end and outputs a space delimited string of base-10 numbers with a single trailing space.

(b,l,s,e)=>(g=o=>++s>e?o:g(s%l&&!~s[t=`toString`](b).search(l[t](b))?o+s+` `:o))``

Try it online

Shaggy

Posted 2018-01-26T16:44:07.027

Reputation: 24 623

This one has the problem as the Japt one. Would you mind modifying it a bit? – Weijun Zhou – 2018-01-27T09:27:17.547

@WeijunZhou: Updated. – Shaggy – 2018-01-28T11:22:15.950

Thank you very much. You can update the "explanation" part of the other answer whenever you like to. No hurry. – Weijun Zhou – 2018-01-28T11:25:27.247

@WeijunZhou: I assume you mean on my Japt solution, rather than this one? I'll be updating when I get back to my computer tomorrow. – Shaggy – 2018-01-28T11:27:03.033

Yes, my bad. I edited the comment right away but you still saw the original one ... Sorry about it. – Weijun Zhou – 2018-01-28T11:28:07.370

1

Perl 6,  94  57 bytes

->\a,$b,\c,\d {grep {!/$b/},grep({$_%$b.parse-base(a)},[...] (c,d)».parse-base(a))».base(a)}

Test it (94)

Since the rules have changed:

->\b,$e,\r{grep {!/"$e.base(b)"/},grep(*%$e,r)».base(b)}

Test it ( Int, Int, Range )
Output is a list of strings in the base

Expanded

->
  \b,  # base  (Int)
  $e,  # elim  (Int)
  \r   # range (Int Range)
{
  grep
    {!/"$e.base(b)"/},  # remove the values that contain the character

    grep(
      * % $e,           # remove values that are divisible by elim
      r                 # the input Range

    )».base(b)          # convert each into base 「b」
}

Brad Gilbert b2gills

Posted 2018-01-26T16:44:07.027

Reputation: 12 713

Thank you for your interest and effort, also for writing a test. Learned a lot. – Weijun Zhou – 2018-01-27T18:55:47.987

0

Java 8, 92 bytes

(b,k,s,e)->{String r="",t;for(;s<=e;r+=t.contains(k)?"":t+" ")t=b.toString(s++,b);return r;}

Input as Integer (base), String (elem), int (start), int (end).

Explanation:

Try it online.

(b,k,s,e)->{              // Method with the four parameters, and String return-type
  String r="",            //  Result-String, starting empty
         t;               //  Temp-String
  for(;s<=e;              //  Loop from start to end (inclusive)
      r+=                 //    After every iteration: append the result-String with:
         t.contains(k)?   //     If the temp-String contains the elem we exclude
          ""              //      Don't append anything to the result-String
         :                //     Else:
          t+" ")          //      Append the temp-String + a space
    t=b.toString(s++,b);  //   Convert the number to the given base and set the temp-String
  return r;}              //  Return the result-String

The three test cases are inputted like this:

16,"7",16,31
10,"3",1,100
16,"A",151,192

Kevin Cruijssen

Posted 2018-01-26T16:44:07.027

Reputation: 67 575