Look-and-say: Conway revisited You should all be familiar with the Conway sequence (a.k.a. 'look-and-say'-sequence) by now:

     1
    11
    21
  1211
111221
312211
etc


You can also start by any arbitrary number as starting point. Let f(s) be the next element of the sequence. Now for every given swe can find f(s). The reverse is not as trivial: it is not for every y possible to find the predecessor s such that f(s) = y. E.g. for y = 1 we cannot find a predecessor. But if y has an even length you can divide it into pairs of digits which describe each one part of a predecessor:

513211 divides in 51,32,11
so: 51 comes from 11111 
    32 comes from 222
    11 comes from 1
put together: 111112221


So this way there we can define an unique predecessor for every y of even length.

Note: The 'predecessor' s defined this way does generally NOT satisfy f(s) = y.

Goal

Write a function / program snippet that accepts a string of digits as input that


calculates the next element of the Conway sequence if the length of the input string is odd
calculates the predecessor of the input string as defined above if the input string length is even.


Shortest code in bytes wins.

Recent Questions based on the look-and-say sequences:


Look and say sequence
Point-free look and say sequence
Quickly find length of n-th term of the look-and-say sequence
Ruby, 125 120 119 101 bytes



f=-&gt;n{c=n.chars;(n.size%2&gt;0?c.chunk{|x|x}.map{|a,b|[b.size,a]}:c.each_slice(2).map{|a,b|b*a.hex})*''}


String input taken through function f:

f['111221']    # =&gt; "1211"
f['513211']    # =&gt; "111112221"
f['111112221'] # =&gt; "513211"


Expanded with notes:

# define lambda that takes one arg
f = -&gt; (n) {
  # store digits in c
  c = n.chars

  # n is of odd length
  if n.size % 2 &gt; 0
    # group identical numbers
    c.chunk{ |x| x }.map do |a, b|
      # array of [digit count, digit value]
      [b.size, a]
    end
  else
    # slice array into groups of two elements
    c.each_slice(2).map do |a, b|
      # repeat the second digit in a pair
      # the first digit-times.
      b * a.hex
    end
  end * '' # join array
}