Skip to main content
added 24 characters in body
Source Link
Riley
  • 11.7k
  • 2
  • 22
  • 53

Perl 3334 28 bytes

Includes +1 for -p

$_=eval join"+"s/./+$&/g,split''$_=eval while/../

Uses the method described in the question.

Example:

$ echo -n 495106 | perl -p DigitalRoot.pl
7

Perl 33 bytes

$_=eval join"+",split'' while/../

Uses the method described in the question.

Example:

$ echo -n 495106 | perl -p DigitalRoot.pl
7

Perl 34 28 bytes

Includes +1 for -p

s/./+$&/g,$_=eval while/../

Uses the method described in the question.

Example:

$ echo -n 495106 | perl -p DigitalRoot.pl
7
Source Link
Riley
  • 11.7k
  • 2
  • 22
  • 53

Perl 33 bytes

$_=eval join"+",split'' while/../

Uses the method described in the question.

Example:

$ echo -n 495106 | perl -p DigitalRoot.pl
7