Cantor's unspeakable numbers

58

8

An unspeakable number is a number which is divisible by seven or has seven as one of its digits. A children game is to count skipping unspeakable numbers

1 2 3 4 5 6 ( ) 8 9 10 11 12 13 ( ) 15 16 ( ) 18 ...

Cantor's version of the game is the sequence defined by recursively filling in the sequence "1 2 3 4 5 6 ( ) 8..." into the gaps ( ) above.

1 2 3 4 5 6 1 8 9 10 11 12 13 2 15 16 3 18 19 20 4 22 23 24 25 26 5 6 29 30 31 32 33 34 1 36 8 38 ...

Print/output at least the first 7^7 numbers of Cantor's unspeakable number game...

While the definition is given recursively, you are not obliged to use recursion in the code.

This is , so the program with the shortest byte count wins!

Note: The sum of numbers in 1 to 7^7 is 203511962727. The last 10 numbers in that range are 823534 823535 221563 108068 823538 823539 823540 823541 823542 221565.

Pastebin dump of first 1000 iterates: http://pastebin.com/Ksiu9Svf

mschauer

Posted 2016-11-27T10:15:06.707

Reputation: 1 348

8Please provide the first 7^7 numbers of that sequence such that we can check our solutions. – flawr – 2016-11-27T10:20:42.997

2Related – Adnan – 2016-11-27T10:29:56.547

2In case anybody wants to generate some more numbers and compare results: The sum of the first 7^77 numbers in the sequence is 3336402440238885119980169136020683586413168645292341926482898521634332654984279162327502549917668322950744929983987545341421076028 – Niklas B. – 2016-11-28T23:46:18.240

Sure, the number of 1's in that sequence is 22977, which means if you pick an element out of the first 7^77 uniformly at random, you have a 2 * 10^-61 chance of it being a 1 – Niklas B. – 2016-11-29T08:10:45.337

1

In case you are interested, here is a graph showing the growth of the number of repeated ones: https://drive.google.com/file/d/0B71iQwGfNtw5NGladjdOZVhoNkk/view?usp=sharing

– Niklas B. – 2016-11-29T09:41:44.187

Thank you, @NiklasB. one can see that the depth grows polynomial and not logaritmically! – mschauer – 2016-11-29T18:56:42.580

Yeah my algorithm to compute the sum is only fast because of that fact. – Niklas B. – 2016-11-29T19:56:31.163

Answers

6

Pyth, 25 23 22 bytes

Thanks to @Maltysen for -2 bytes

.V1=+Y
?}7+PbjbT@Y~hZb

A program that prints an infinite stream.

Try it online! (Output flushed at intervals and times out at 1 min)

How it works

.V1=+Y
?}7+PbjbT@Y~hZb

Z = 0, Y = []    Implicit variable assignment
.V1              Infinite incrementing for loop with variable b, starting at 1:
   =+Y            Y = Y +
(newline)          (Implicitly print the result of the following:)
?                   If
 }7                  7 is in
    Pb                the prime factorisation of b
   +                  or
      jbT             the digits of b:
         @Y            Index into Y at index
             Z          Z
           ~h          (Increment Z)
                    else:
              b      b

TheBikingViking

Posted 2016-11-27T10:15:06.707

Reputation: 3 674

123 bytes. It works cuz 7 is prime, so divisibility is can be done through checking the prime factorization, which fits in well with the other check – Maltysen – 2016-11-27T21:15:11.113

you can post it, the main part of its yours – Maltysen – 2016-11-27T21:19:18.300

1Congratulation for winning this contest. I also like @Maltysen 's trick! – mschauer – 2016-11-30T23:06:06.147

23

Python 2, 77 75 74 70 bytes

Thanks to @MartinEnder for suggesting the limit of 9e5 which enderd up working after a change.
Thanks to @mschauer for suggesting an infinite stream, saving 4 bytes.

def f(n=0):
 i=f()
 while 1:n+=1;yield next(i)if'7'in`n`or n%7<1else n

This is a generator that yields an infinite stream of the numbers.

PurkkaKoodari

Posted 2016-11-27T10:15:06.707

Reputation: 16 699

Could you not remove the upper bound entirely? – mschauer – 2016-11-27T13:30:34.590

@mschauer Thanks, didn't think of that one. – PurkkaKoodari – 2016-11-27T13:57:06.020

