-3
\$\begingroup\$

Challenge

Create a function that takes an string as a parameter. (Easy as far)

This string will contain

  • Single digit numbers
  • Letters from the alphabet
  • Question marks (Of course)

Your function will check if there are exactly 3 question marks between every pair of two numbers that add up to 10 or more. If so, then your function should return truthy, otherwise it should return falsey.

If there are not any two numbers that add up to 10 or more in the string, your function should return false.

Rules

  • Input must be a string
  • Output must be truthy or falsey value
  • If string contains only one number or none return falsey
  • If string contains odd amount of single digits, ignore the last one (left to right)

Example

Given: "arrb6???4xxbl5???eee5"

Your function must output true because there are exactly 3 question marks between 6 and 4, and 3 question marks between 5 and 5 at the end of the string


Given: "a4sd???9dst8?3r"

Your function must output false because there is just a single question mark between 8 and 3

Test Cases

Input: "aa6?9"

Output: false


Input: "acc?7??sss?3rr1??????5"

Output: true


Input: "sdty5???xcd8s3"

Output: true


Input: "sthfer5dfs"

Output: false


Update (Some clarification points)

  • Once you use a number to pair with other, you can not use it again.
  • You only can pair consecutive numbers (left to right). Example "as4f???6sda3?3d" the pairs are 4-6 and 3-3

This is , so the shortest answer in bytes win.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – user45941
    Apr 27, 2018 at 1:49
  • \$\begingroup\$ The "Once you use a number to pair with other, you can not use it again." part is still not very clear. Perhaps you meant "only consider gaps at even indices", something like that. \$\endgroup\$
    – DELETE_ME
    Apr 27, 2018 at 14:56
  • \$\begingroup\$ Any reason why you special-cased the "1 number or none" case? \$\endgroup\$
    – DELETE_ME
    Apr 27, 2018 at 14:59
  • 2
    \$\begingroup\$ This question appears to be taken from here. \$\endgroup\$
    – Laikoni
    Apr 27, 2018 at 22:16
  • \$\begingroup\$ Yes it is @Laikoni \$\endgroup\$ Apr 27, 2018 at 22:51

2 Answers 2

1
\$\begingroup\$

Python 3, 148 bytes

def f(a):q=[a.group(1).count("?")==3for a in re.finditer("(?=((\d+)\D+(\d+)))",a)if 10==sum(map(int,a.groups()[1:]))];return any(q)*all(q)
import re

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Doesnt work with complex strings like arrb6???4xxbl5???eee5 \$\endgroup\$ Apr 26, 2018 at 13:04
  • \$\begingroup\$ @LuisfelipeDejesusMunoz sorry, had my condition backwards. \$\endgroup\$
    – hyper-neutrino
    Apr 26, 2018 at 13:39
0
\$\begingroup\$

Python 2, 126 bytes

all*any idea is by @HyperNeutrino, checkout his answer

def f(n):r=[sum(map(int,g[0::2]))>9for g in re.findall('(\d)(.*?)(\d)',n)if 3==g[1].count('?')];return all(r)*any(r)
import re

Try it online!


Python 2, 125 bytes

Ouputs [] for false and [True] for true

def f(n):r=[sum(map(int,g[0::2]))>9for g in re.findall('(\d)(.*?)(\d)',n)if 3==g[1].count('?')];return r[:1]*all(r)
import re

Try it online!

\$\endgroup\$

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