Skip to main content
briefly explain your changes (corrected spelling, fixed grammar, improved formatting)
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142

CJam, 80 77 65 5757 54 Characters

Mr{s:C_,{:H<M_,H->=C\_H(+_@>=!*_CH@-@}g:T>+:MCT<_O@-+:O,A<Ci(*}h;

Explanation soon ...How it works:

Basic idea is that for each countdown number C, check if the first H digits are equal to the last H digits of the resultant string, where H goes from number of digits in C to 0

Mr                                    "Put an empty string and input on stack";
  { ... }h;                           "Run while top element of stack is true, pop when done";
s:C                                   "Store string value of top stack element in C"
   _,                                 "Put the number of characters in C to stack";
     { ... }g                         "Run while top element of stack is true";
:H<                                   "Store the digit iteration in H and slice C";
   M                                  "M is the final output string in making";
    _,H-                              "Take length of M and reduce H from it";
        >                             "Take that many digits of M from end and..."
         =!_                          "Compare with first H digits of C, negate and copy";
            CH@                       "Put C and H on stack and bring the above result to top of stack";
               -                      "Reduce H if the matched result was false";
                @                     "Bring the matched result on top in order continue or break the loop"
             :T                       "Store top stack element in T after the loop";
               >+:M                   "Take everything but first T digits of C and add it to M and update M";
                   CT<_               "Take first T digits of C and copy them";
                       O@             "Put saved digits on stack, and rotate top three elements";
                         -            "Remove all occurence of first T digits of C from O";
                          +:O         "Add first T digits of C to O and update O";
                             ,A<      "Compare number of saved digits with 10";
                                Ci(   "Decrement integer value of C and put it on stack";
                                   *  "If number of saved digits greater than 9, break loop";

CJam, 80 77 65 57 Characters

Mr{s:C_,{:H<M_,H->=C\_H(+_@!*}g:T>+:MCT<_O@-+:O,A<Ci(*}h;

Explanation soon ...

CJam, 80 77 65 57 54 Characters

Mr{s:C_,{:H<M_,H->=!_CH@-@}g:T>+:MCT<_O@-+:O,A<Ci(*}h;

How it works:

Basic idea is that for each countdown number C, check if the first H digits are equal to the last H digits of the resultant string, where H goes from number of digits in C to 0

Mr                                    "Put an empty string and input on stack";
  { ... }h;                           "Run while top element of stack is true, pop when done";
s:C                                   "Store string value of top stack element in C"
   _,                                 "Put the number of characters in C to stack";
     { ... }g                         "Run while top element of stack is true";
:H<                                   "Store the digit iteration in H and slice C";
   M                                  "M is the final output string in making";
    _,H-                              "Take length of M and reduce H from it";
        >                             "Take that many digits of M from end and..."
         =!_                          "Compare with first H digits of C, negate and copy";
            CH@                       "Put C and H on stack and bring the above result to top of stack";
               -                      "Reduce H if the matched result was false";
                @                     "Bring the matched result on top in order continue or break the loop"
             :T                       "Store top stack element in T after the loop";
               >+:M                   "Take everything but first T digits of C and add it to M and update M";
                   CT<_               "Take first T digits of C and copy them";
                       O@             "Put saved digits on stack, and rotate top three elements";
                         -            "Remove all occurence of first T digits of C from O";
                          +:O         "Add first T digits of C to O and update O";
                             ,A<      "Compare number of saved digits with 10";
                                Ci(   "Decrement integer value of C and put it on stack";
                                   *  "If number of saved digits greater than 9, break loop";
added 3 characters in body
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142

CJam, 80 77 6565 57 Characters

Probably not at all optimized, but a After a lot of optimizations and debugging here is the direct conversion of my ES6 answer in CJam:

OMriMr{s:C_,{:H<M_,H->=C\_H(+_@!*}g:T>+:M\CT<_@\MCT<_O@-\+_+:O,A<Ci1?A<Ci(@\*}h;\;h;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

CJam, 80 77 65 Characters

Probably not at all optimized, but a After a lot of optimizations and debugging here is the direct conversion of my ES6 answer in CJam:

OMri{s:C_,{:H<M_,H->=C\_H(+_@!*}g:T>+:M\CT<_@\-\+_,A<Ci1?(@\}h;\;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

CJam, 80 77 65 57 Characters

Probably not at all optimized, but a After a lot of optimizations and debugging here is the direct conversion of my ES6 answer in CJam:

Mr{s:C_,{:H<M_,H->=C\_H(+_@!*}g:T>+:MCT<_O@-+:O,A<Ci(*}h;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

added 14 characters in body
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142

CJam, 80 7777 65 Characters

Probably not at all optimized, but afterProbably not at all optimized, but a After a lot of tryingoptimizations and debugging here is the direct conversion of my ES6 answer in CJam:

OMri{s:C_,{:H<_M\,MH<M_,\->=HT?:THH-C\H>=C\_H(0?+_@!*}h;T>+g:T>+:M\CT<_@\-\+_,A<C*Ci1A<Ci1?(@\0:T;@\}h;\;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

CJam, 80 77 Characters

Probably not at all optimized, but after a lot of trying and debugging here is the direct conversion of my ES6 answer in CJam:

OMri{s:C_,{:H<_M\,M,\->=HT?:TH-C\H(0?}h;T>+:M\CT<_@\-\+_,A<C*Ci1?(@\0:T;}h;\;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

CJam, 80 77 65 Characters

Probably not at all optimized, but a After a lot of optimizations and debugging here is the direct conversion of my ES6 answer in CJam:

OMri{s:C_,{:H<M_,H->=C\_H(+_@!*}g:T>+:M\CT<_@\-\+_,A<Ci1?(@\}h;\;

Try it online here. The function takes the number as STDIN and outputs the recycled countdown, stopping in between if recycling is complete.

I will try to golf it further.

Explanation soon ...

added 7 characters in body
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142
Loading
added 4 characters in body
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142
Loading
Source Link
Optimizer
  • 26.6k
  • 7
  • 66
  • 142
Loading