0
\$\begingroup\$

Goal:

  • Get every integer from the string (not a number, but integer)
  • Multiply them
  • Output the result


Input:

5 kilograms of food eaten, 10 liters of water drank, 20 plates dirty, 40 mugs dirty, and only 3 people acted!


Output:

120000


How:

Result was 5 * 10 * 20 * 40 * 3


What do we count as an integer:

General:

  • If integer has a symbol BEFORE of AFTER the int, only take the number without symbols. -335 or 335+ are 335 anyways.
  • If integer has a symbol like this: 35:3, don't take it. 35 : 3 is available though, and considered as 2 integers.

    Detailed:

  • 35/3 aren't two integers, skip this

  • 35.3 is not an integer, skip this
  • 35:3, 35*3, 3e3, etc. aren't ints, skip them as well
  • 353 is an integer
  • 35 3 are two integers
    1. is an integer
  • 353?, 353!, etc. are integers
  • -353 is an integer, but you only claim 353 and skip "-".
  • +353 is the same case as upper


    Requirements:

  • Select any language you want

  • The program should contain as little bytes as possible
  • You should tell us the language (if it's, like, exotic, link it like this)
  • Please, upload the code to Try It Online services like this
  • Count the bytes using special services like this
  • It would be fine if you'd explain your code!


Scoring:

Less bytes program wins! The end is 20th of June, you guys have a week

\$\endgroup\$
  • 1
    \$\begingroup\$ Can there be negative or zero integers? Can they have scientific notation? \$\endgroup\$ – Luis Mendo Jun 13 at 16:12
  • \$\begingroup\$ Can there be numbers like 3.45 (which we should then discard)? \$\endgroup\$ – Luis Mendo Jun 13 at 16:14
  • \$\begingroup\$ Can the string contain things like 13/06/2020? In general, you should specify exactly what counts as an integer to be extracted and what doesn't \$\endgroup\$ – Luis Mendo Jun 13 at 16:15
  • 5
    \$\begingroup\$ I'm still not clear exactly what's an integer. You have lots of examples which is good, but need a rule. \$\endgroup\$ – xnor Jun 13 at 17:10
  • 2
    \$\begingroup\$ Possible duplicate of Sum integers in a string \$\endgroup\$ – pppery Jun 13 at 17:38
1
\$\begingroup\$

perl -pl, 64 bytes

s!\D+|\d+(?:[.:^e/]\d+)+|(\d+)!$1?"*".(0+$1):""!aeg;$_=eval"1$_"

Try it online!

Ignores anything which isn't a digit, or multiple sequences of digits separated by /, ., e, :, or ^. Sequences of digits are replaced by themselves, prepended with *. The result, we eval, after predending 1. There's a tiny bit of hackery going to deal with numbers starting with 0s -- we don't want them be interpreted as octal numbers.

Reads lines from STDIN, writes the result to STDOUT.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The shortest won \$\endgroup\$ – KViiTEN Jun 14 at 10:53
4
\$\begingroup\$

Red, 109 bytes

func[s][p: 1 d: charset"0123456789"parse s[any[to d copy t[any d ahead[" "|"!"|"?"]](p: p * to p t)| skip]]p]

Try it online!

| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ The challenge says that 353?, 353!, and 353. are integers. \$\endgroup\$ – Abigail Jun 13 at 18:33
  • \$\begingroup\$ @Abigail Thank you, I've missed that part. I'll fix it \$\endgroup\$ – Galen Ivanov Jun 13 at 18:35
  • \$\begingroup\$ Don't answer duplicate/unclear questions. \$\endgroup\$ – pppery Jun 13 at 18:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.