if n%7<1or'7'in`n`else n might be slightly faster (same byte count), since n%7<1 is faster than checking the string, and or is short-circuiting. It's too bad that yield[n,next(i)][n%7<1or'7'in`n`] won't work. – mbomb007 – 2016-11-29T23:03:40.367

@mbomb007 I don't think speed is an issue here, but thanks. :) – PurkkaKoodari – 2016-11-29T23:04:56.873

10

Perl, 47 46 41 39 bytes

Saved 5 bytes thanks to @Dada

say$_=$_%7*!/7/?$_:$a[$b++]for@a=1..1e6

Try It Online! TIO Nexus, now with Perl support! This will truncate the output after a certain point, but if you have Perl installed, you can run it locally to produce the full output.

The code makes use of a couple of strange quirks of Perl's syntax, so I'll break down how it works below.

Code breakdown:

say$_=$_%7*!/7/?$_:$a[$b++]for@a=1..1e6
                              @a=1..1e6 #Assign the range (1..1,000,000) to the array @a
                           for          #and then loop through this list, with $_ as an alias for the list member.  As an alias, modifying $_ modifies @a.
      $_%7*!/7/?$_:$a[$b++]             #Ternary operation
      $_%7                              #Returns the residue modulo 7...
          *!/7/                         #...and multiplies it by the negation of whether or not there exists a 7 $_
                                        #Since % and * have the same operator precedence, it must be evaluated in this order
                                        #otherwise we would get (!/7/*$_)%7 instead of ($_%7)*!/7/
               ?$_                      #If the result is non-zero (i.e. truthy), then return $_
                  :$a[$b++]             #Otherwise, return the $b-th element of @a, and increment $b
   $_=                                  #Reassign the result back to $_, modifying @a
say                                     #Prints the result of the assignment, separated by newlines

Gabriel Benamy

Posted 2016-11-27T10:15:06.707

Reputation: 2 827

1say$a[@a]=$_=... to win 2 bytes if I'm not mistaken. – Dada – 2016-11-27T22:30:08.110

@Dada actually since that saves me from having to assign to $_, it saves me 5 bytes. Thanks! – Gabriel Benamy – 2016-11-27T22:39:52.283

1Oh indeed, I just had a quick look and didn't noticed that assignment in the middle.. good job :) – Dada – 2016-11-27T22:41:31.777

It is at this moment (and this moment only!) that I have understood the statement "Perl can be quite the write-only language". – haneefmubarak – 2016-11-28T04:52:24.843

@Grimy please don't edit others code. If you want to improve an answer add a comment including the improvement or post your own answer. As you probably won't reach the OP by a comment just post your own answer. – ovs – 2017-10-24T20:02:57.520

5

Haskell, 67 66 bytes

i#x|mod x 7<1||'7'`elem`show x=f!!i:(i+1)#(x+1)|y<-x+1=x:i#y
f=0#1

f is an infinite list of the numbers.

Try it online!

f starts a new iteration with 1 and an index which number to pick of 0. Whenever there's a gap we take a new iteration an pick it's ith element and continue the current iteration with i+1. If there's no gap, we take the current number x and go on without increasing i.

Edit: -1 byte thanks to @BMO.

nimi

Posted 2016-11-27T10:15:06.707

Reputation: 34 639

5

PHP, 80 (Wahooka) 57 54 bytes

While the idea is from Wahooka. I think my version is different enough to make it an own answer:

for(;;)echo$a[]=strpos(++$n,55)<-$n%7?"$n ":$a[+$b++];

Christoph

Posted 2016-11-27T10:15:06.707

Reputation: 1 489

4

MATL, 26 25 bytes

