Skip to main content
Using right exponentiation symbol
Source Link

Python3+Bash (78 - 185 = -107)

python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first. If the result of the expression is negative, the result is undefined.

Use it like:

bash golf.sh "12 + (42 / 3 + 3**43^4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -7.

Python3+Bash (78 - 185 = -107)

python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first. If the result of the expression is negative, the result is undefined.

Use it like:

bash golf.sh "12 + (42 / 3 + 3**4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -7.

Python3+Bash (78 - 185 = -107)

python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first. If the result of the expression is negative, the result is undefined.

Use it like:

bash golf.sh "12 + (42 / 3 + 3^4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -7.

added 71 characters in body
Source Link

Python3+Bash (8978 - 185 = -96107)

#!/bin/bash
python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first. If the result of the expression is negative, the result is undefined.

Use it like:

./bash golf.sh "12 + (42 / 3 + 3**4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is 4-7.

Python3+Bash (89 - 185 = -96)

#!/bin/bash
python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first.

Use it like:

./golf.sh "12 + (42 / 3 + 3**4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is 4.

Python3+Bash (78 - 185 = -107)

python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first. If the result of the expression is negative, the result is undefined.

Use it like:

bash golf.sh "12 + (42 / 3 + 3**4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -7.

Fixing int
Source Link

Python3+Bash (8489 - 185 = -10196)

#!/bin/bash
python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first.

Use it like:

./golf.sh "12 + (42 / 3 + 3**4)"

1: unlesunless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -14.

Python3+Bash (84 - 185 = -101)

#!/bin/bash
python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(${1//^/**})))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

1: unles you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is -1.

Python3+Bash (89 - 185 = -96)

#!/bin/bash
python3 -c"print(sum(sum(map(int,str(x+1)))for x in range(int(${1//^/**}))))"
  • can handle all positive number
  • can handle expressions with + - / * operation
  • can handle ^ (power) operator.
  • can handle expressions, without eval or similar¹

If the result of expression is not integer, it will be truncated first.

Use it like:

./golf.sh "12 + (42 / 3 + 3**4)"

1: unless you count invoking Python from Bash as such, but I don't think it is the case. If you think that it actually is, then the adjusted score is 4.

Rollback to Revision 2
Source Link
Loading
Explaining better.
Source Link
Loading
Removing uneeded spaces
Source Link
Loading
Source Link
Loading