An old test for programmers, taken from here (Note: in italian).
Along a road (denoted by '_
'), there is a Magical Piper (denoted by 'P
') and several mice (represented by the two characters 'o' and '~
', that denote respectively the head and the tail of the small rodents).
Write a program that prints how many mice are going towards the Piper and how many mice are going away from him.
The input is a string, the output are two numbers, the first the number of mice that go towards the Piper, the second the number of mice that go away from the Piper.
The input can be also a list or vector of characters, and the output a vector or list of two numbers. You can assume that the input is always correct.
Both programs as well as functions are allowed.
Examples:
input: __o~P_o~~o
output: 1 2
input: __P~oo~o~_o~~o__
output: 3 2
input: ~oPo~
output: 2 0
input: o~P~o
output: 0 2
This is code golf, so the shortest program in any language wins.
Note: In the question, I've removed the requirement of an error message, given the majority prefer it this way. Sorry for people that already coded the error test!