9e5:`t7\yFYA!7-A*~s:2M(2M

Try it online! with 9e5 replaced by 9e4, so that the maximum running time and output size of the online compiler are not exceeded.

How it works

This uses iteration instead of recursion. (In fact, MATL doesn't have recursion).

An array of numbers from 1 to 9e5 is first generated (this is enough, because 9e5 exceeds 7^7). Then, numbers that are multiples of 7 or have 7 as digit are identified, and replaced by 1, 2, ... The process is iterated until there are no numbers that need to be replaced.

9e5:       % Generate array of numbers [1 2 ... 9e5]. This array will become the
           % output, after some numbers have been replaced
`          % Do...while
  t        %   Duplicate the array of numbers
  7\       %   Modulo 7. Gives zero for multiples of 7
  y        %   Duplicate the array of numbers
  FYA!     %   Matrix of decimal digits, with a column for each number
  7-       %   Subtract 7 to each entry of that matrix
  A        %   Array that contains "true" for columns that only contain nonzeros;
           %   that is, for numbers that do not have 7 as digit 
  *        %   Multiply. This corresponds to a logical "and" of the two conditions.
           %   A zero indicates that the number at that index needs to be replaced
  ~        %   Logical negate. Each "true" corresponds to a number to be replaced
  s        %   Sum. This is the amount of numbers to be replaced, say n
  :        %   Push array [1 2 ... n]
  2M       %   Push array of logical values again
  (        %   Replace the numbers at the positions indicated by the logical array
           %   by the values [1 2 ... n]
  2M       %   Push n again. This is used as loop condition, so if it is nonzero
           %   the next iteration will be executed. Note that this executes one
           %   too many iterations: the exit condition is that no replacing has
           %   been needed in the current iteration; but then the current iteration 
           %   (which will be the last) was not really necessary. This does not
           %   matter; the last iteration is useless but also harmless
           % End do...while implicitly. Display implicitly

Luis Mendo

Posted 2016-11-27T10:15:06.707

Reputation: 87 464

3

Tcl, 121 Bytes

The trivial solution using infinite loop, nothing fancy..

set r 0;set n 0;while {[set r [expr $r+1]]} {if {![expr $r%7]||(7 in[split $r ""])} {puts [set n [expr $n+1]]} {puts $r}}

Ungolfed:

set r 0
set n 0
while {[set r [expr $r+1]]} {
  if {![expr $r % 7] || (7 in [split $r ""])} {
    puts [set n [expr $n+1]]
  } {
    puts $r
  }
}

hdrz

Posted 2016-11-27T10:15:06.707

Reputation: 321

You can use incr. And if tcl version >= 8.6, incr assumes the first iteration an increment of a *new* variable from 0 to 1 if that variable was not set before; so you can get rid of the first two set instructions. – sergiol – 2017-05-28T15:01:27.367

golfed by me — I removed also some non needed white space. – sergiol – 2017-05-28T15:30:01.683

The site where I posted my golfing suggestions for you has lost them, so I made a my new answer

– sergiol – 2018-05-25T23:50:48.253

3

PHP, 106 80 bytes

Thank you Ismael Miguel for help with the ternary solution and shorter loop code using for instead of while.

Could not verify the last parts of the full sequence due to PhpFiddle's 30 second max runtime. Seems to work at least up to 1K based on the sample output provided by the OP.

Golf:

for($n=1;;$n++)echo$a[]=!(strpos($n,"7")>-1||$n%7==0)?"$n ":array_shift($a)." ";

Original golfed version:

$n=1;while(1){if(!(strpos($n,"7")>-1||$n%7==0)){echo$a[]=$n." ";}else{echo$a[]=array_shift($a)." ";}$n++;}

Wahooka

Posted 2016-11-27T10:15:06.707

Reputation: 79

1for($n=1;;$n++)echo$a[]=!(strpos($n,7)>-1||$n%7==0)?"$n ":array_shift($a)." "; I don't know the byte count, but I'm sure it is a lot lower than 106 bytes. Try it out and see if it works. – Ismael Miguel – 2016-11-27T18:36:22.330

Very nice, thanks for the help. The only modification to your code was to put the first 7 in quotations which added two bytes to your 78 byte version. – Wahooka – 2016-11-27T19:11:16.317

You can save 3 bytes or so by doing for($n=1;;$n++)echo$a[]=strpos($n,"7")>-1||$n%7==0?array_shift($a)." ":"$n ";. I'm not sure if you can replace $n%7==0 with !$n%7 but it's worth a try. – Ismael Miguel – 2016-11-27T20:08:52.403

." " is not neccessary. Use for($n=1;;$n++)echo$a[]=strpos($n,"7")>-1||$n%7==0?array_shift($a):"$n "; to save 7 chars – Christoph – 2016-11-28T09:59:13.473

for($n=1;;$n++)echo$a[]=strpos($n,"7")<-1&&$n%7?"$n ":array_shift($a); gets you down to 70. – Christoph – 2016-11-28T10:05:34.813

for($n=0;;)echo$a[]=strpos(++$n,"7")<-1&&$n%7?"$n ":array_shift($a); 68. Last comment so far. – Christoph – 2016-11-28T10:11:21.483

1Keep going -6 : $n=0 is useless, "7" can be 7. – Crypto – 2016-11-28T10:43:15.337

@Crypto thx for the tip: for(;;)echo$a[]=strpos(++$n,55)<-1&&$n%7?"$n ":array_shift($a); (63 Byte) works correctly (param 2 gets covered to a char so we need 55 instead of 7). – Christoph – 2016-11-28T14:07:05.730

1why shift? for(;;)echo$a[]=strpos(++$n,55)<-1&&$n%7?"$n ":$a[++$b-1]; (58 byte). ++$b-1 because $a[null] === null – Christoph – 2016-11-28T14:13:45.767

3

Perl 6,  74 57 54  53 bytes

sub u{my@u;(1..*).map: {if $_%%7||.comb('7') {@u||=u;@u.shift} else {$_}}}
sub u{(1..*).map: {$_%%7||.comb('7')??(@||=u).shift!!$_}}
sub u{map {$_%%7||.comb('7')??(@||=u).shift!!$_},1..*}
sub u{map {$_%%7||.comb(~7)??(@||=u).shift!!$_},1..*}

Try it

Expanded:

sub u{
  map             # for each element transform using:

  { # bare block lambda with implicit parameter 「$_」

      $_ %% 7     # if it is divisible by 7
      ||          # or
      .comb(~7)   # contains the number 7 (implicit method call on 「$_」)

    ??            # then
      ( @ ||= u ) # store a new instance of the Seq into an unnamed state array if it is empty
                  # ( it is only empty the first time it is seen in this Seq instance )
      .shift      # pull one off of the front

    !!            # else
      $_          # return the value
  },

  1 .. *          # infinite range starting at one ( elements to be mapped over )
}

Test:

$ time perl6 -e'sub u{map {$_%%7||.comb(~7)??(@||=u).shift!!$_},1..*};put 203511962727 == sum u()[^7**7]'
True

real    2m45.744s
user    2m45.416s
sys     0m0.212s

Brad Gilbert b2gills

Posted 2016-11-27T10:15:06.707

Reputation: 12 713

Looks like you could save a byte by saying ~7 instead of '7'. – Sean – 2016-12-29T17:40:58.323

3

Julia, 62 bytes

x=[];j=0;for i=1:7^7;x=[x;i%7<1||('7' in "$i")?x[j+=1]:i]end;x

Nothing fancy. Uses that the sequence within the gaps is the sequence itself. Makes excessive array copies to save some bytes.

mschauer

Posted 2016-11-27T10:15:06.707

Reputation: 1 348

2

Ceylon, 202 bytes

object u satisfies{Integer*}{iterator()=>object satisfies Iterator<Integer>{variable value i=0;late Iterator<Integer>n;next()=>if(++i%7<1||'7'in"``i``")then(i<8then(n=iterator())else n).next()else i;};}

This is not a function, but an object declaration implementing an infinite sequence (Iterable). The object can be printed directly, print(u) outputs this:

{ 1, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 2, 15, 16, 3, 18, 19, 20, 4, 22, 23, 24, 25, 26, 5, 6, 29, 30, ... }

To print more, use printAll(u). The following code uses newlines, and also prints the sum (and the first 30 elements shown above):

shared void run() {
    printAll(u.take(7^7), "\n");
    print(sum({0, * u.take(7^7)}));
    print(u);
}

Here is the ungolfed and commented version:

// Prints cantor's unspeakable numbers.
//
// Question:  http://codegolf.stackexchange.com/q/101231/2338
// My answer: http://codegolf.stackexchange.com/a/101297/2338

// this object u (which is like a singleton class with its single instance)
// implements the Iterable<Integer> interface.
object u satisfies {Integer*} {
    // That interface has just one formal method,
    // `shared formal Iterator<Integer> iterator()`.
    // Lets implement it by ...
    iterator()
    // ... providing for each call ...
            =>
                // ... a new (anonymous) object, which
                // implements the Iterator<Integer> interface.
                object satisfies Iterator<Integer> {
                    // This is the counter (the type `Integer`
                    // is longer than `value`, so we infer it).
                    // We start at 0.
                    variable value i = 0;
                    // This is a nested Iterator. It will be
                    // initialized when first needed, so we don't
                    // get an endless recursion when creating the
                    // first iterator.
                    late Iterator<Integer> n;
                    // `shared formal Integer next()` is the single method
                    // of Iterator which needs to be implemented.
                    next()
                    // each time it is called, the following
                    // expression will be evaluated.
                            =>
                                // increment the counter, then check if it
                                // is an unspeakable number.
                                if (++i % 7 < 1 || '7' in "``i``")
                                then
                                    // if so, take the nested iterator (and the
                                    //  first time, for i == 7, create it first),
                                    // and take its next element.
                                    (i < 8 then (n = iterator()) else n).next()
                                else
                                    // otherwise, just return i.
                                    i;
                };
}

Paŭlo Ebermann

Posted 2016-11-27T10:15:06.707

Reputation: 1 010

2

Ruby, 80 bytes

l=->x{x%7==0||x.to_s[/7/]};a=(1..100);b=a.reject &l p a.map{|x|!l[x]?x:b.shift}

First submission, I'm sure it can be improved :)

Christopher Lates

Posted 2016-11-27T10:15:06.707

Reputation: 121

1Welcome to PPCG! Does this go up to at least 7^7 (i.e. 823543), and does it account for numbers which contain the digit 7, i.e. 17? – ETHproductions – 2016-11-28T17:07:17.563

It sure didn't. Fixed now. Thought that problem was a little too easy :) – Christopher Lates – 2016-11-28T17:32:39.460

Nice, but I'm not sure it qualifies yet. The number after 34 (which is 8 currently) should be 7, but because 7 is an unspeakable number, the program should start a third iteration and instead print 1. – ETHproductions – 2016-11-28T17:56:52.250

2

Dyalog APL, 39 bytes

{(⍵⍴⍨⍴i)@(i←⍸('7'∊¨⍕¨⍵)∨0=7|⍵)⊢⍵}⍣≡⍳7*7

⍳7*7 is 1 2 3...77

{ }⍣≡ is the fixed point operator - apply a function repeatedly until the result stabilises

A@I⊢B amend operator - replace the elements at indices I in B with A

0=7|⍵ bitmask for where the argument is divisible by 7

'7'∊¨⍕¨⍵ bitmask for where the decimal formatting of the argument contains a 7

or

at what indices is either of the above bitmasks true?

i← assign to i

⍵⍴⍨⍴i reshape the argument to the number of elements in i

ngn

Posted 2016-11-27T10:15:06.707

Reputation: 11 449

This is nice. Does it help if you multiply ⍳7*7 with the bitmask and take the fixpoint of amending the zeros in the sequence? – mschauer – 2016-11-28T20:59:04.433

2

C 157 155 Bytes

int c[999999],r;main(_,p){if(_){p=--_;c[_]=1;for(;;){printf("%d ",c[_]);main(0,++_+1);c[_]=r?_+1:c[p++];}}else!p?r=1:p%7?p%10-7?main(0,p/10):(r=0):(r=0);}

It looks right, I didn't bother to fully check. Goes up to 999999 which is apparently large enough.

Ungolfed version:

int cantor_n[1000000];

int cantor_n_safe(int x) {
    if (!x) return 1;
    if (x % 7 == 0) return 0;
    if (x % 10 == 7) return 0;
    return cantor_n_safe(x / 10);
}

int main(_, prev_index) {
    prev_index = --_;
    cantor_n[_] = 1;
    for(;;) {
        printf("%d ", cantor_n[_]);
        _++;
        if (!cantor_n_safe(_+1)) {
            cantor_n[_] = cantor_n[prev_index++];
        } else {
            cantor_n[_] = _+1;
        }
    }
    return 0;
}

Partially golfed version:

int c[999999];int r;
safe(x){ 
    !x?
        r=1:
        x%7?
            x%10-7?
                safe(x/10):
                (r=0):
            (r=0);
}

main(_){
    int p;
    p=--_;
    c[_]=1;
    for(;;){
        printf("%d ",c[_]);
        safe(++_+1);
        if (!r) {
            c[_]=c[p++];
        } else {
            c[_]=_+1;
        }
    }
}

LambdaBeta

Posted 2016-11-27T10:15:06.707

Reputation: 2 499

Do you need the braces after else? – Zacharý – 2016-11-28T22:40:57.560

I do not, thank you. I also don't technically need the braces around (r=0) most of the time. But some compilers are picky. I'm too lazy to check the spec right now. – LambdaBeta – 2016-11-28T23:17:09.943

2

R, 86 bytes

x=1;while(T<7^7){T=T+1;x[T]=if(!T%%7|7%in%el(strsplit(c(T,""),""))){F=F+1;x[F]}else T}

Uses R's Truthy built-in T (initialized to TRUE/1) to count the numbers in the the sequence and the Falsy value F (initialized to FALSE/0) to count the unspeakables. Other than that the program simply checks whether each number is divisible by seven or contains the number.

Billywob

Posted 2016-11-27T10:15:06.707

Reputation: 3 363

-4 bytes replacing 7%in%el(strsplit(c(T,""),"")) by 55%in%utf8ToInt(paste(T))? (not tested) – JayCe – 2018-05-26T14:20:07.070

2

C - 115 bytes

s[99],r;g(x){return x%10-7&&(!x||g(x/10));};f(i){(r=++s[i])%7&&g(r)||f(i+1);}main(){for(;;f(0),printf("%d\n",r));}

EDIT: Thanks to @mschauer who pointed out I missed some things.

orion

Posted 2016-11-27T10:15:06.707

Reputation: 3 095

Nice approach. Two remarks. r%10-7 does only captures trailing sevens and don't corrupt your heap: stack depth grows polynomially... s[99] is safe. – mschauer – 2016-11-29T18:21:13.790

2

Javascript, 80 bytes

n=[]
r=l=>(m=n[l]=++n[l]||1,!/7/.test(m)m%7?m:r(l+1))
for(;;)console.log(r(0))

Since there is only a minimum requirements but not a maximum requirements, this solution continues to output indefinitely.

To verify that the algorithm is correct, you can execute the same code printing only the last 10 numbers and the sum:

n = []
r = l => (m = n[l] = ++n[l] || 1, !/7/.test(m) && m % 7 ? m : r(l + 1))
var tot = 0
for (i = 0; i + 1; i++) {
    v = r(0)
    tot += v
        if (i > Math.pow(7, 7) - 11) {
        console.log(v)
    }
    if (i === Math.pow(7, 7) - 1) {
        console.log(tot)
        break
    }
}

Sullof

Posted 2016-11-27T10:15:06.707

Reputation: 31

SyntaxError: missing ) in parenthetical – l4m2 – 2018-05-26T13:01:25.060

