Solution to 99 lisp problems, p09 in ruby I am fairly new to ruby, and I am worried that my solution to problem 9 of the 99 lisp problems is extremly convoluted and inefficient. 
The problem is:



My Code

ul = "putanytexthere"
h = []

ul.upcase
  .split('')
  .sort
  .join('')
  .each_char
  .slice_when { |a,b| a != b }
  .map(&amp;:join)
  .each do |el|
    if el.length &gt; 1
      h &lt;&lt; el
    end
  end

  print h.length
Here is solution that aims to solve the described problem.

Note that your initial solutions is doing more that the problem requires, you are handling string instead of lists, are ordering them, and the output isn't the one desired by the problem.

require 'minitest/autorun'

class L99
  # P09 (**) Pack consecutive duplicates of list elements into sublists.
  # If a list contains repeated elements they should be placed in separate sublists.
  def self.pack(list)
    list.slice_when { |i, j| i != j }.to_a
  end
end

class PackTest &lt; Minitest::Test
  def test_pack
    list = %i[a a a a b c c a a d e e e e]
    expected = [%i[a a a a], [:b], %i[c c], %i[a a], [:d], %i[e e e e]]

    assert_equal expected, L99.pack(list)
  end

  def test_pack_string
    str = 'putanytexthere'
    expected = [['a'], %w[e e e], ['h'], ['n'], ['p'], ['r'], %w[t t t], ['u'], ['x'], ['y']]


    assert_equal expected, L99.pack(str.each_char.sort)
  end
end