Skip to main content
Mod Removes Wiki by Doorknob
added 69 characters in body
Source Link
jimmy23013
  • 37k
  • 6
  • 77
  • 148

#Convert from base n with a list of numbers greater than n

CJam converts a list to a number with this formula: A0*nl + A1*nl-1 + A2*nl-2 + Al*n0 (with nonnegative n). n is the base and l is the list length. This means Ai can be any integer, which doesn't have to be in the range of [0,n).

Some examples:

  • 0b extracts the last item and cast it to integer. Works like W=i and saves a byte if it wasn't integer. But everything else in the list must also be able to cast into integer.

  • 1b returns the sum. Works like :i:+ and saves two bytes if they aren't integerweren't integers. It also works with empty listlists while :+ doesn't.

  • [i{_1&9 32?_@\m2/}16*;]W%:c converts a character to a string of line endings and tabs, which can be converted back with 2bc. The encoding function isn't easy to be golfed in a code-golf program, though. But you don't usually need that.

  • You can use the following code to convert a string to Unicode characters not in 16 bit, which can be converted back with 2A#b128b:c. (Explanations will be added later. Or perhaps I'll write a new version later.)

      128b2A#b         " Convert to base 1024. ";
      W%2/)W%\:+       " Convert to two base 1024 digit groups. ";
      [0X@
      {
        _54+
        @I+_Am>@\-
        _Am<@+ 0@-@1^
      }fI
      ]);)
      @\+[~+]2A#b_2G#<!{2A#b}*
      \W%+:c
    

The similar method works with any set of n integers which have different values mod n, if you can find some way to get rid of the most significant digit.

#Convert from base n with a list of numbers greater than n

CJam converts a list to a number with this formula: A0*nl + A1*nl-1 + A2*nl-2 + Al*n0 (with nonnegative n). n is the base and l is the list length. This means Ai can be any integer, which doesn't have to be in the range of [0,n).

Some examples:

  • 0b extracts the last item and cast it to integer. Works like W=i and saves a byte if it wasn't integer. But everything else in the list must also be able to cast into integer.

  • 1b returns the sum. Works like :i:+ and saves two bytes if they aren't integer. It also works with empty list while :+ doesn't.

  • [i{_1&9 32?_@\m2/}16*;]W%:c converts a character to a string of line endings and tabs, which can be converted back with 2bc. The encoding function isn't easy to be golfed in a code-golf program, though. But you don't usually need that.

  • You can use the following code to convert a string to Unicode characters not in 16 bit, which can be converted back with 2A#b128b:c. (Explanations will be added later. Or perhaps I'll write a new version later.)

      128b2A#b         " Convert to base 1024. ";
      W%2/)W%\:+       " Convert to two base 1024 digit groups. ";
      [0X@
      {
        _54+
        @I+_Am>@\-
        _Am<@+ 0@-@1^
      }fI
      ]);)
      @\+[~+]2A#b_2G#<!{2A#b}*
      \W%+:c
    

The similar method works with any set of n integers which have different values mod n.

#Convert from base n with a list of numbers greater than n

CJam converts a list to a number with this formula: A0*nl + A1*nl-1 + A2*nl-2 + Al*n0 (with nonnegative n). n is the base and l is the list length. This means Ai can be any integer, which doesn't have to be in the range of [0,n).

Some examples:

  • 0b extracts the last item and cast it to integer. Works like W=i and saves a byte if it wasn't integer. But everything else in the list must also be able to cast into integer.

  • 1b returns the sum. Works like :i:+ and saves two bytes if they weren't integers. It also works with empty lists while :+ doesn't.

  • [i{_1&9 32?_@\m2/}16*;]W%:c converts a character to a string of line endings and tabs, which can be converted back with 2bc. The encoding function isn't easy to be golfed in a code-golf program, though. But you don't usually need that.

  • You can use the following code to convert a string to Unicode characters not in 16 bit, which can be converted back with 2A#b128b:c. (Explanations will be added later. Or perhaps I'll write a new version later.)

      128b2A#b         " Convert to base 1024. ";
      W%2/)W%\:+       " Convert to two base 1024 digit groups. ";
      [0X@
      {
        _54+
        @I+_Am>@\-
        _Am<@+ 0@-@1^
      }fI
      ]);)
      @\+[~+]2A#b_2G#<!{2A#b}*
      \W%+:c
    

The similar method works with any set of n integers which have different values mod n, if you can find some way to get rid of the most significant digit.

Source Link
jimmy23013
  • 37k
  • 6
  • 77
  • 148

#Convert from base n with a list of numbers greater than n

CJam converts a list to a number with this formula: A0*nl + A1*nl-1 + A2*nl-2 + Al*n0 (with nonnegative n). n is the base and l is the list length. This means Ai can be any integer, which doesn't have to be in the range of [0,n).

Some examples:

  • 0b extracts the last item and cast it to integer. Works like W=i and saves a byte if it wasn't integer. But everything else in the list must also be able to cast into integer.

  • 1b returns the sum. Works like :i:+ and saves two bytes if they aren't integer. It also works with empty list while :+ doesn't.

  • [i{_1&9 32?_@\m2/}16*;]W%:c converts a character to a string of line endings and tabs, which can be converted back with 2bc. The encoding function isn't easy to be golfed in a code-golf program, though. But you don't usually need that.

  • You can use the following code to convert a string to Unicode characters not in 16 bit, which can be converted back with 2A#b128b:c. (Explanations will be added later. Or perhaps I'll write a new version later.)

      128b2A#b         " Convert to base 1024. ";
      W%2/)W%\:+       " Convert to two base 1024 digit groups. ";
      [0X@
      {
        _54+
        @I+_Am>@\-
        _Am<@+ 0@-@1^
      }fI
      ]);)
      @\+[~+]2A#b_2G#<!{2A#b}*
      \W%+:c
    

The similar method works with any set of n integers which have different values mod n.