1

Mathematica, 82 bytes

Nest[#2&[i=1,If[Or@@(#==7&)/@IntegerDigits@#,i++,#]&/@#]&,Table[i,{i,7^7}],20]

J. Antonio Perez

Posted 2016-11-27T10:15:06.707

Reputation: 1 480

1

JavaScript 81 bytes

Original (98 bytes)

for(c=0,i=1;i<=Math.pow(7,7);i++)/7/.test(i)||i%7==0?(6==c?c=1:c++,console.log(c)):console.log(i);

Golfed

p=console.log;for(c=0,i=1;i<9e5;i++)/7/.test(i)||i%7==0?(6==c?c=1:c++,p(c)):p(i);

Richard Sime

Posted 2016-11-27T10:15:06.707

Reputation: 21

Welcome to the site! I don't know a lot about javascript, but could you do something like p=console.log;for(c=0,i=1;i<=Math.pow(7,7);i++)/7/.test(i)||i%7==0?(6==c?c=1:c++,p(c)):p(i);? – James – 2016-11-28T19:53:32.790

Thanks @DrMcMoylex, that dropped a few more bytes. I don't doubt there's still room for improvement. – Richard Sime – 2016-11-28T20:06:00.950

Glad I could help! One other thing I just realized, is you could do 9e5 instead of Math.pow(7,7), since the challenge said: Print/output AT LEAST the first 7^7 – James – 2016-11-28T20:09:25.010

Yep, nice shot Doc! This allowed me to drop an equals from a comparison operator too. – Richard Sime – 2016-11-28T20:29:15.430

It doesn't seem to do what's expected. When filling the gaps, you apparently have to apply the rules again rather than just resetting a counter (see this part of the sequence: 34 1 36 **8** 38). But for what it's worth, the current version could be golfed some more: for(c=i=0;++i<9e5;)console.log(!/7/.test(i)&&i%7?i:c++%6+1). – Arnauld – 2016-11-30T04:29:54.697

Seems wrong, a(37) is 8, not 2 – l4m2 – 2018-05-26T13:17:41.873

1

Befunge, 100 or 156 bytes

This first version is the more portable of the two, limiting itself to 7-bit memory cells, which is what you get in the reference interpreter.

"O":0>\#09#:p#-:#1_v<0$.< 
9\*"~"g9+1:+1::p00:<+3$_^#g01$$<v"~":/"~"p9g00%"~"::+1+g9\*"~"+g
:#15#+5#g+#0%#17#\-#/!#+\#5:#5_^>%00g1+9p"~"/00g2+9p::7%!10>>p#0

The second version only works with interpreters that have 32-bit memory cells, and thus isn't strictly standard Befunge, but that lets us store larger values in memory without having to split them across cells.

"O":0>\#09#:p#-:#1_v<0$.< 
%7::p9g00:+1g9:p00:<+1$_^#g01$$<v01!
:#15#+5#g+#0%#17#\-#/!#+\#5:#5_^>p#0

In both cases the program runs indefinitely, but the first version will overflow around the 2 million mark, while the second version should get up to the max int value (around 2 billion).

You can Try it online, but you'll need to kill the process to prevent it from trying to run forever.

James Holderness

Posted 2016-11-27T10:15:06.707

Reputation: 8 298

1

Clojure, 130 bytes

#(let[R(range(inc %))](rest((reduce(fn[[r s]i](if(or(=(mod i 7)0)((set(str i))\7))[(assoc r i(r s))(inc s)][r s]))[(vec R)0]R)0)))

Basic reduce, keeping track of contents of the result vector and how many values have been skipped. The last 0 takes first element of the reduced [r s], rest drops first element of the 0-indexed result.

NikoNyrh

Posted 2016-11-27T10:15:06.707

Reputation: 2 361

1

Perl6, 41 bytes

put {($_=++$)%%7|m/7/??@_[$++]!!$_}…1e6

Grimmy

Posted 2016-11-27T10:15:06.707

Reputation: 12 521

1

Tcl, 64 bytes

while 1 {puts [expr {[incr i]%7&&7ni[split $i ""]?$i:[incr s]}]}

Try it online!

sergiol

Posted 2016-11-27T10:15:06.707

Reputation: 3 055

nice! much shorter than mine… – hdrz – 2018-05-26T09:36:15.547

This writes "...33 34 7 36 8 38..." instead of "...33 34 1 36 8 38..." – mschauer – 2018-05-28T13:27:51.867

@mschauer: Ok, I will fix it when I have time... – sergiol – 2018-06-05T14:38:34.010

@hdrz I tried your solution and it has the same issue mschauer told about! – sergiol – 2018-06-05T14:39:19.430

1

JavaScript, 64 bytes

for(f=n=>!/7/.test(m=++n[0])*m%7?m:f(n.t=n.t||[0]);;)alert(f(f))

output=[];index=0;for(f=n=>!/7/.test(m=++n[0])*m%7?m:f(n.t=n.t||[0]);index<100;)output[index++]=f(f);console.log(output.join(','))

l4m2

Posted 2016-11-27T10:15:06.707

Reputation: 5 985

p.s. to compare with the other few (console.log) JavaScript answers, it's 70 bytes – l4m2 – 2018-05-26T13:10:14.740

1

Japt, 25 bytes

[]L³õ@pX%7«/7/tX ?X:UgV°

Test the sum and last 10 elements.

Generates first 1,000,000 entries of the sequence and prints them. One million is the shortest number over 7**7 == 823543 in Japt.

The trailing newline is significant, as it activates the implicit assignment to U.

Generating the list only takes around a second, but outputting the entire array will likely make your browser hang.

Unpacked & How it works

[]L³õX{UpX%7&&!/7/tX ?X:UgV++

[]                            Assign empty array to U
  L³õX{                       Map over 1 to 1,000,000 inclusive...
         X%7&&                  If X is not divisible by 7 and
              !/7/tX            X does not have a digit 7
                     ?X:UgV++   then X, otherwise the next element already in U
       Up                       Push it to the end of U

                              Implicit print U

Uses the property that the recursive definition can be resolved by looking at the already generated sequence.

Bubbler

Posted 2016-11-27T10:15:06.707

Reputation: 16 616