Skip to main content
added tilde version
Source Link
Titus
  • 14.9k
  • 1
  • 25
  • 41

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s has no `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

for(;$o=ord($s[$p++]);)     # F) 23 - work on ASCII codes, if D$s has no NULL byte and D
for(;~$c=$s[$p++];)         # G) 19 - if $s has no NULLchr(207) byteand D

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s has no `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

for(;$o=ord($s[$p++]);)     # F) 23 - work on ASCII codes, if D and $s has no NULL byte

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s has no `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

for(;$o=ord($s[$p++]);)     # F) 23 - work on ASCII codes, if $s has no NULL byte and D
for(;~$c=$s[$p++];)         # G) 19 - if $s has no chr(207) and D

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

added `ord` loop
Source Link
Titus
  • 14.9k
  • 1
  • 25
  • 41

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s does not containhas theno `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

for(;$o=ord($s[$p++]);)     # F) 23 - work on ASCII codes, if D and $s has no NULL byte

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s does not contain the `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s has no `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

for(;$o=ord($s[$p++]);)     # F) 23 - work on ASCII codes, if D and $s has no NULL byte

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

turned to bitwise, improved formatting
Source Link
Titus
  • 14.9k
  • 1
  • 25
  • 41

looping through strings

can be done with 26 bytes:

foreach(str_split($s)as$c)

or with 1824 down to 25 bytes18:

for($p=0;""<$c=$s[$p++];)
foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s does not contain the `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

$p=0$a&$b is unnecessary if this isdoes a bitwise AND on the only loop through (ascii codes of) the characters in $s$a and $b
and results in a string that has the same length as the shorter of ""<$a can be omitted if the string contains noand 0$b.

looping through strings

can be done with 26 bytes:

foreach(str_split($s)as$c)

or with 18 to 25 bytes:

for($p=0;""<$c=$s[$p++];)

$p=0 is unnecessary if this is the only loop through $s
and ""< can be omitted if the string contains no 0.

looping through strings

can be done with 26 bytes or with 24 down to 18:

foreach(str_split($s)as$c)  # A) 26 - general
for($p=0;a&$c=$s[$p++];)    # B) 24 - general
for($p=0;$c=$s[$p++];)      # C) 22 - if $s does not contain the `0` character
for(;a&$c=$s[$p++];)        # D) 20 - if $p is already NULL or 0 (does NOT work for false)
for(;$c=$s[$p++];)          # E) 18 - both C and D

$a&$b does a bitwise AND on the (ascii codes of) the characters in $a and $b
and results in a string that has the same length as the shorter of $a and $b.

Source Link
Titus
  • 14.9k
  • 1
  • 25
  • 41
Loading