8
\$\begingroup\$

Challenge:

Given the input array l with a list of strings, only keep the elements in the sequence that have a letter that's repeated at least 3 times. Like 'lessons' has 3 s letters, so it should be kept in the sequence. But, 'lesson' has only two s letters, so it should be removed.

Notes:

  • l will always be a sequence, and its elements will always be strings with only alphabetical characters.

  • I am using the example output with Python Lists. You can use any type of sequence in your own language.

Test cases:

['element', 'photoshop', 'good'] -> ['element', 'photoshop']
['happy', 'colorful', 'luggage'] -> ['luggage']
['reference', 'tomorrow', 'today'] -> ['reference', 'tomorrow'] 

This is , so the shortest code in bytes wins!

\$\endgroup\$
6
  • 4
    \$\begingroup\$ This is fine for now, but in future, please note that it's recommended to use the Sandbox before you post your challenge, so you can get feedback on it first. \$\endgroup\$
    – The Thonnu
    Commented Dec 22, 2022 at 12:26
  • 1
    \$\begingroup\$ I will @TheThonnu next time. \$\endgroup\$ Commented Dec 22, 2022 at 12:27
  • \$\begingroup\$ @U12-Forward order doesn't matter right? \$\endgroup\$ Commented Dec 23, 2022 at 12:50
  • 2
    \$\begingroup\$ Can the input array have repeates? \$\endgroup\$
    – xnor
    Commented Dec 23, 2022 at 22:55
  • \$\begingroup\$ @UndoneStudios It doesn't matter. \$\endgroup\$ Commented Dec 25, 2022 at 9:07

33 Answers 33

1
2
0
\$\begingroup\$

Thunno, \$10\log_{256}(96)\approx\$ 8.23 bytes

gz:zy.L2>S

Attempt This Online!

gz:zy.L2>S  # Implicit input
g           # Filter the input for items where:
         S  #  There is at least one item where:
     .L     #   The lengths of
 z:zy       #   The string, sorted and grouped
       2>   #   Is greater than 2
            # Implicit output 
\$\endgroup\$
0
\$\begingroup\$

Scala, 100 bytes

Golfed version. Try it online!

_.filter(w=>ListMap(w.groupBy(identity).mapValues(_.size).toSeq.sortBy(_._1):_*).values.exists(_>2))
\$\endgroup\$
0
\$\begingroup\$

Uiua SBCS, 13 bytes

▽>2≡◇/↥⍚°⊚⍚⊛.

Try it!

▽>2≡◇/↥⍚°⊚⍚⊛.­⁡​‎‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌­
            .  # ‎⁡duplicate
          ⍚⊛   # ‎⁢classify each string (convert to naturals)
       ⍚°⊚     # ‎⁣occurrences of each string
   ≡◇/↥        # ‎⁤maximums
▽>2            # ‎⁢⁡keep those with more than two occurrences
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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