Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 242 characters in body; added 1 characters in body
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

JavaScript (148145)

(削除) 148 (削除ここまで) 145

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |"|_\n|",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L&1]+b[c&2]+b[c&4]+b[i%L?" "0:"\n");return3];return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |"|_\n|", L = n.length; i < 3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1]1 ] +
 b [ c&2 ] +
 b [ c&4 ] +
 (b [ i%L ? " "0 : "\n");3 ]; // space or newline
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

  • Finally, the spaces between the digits and the newlines between the lines are also retrieved by indexing into b, re-using the space character and the otherwise unused position 3 in that string! :)

JavaScript (148)

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L?" ":"\n");return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |", L = n.length; i < 3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1] +
 b [ c&2 ] +
 b [ c&4 ] +
 (i%L ? " " : "\n");
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

JavaScript (145)

(削除) 148 (削除ここまで) 145

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_\n|",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+b[i%L?0:3];return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_\n|", L = n.length; i < 3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1 ] +
 b [ c&2 ] +
 b [ c&4 ] +
 b [ i%L ? 0 : 3 ]; // space or newline
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

  • Finally, the spaces between the digits and the newlines between the lines are also retrieved by indexing into b, re-using the space character and the otherwise unused position 3 in that string! :)

added 2 characters in body
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

JavaScript (148)

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L?" ":"\n");return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |", L = n.length; i<3*L;i < 3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1] +
 b [ c&2 ] +
 b [ c&4 ] +
 (i%L ? " " : "\n");
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

JavaScript (148)

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L?" ":"\n");return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |", L = n.length; i<3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1] +
 b [ c&2 ] +
 b [ c&4 ] +
 (i%L ? " " : "\n");
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

JavaScript (148)

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L?" ":"\n");return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |", L = n.length; i < 3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1] +
 b [ c&2 ] +
 b [ c&4 ] +
 (i%L ? " " : "\n");
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

JavaScript (148)

Since JavaScript doesn’t really have standard input/output, this is written as a function that takes a string and returns the output as a string.

function r(n){for(i=o="",b=" |_ |",L=n.length;i<3*L;)o+=b[(c="ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L])>>(i++/L|0)*3)&1]+b[c&2]+b[c&4]+(i%L?" ":"\n");return o}

Spaced out:

function r(n)
{
 for (i = o = "", b = " |_ |", L = n.length; i<3*L; )
 o += b [ (c = "ǪĠòƲĸƚǚĢǺƺ".charCodeAt(n[i%L]) >> (i++/L|0)*3) & 1] +
 b [ c&2 ] +
 b [ c&4 ] +
 (i%L ? " " : "\n");
 return o
}

Here’s how it works:

  • Every digit shape is encoded in a Unicode character consisting of 9 bits.

  • The first three bits are for the first row, etc.

  • In each group of three bits, the first specifies whether the first character is | or space, the second whether it’s _ or space, and the third again | or space.

  • These three bits are retrieved as c&1, c&2 and c&4, which are then used as indexes into the string b.

  • At each iteration, i%L is the "x-coordinate", i.e. the digit within the input n

  • At each iteration, i/L is the "y-coordinate", i.e. the row, but we need |0 to make it an integer

AltStyle によって変換されたページ (->オリジナル) /