Skip to main content
added 1184 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Example run

$ cjam <(echo '0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`') <<< 33
[0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46]

How it works

0ali                               " Push S := [ 0 ] and read an integer N from STDIN.    ";
    {                      }fI     " For each I in [ 0 ... (N - 1) ]:                     ";
     _W=                           "   X := S[-1].                                        ";
        _I-                        "   Y := X - I                                         ";
            _0<                    "   A := (Y < 0)                                       ";
           _   4$@#)               "   B := (Y ∊ S)                                       ";
                     @I+           "   Z := X + I                                         ";
                    |   @?         "   C := (A || B) ? Z : Y                              ";
                          +        "   S += [C]                                           ";
                              1>`  " Push str(S[1:]).                                     ";

Example run

$ cjam <(echo '0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`') <<< 33
[0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46]

How it works

0ali                               " Push S := [ 0 ] and read an integer N from STDIN.    ";
    {                      }fI     " For each I in [ 0 ... (N - 1) ]:                     ";
     _W=                           "   X := S[-1].                                        ";
        _I-                        "   Y := X - I                                         ";
            _0<                    "   A := (Y < 0)                                       ";
           _   4$@#)               "   B := (Y ∊ S)                                       ";
                     @I+           "   Z := X + I                                         ";
                    |   @?         "   C := (A || B) ? Z : Y                              ";
                          +        "   S += [C]                                           ";
                              1>`  " Push str(S[1:]).                                     ";
added 9 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 3434 33 bytes

0ali({_W=_I)-__0<4$@#)|@I)+@|@I+@?+}fI`fI1>`

Try it online.

CJam, 34 bytes

0ali({_W=_I)-__0<4$@#)|@I)+@?+}fI`

Try it online.

CJam, 34 33 bytes

0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`

Try it online.

deleted 4 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 3834 bytes

li0ali(__,:)_@f-\{_W=_I)-_3$\#__0<4$@#)@I+@|@I)+@?+}fI\~>fI`

Try it online.

CJam, 38 bytes

li(__,:)_@f-\{_W=_I-_3$\#)@I+@?+}fI\~>

Try it online.

CJam, 34 bytes

0ali({_W=_I)-__0<4$@#)|@I)+@?+}fI`

Try it online.

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading