Return the length of the sequence

Asked

Viewed 37 times

0

I got a problem I can’t fix:

Given a string "aeiaaioooau", identify existing sequences and count your elements with PHP.

A sequence would be a,e,i,o and u ...

Example:

$s = "aeiaaioooau"
  • "aei" is sequence of 3 elements, therefore sum + 3
  • afterward "aa" is not sequence,so it adds up to nothing
  • afterward "iooo" is sequence of 4 elements, therefore sum + 4
  • the next "a" don’t add up nothing for not being sequential
  • finally "u" is sequence one-element, sum + 1

The elements being sequential "aei+iooo+u" = 8 elements.

How to do this with PHP?

exemplo

  • 2

    Hello. I don’t quite understand the proposition. Why "Aai" is not sequence but "iooo" is?

  • What is the logic? Why the last to is not considered a sequence, but u, yes? In the case of another word, example: abecedario, the result should be 4 or other value?

  • Is this a school exercise? You need, before applying these logics, to break the string to have the distinct elements in an array and then try to use it for each situation. Good luck.

  • the logic is that a sequence is always 'a,e,i,o , u' , therefore aaaeiiiiioooou is a sequence as much as aeiou, but aaaaeiaaaaaou , has to ignore this chain of Aaaaa in order to be accounted for.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.