Skip to main content
Empty input still needs special handling due to the space in ` 15`
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN: (final newline on input is optional, but MUST be absent for the empty input)

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
1*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN:

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
1*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN (final newline on input is optional, but MUST be absent for the empty input)

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
1*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

edited body
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN:

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
.*1*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN:

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
.*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN:

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
1*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Rollback to Revision 2
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45

Perl, 76 bytes

Doesn't properly handle final 0

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN (a terminating newline is OK except for the empty input):

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
.*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Doesn't properly handle final 0

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN (a terminating newline is OK except for the empty input)

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
.*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Perl, 76 bytes

Includes +3 for -p (normally +1, but +3 to play fair with the other perl solution)

Run with the input on STDIN:

sum15.pl <<< "1 2 3"

sum15.pl:

#!/usr/bin/perl -p
s/$/ 15/;s/\d+/1x$&/eg;s/( *1){15}\K ?/
/g;s/
.*
*$//;s/1+|\B/length$&/eg

Look ma, no calculations whatsoever...

Post Undeleted by Ton Hospel
Post Deleted by Ton Hospel
added 35 characters in body
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45
Loading
Clarify that empty input must have no newline
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45
Loading
added 39 characters in body
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45
Loading
Source Link
Ton Hospel
  • 14.9k
  • 1
  • 22
  • 45
Loading