Skip to main content
Commonmark migration
Source Link

#Javascript (ES6), 80 91 90 bytes

Javascript (ES6), 80 91 90 bytes

a=>[...a].reduce((p,c)=>c=='!'?p^255:c=='<'?p*2%256:c=='>'?p>>1:c=='@'?p/16|0+p%16*16:p,0)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

Thanks to @vihan for suggesting the use of reduce to save a byte.

#Javascript (ES6), 80 91 90 bytes

a=>[...a].reduce((p,c)=>c=='!'?p^255:c=='<'?p*2%256:c=='>'?p>>1:c=='@'?p/16|0+p%16*16:p,0)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

Thanks to @vihan for suggesting the use of reduce to save a byte.

Javascript (ES6), 80 91 90 bytes

a=>[...a].reduce((p,c)=>c=='!'?p^255:c=='<'?p*2%256:c=='>'?p>>1:c=='@'?p/16|0+p%16*16:p,0)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

Thanks to @vihan for suggesting the use of reduce to save a byte.

changed map to reduce
Source Link
ETHproductions
  • 50.3k
  • 6
  • 96
  • 241

#Javascript (ES6), 80 9191 90 bytes

a=>(x=0,[a=>[...a].mapreduce(c=>x=c=='(p,c)=>c=='!'?x^255p^255:c=='<'?x*2%256p*2%256:c=='>'?x>>1p>>1:c=='@'?xp/16|0+x%16*1616|0+p%16*16:x)p,x0)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

Thanks to @vihan for suggesting the use of reduce to save a byte.

#Javascript (ES6), 80 91 bytes

a=>(x=0,[...a].map(c=>x=c=='!'?x^255:c=='<'?x*2%256:c=='>'?x>>1:c=='@'?x/16|0+x%16*16:x),x)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

#Javascript (ES6), 80 91 90 bytes

a=>[...a].reduce((p,c)=>c=='!'?p^255:c=='<'?p*2%256:c=='>'?p>>1:c=='@'?p/16|0+p%16*16:p,0)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.

Thanks to @vihan for suggesting the use of reduce to save a byte.

edited outdated description
Source Link
ETHproductions
  • 50.3k
  • 6
  • 96
  • 241

#Javascript (ES6), 80 9291 bytes

a=>(x=0,[...a].map(c=>x=c=='!'?x^255:c=='<'?x*2%256:c=='>'?x>>1:c=='@'?x/16|0+x%16*16:x),x)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's !~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, dividestruly shifts the bits of x by 2 and floors1 bit to the resultright.
  • For @, floors x/16 and adds it to x%16*16.

#Javascript (ES6), 80 92 bytes

a=>(x=0,[...a].map(c=>x=c=='!'?x^255:c=='<'?x*2%256:c=='>'?x>>1:c=='@'?x/16|0+x%16*16:x),x)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ! would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, divides x by 2 and floors the result.
  • For @, floors x/16 and adds it to x%16*16.

#Javascript (ES6), 80 91 bytes

a=>(x=0,[...a].map(c=>x=c=='!'?x^255:c=='<'?x*2%256:c=='>'?x>>1:c=='@'?x/16|0+x%16*16:x),x)

Pretty much as short as it can get. Defines an anonymous function which takes the program as input.

  • For !, takes x XOR 255, as JS's ~ would consider x a 32-bit number.
  • For <, multiplies x by 2 and takes the result mod 256.
  • For >, truly shifts the bits of x 1 bit to the right.
  • For @, floors x/16 and adds it to x%16*16.
saved 1 byte
Source Link
ETHproductions
  • 50.3k
  • 6
  • 96
  • 241
Loading
Source Link
ETHproductions
  • 50.3k
  • 6
  • 96
  • 241
Loading