Skip to main content
1 more
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

PHP, 46 bytes

No PHP answer on this yet, so here's the easy one:

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

$ echo Hello World!|php -F addascii.php
1085

More non-competing answers:

48 bytes

Iterative:

foreach(str_split($argn)as$s)$x+=ord($s);echo$x;

Try it online!

51 bytes

Iterative 2:

while($i<strlen($argn))$x+=ord($argn[$i++]);echo$x;

Try it online!

63 bytes

Recursive:

function f($s,$c=0){return$s?f(substr($s,1),ord($s[0])+$c):$c;}

Try it online!

69 bytes

Using PHP's rarely used [citation needed] array_reduce() function:

<?=array_reduce(str_split($argn),function($c,$i){return$c+ord($i);});

Try it online!

PHP, 46 bytes

No PHP answer on this yet, so here's the easy one:

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

$ echo Hello World!|php -F addascii.php
1085

More non-competing answers:

51 bytes

Iterative:

while($i<strlen($argn))$x+=ord($argn[$i++]);echo$x;

Try it online!

63 bytes

Recursive:

function f($s,$c=0){return$s?f(substr($s,1),ord($s[0])+$c):$c;}

Try it online!

69 bytes

Using PHP's rarely used [citation needed] array_reduce() function:

<?=array_reduce(str_split($argn),function($c,$i){return$c+ord($i);});

Try it online!

PHP, 46 bytes

No PHP answer on this yet, so here's the easy one:

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

$ echo Hello World!|php -F addascii.php
1085

More non-competing answers:

48 bytes

Iterative:

foreach(str_split($argn)as$s)$x+=ord($s);echo$x;

Try it online!

51 bytes

Iterative 2:

while($i<strlen($argn))$x+=ord($argn[$i++]);echo$x;

Try it online!

63 bytes

Recursive:

function f($s,$c=0){return$s?f(substr($s,1),ord($s[0])+$c):$c;}

Try it online!

69 bytes

Using PHP's rarely used [citation needed] array_reduce() function:

<?=array_reduce(str_split($argn),function($c,$i){return$c+ord($i);});

Try it online!

3 more answers of varying quality
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

PHP, 46 bytes

No PHP answer on this yet, so here's the easy one:

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

No PHP answer on this yet, so here's the obvious one.

$ echo Hello World!|php -F addascii.php
1085

More non-competing answers:

51 bytes

Iterative:

while($i<strlen($argn))$x+=ord($argn[$i++]);echo$x;

Try it online!

63 bytes

Recursive:

function f($s,$c=0){return$s?f(substr($s,1),ord($s[0])+$c):$c;}

Try it online!

69 bytes

Using PHP's rarely used [citation needed] array_reduce() function:

<?=array_reduce(str_split($argn),function($c,$i){return$c+ord($i);});

Try it online!

PHP, 46 bytes

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

No PHP answer on this yet, so here's the obvious one.

$ echo Hello World!|php -F addascii.php
1085

PHP, 46 bytes

No PHP answer on this yet, so here's the easy one:

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

$ echo Hello World!|php -F addascii.php
1085

More non-competing answers:

51 bytes

Iterative:

while($i<strlen($argn))$x+=ord($argn[$i++]);echo$x;

Try it online!

63 bytes

Recursive:

function f($s,$c=0){return$s?f(substr($s,1),ord($s[0])+$c):$c;}

Try it online!

69 bytes

Using PHP's rarely used [citation needed] array_reduce() function:

<?=array_reduce(str_split($argn),function($c,$i){return$c+ord($i);});

Try it online!

Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

PHP, 46 bytes

<?=array_sum(array_map(ord,str_split($argn)));

Try it online!

No PHP answer on this yet, so here's the obvious one.

$ echo Hello World!|php -F addascii.php
1085