Happy World Computing Day!

To celebrate, we propose a challenge.

With the help of a program, perform a calculation from this text. This calculation will consist of counting the number of lines in which exactly three of the same characters appear, and separately, the number of lines in which exactly four of the same characters appear.

The result should be sent as the difference between these two numbers.

Here is an example:

  • bbcbcccd —-> Three times (✓) [b] | Four times (✓)
  • abbbccde —-> Three times (✓) [b] | Four times (✘)
  • aaaabbcd —-> Three times (✘) | Four times (✓) [a]
  • aaabcccd —-> Three times (✓) [a,c] | Four times (✘)
  • aaaabbbb —-> Three times (✘) | Four times (✓) [a,b]
  • abcccdcc —-> Three times (✘) | Four times (✘)
  • abababcc —-> Three times (✓) [a,b] | Four times (✘)

We find that 4 lines meet the three-character condition, and that 3 lines meet the four-character condition. So, the result would be 4 – 3 = 1

Are you up for the challenge? Leave your solution in our publications on social networks.

Exercise developed by Raúl Perelló, Software Engineer at EDICOM.