Skip to main content
Commonmark migration
Source Link

#Perl 5, 22 bytes

Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+2)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

#Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+2)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+2)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

[Edit removed during grace period]
Source Link
msh210
  • 3.5k
  • 23
  • 36
oops
Source Link
msh210
  • 3.5k
  • 23
  • 36

#Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+3$_+2)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+3$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

#Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+3)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+3) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

#Perl 5, 22 bytes

21 plus one for -p:

$_=(-$_,$_+2)[$_%3]/3

Uses 1-based indexing.

Explanation:

-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.

added 23 characters in body
Source Link
msh210
  • 3.5k
  • 23
  • 36
Loading
added 23 characters in body
Source Link
msh210
  • 3.5k
  • 23
  • 36
Loading
Source Link
msh210
  • 3.5k
  • 23
  • 36
Loading