- Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
.... Finished in 0.00648 seconds 4 examples, 0 failures
Срокът за предаване на решения е отминал
Нали помните онова за Monkey Patching-а…? :-)
Дефинирайте метод String#longest_sequence
, който връща масив от тези символи
в низа, които имат най-дълги последователности в него. „Последователност“ ще
рече непрекъсната поредица от един и същ символ, например низът
'aaAA_32222BBB_)))'
има 8 последователности:
['aa', 'AA', '_', '3', '2222', 'BBB', '_', ')))']
, като най-дългата е
'2222'
, тоест 'aaAA_32222BBB_)))'.longest_sequence
трябва да върне ['2']
.
Ако има повече от един отговор, то връщате всички, като наредбата на
резултатите не е от значение, например: 'aaabbb23ccc'.longest_sequence
може
да върне която и да е пермутация на масива ['a', 'b', 'c']
.
Забележка: Във върнатия масив трябва да има низове (String
) с дължина
1, а не символи (Symbol
).
Примери:
'aab'.longest_sequence # => ['а']
'abba'.longest_sequence # => ['b']
'aaaaabbbbbddacccc'.longest_sequence # => ['a', 'b'] (Може и ['b', 'a'])
'.....??????&gh'.longest_sequence # => ['?']
P.S. Примерните тестове от вас. :-) Вярваме, че можете да си ги напишете сами.
.... Finished in 0.00648 seconds 4 examples, 0 failures
...F Failures: 1) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] expected collection contained: ["a", "b"] actual collection contained: ["a", "a", "b"] the extra elements were: ["a"] # /tmp/d20131202-25737-1bi4pp/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00642 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20131202-25737-1bi4pp/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once
.... Finished in 0.00636 seconds 4 examples, 0 failures
.... Finished in 0.00691 seconds 4 examples, 0 failures
.... Finished in 0.00836 seconds 4 examples, 0 failures
.... Finished in 0.00629 seconds 4 examples, 0 failures
.... Finished in 0.00664 seconds 4 examples, 0 failures
...F Failures: 1) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] expected collection contained: ["a", "b"] actual collection contained: ["a", "a", "b"] the extra elements were: ["a"] # /tmp/d20131202-25737-j3tfsc/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00651 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20131202-25737-j3tfsc/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once
.... Finished in 0.00671 seconds 4 examples, 0 failures
.... Finished in 0.00633 seconds 4 examples, 0 failures
.... Finished in 0.00961 seconds 4 examples, 0 failures
.... Finished in 0.00757 seconds 4 examples, 0 failures
.... Finished in 0.01269 seconds 4 examples, 0 failures
.... Finished in 0.00711 seconds 4 examples, 0 failures
FFFF Failures: 1) #longest_sequence for an empty string should return an empty Array Failure/Error: ''.longest_sequence.should eq [] NoMethodError: undefined method `longest_sequence' for "":String # /tmp/d20131202-25737-57t60i/spec.rb:4:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 2) #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of Failure/Error: 'aab'.longest_sequence.should eq ['a'] NoMethodError: undefined method `longest_sequence' for "aab":String # /tmp/d20131202-25737-57t60i/spec.rb:10:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 3) #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of Failure/Error: 'aabb'.longest_sequence.should =~ ['a','b'] NoMethodError: undefined method `longest_sequence' for "aabb":String # /tmp/d20131202-25737-57t60i/spec.rb:19:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 4) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] NoMethodError: undefined method `longest_sequence' for "aaabbbaaa":String # /tmp/d20131202-25737-57t60i/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00488 seconds 4 examples, 4 failures Failed examples: rspec /tmp/d20131202-25737-57t60i/spec.rb:3 # #longest_sequence for an empty string should return an empty Array rspec /tmp/d20131202-25737-57t60i/spec.rb:9 # #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of rspec /tmp/d20131202-25737-57t60i/spec.rb:18 # #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of rspec /tmp/d20131202-25737-57t60i/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once
.... Finished in 0.00627 seconds 4 examples, 0 failures
.... Finished in 0.00647 seconds 4 examples, 0 failures
.... Finished in 0.00763 seconds 4 examples, 0 failures
.... Finished in 0.00769 seconds 4 examples, 0 failures
.... Finished in 0.00631 seconds 4 examples, 0 failures
FFFF Failures: 1) #longest_sequence for an empty string should return an empty Array Failure/Error: ''.longest_sequence.should eq [] NoMethodError: undefined method `last' for nil:NilClass # /tmp/d20131202-25737-h0oriu/solution.rb:11:in `longest_sequence' # /tmp/d20131202-25737-h0oriu/spec.rb:4:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 2) #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of Failure/Error: 'aab'.longest_sequence.should eq ['a'] expected: ["a"] got: ["[\"", "a", "\"]"] (compared using ==) # /tmp/d20131202-25737-h0oriu/spec.rb:10:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 3) #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of Failure/Error: 'aabb'.longest_sequence.should =~ ['a','b'] expected collection contained: ["a", "b"] actual collection contained: ["\", \"", "\"]", "[\"", "a", "b"] the extra elements were: ["\", \"", "\"]", "[\""] # /tmp/d20131202-25737-h0oriu/spec.rb:19:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 4) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] expected collection contained: ["a", "b"] actual collection contained: ["\", \"", "\", \"", "\"]", "[\"", "a", "a", "b"] the extra elements were: ["\", \"", "\", \"", "\"]", "[\"", "a"] # /tmp/d20131202-25737-h0oriu/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.0067 seconds 4 examples, 4 failures Failed examples: rspec /tmp/d20131202-25737-h0oriu/spec.rb:3 # #longest_sequence for an empty string should return an empty Array rspec /tmp/d20131202-25737-h0oriu/spec.rb:9 # #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of rspec /tmp/d20131202-25737-h0oriu/spec.rb:18 # #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of rspec /tmp/d20131202-25737-h0oriu/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once
.... Finished in 0.00651 seconds 4 examples, 0 failures
.... Finished in 0.0067 seconds 4 examples, 0 failures
.FF. Failures: 1) #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of Failure/Error: '.....??????&gh'.longest_sequence.should eq ['?'] expected: ["?"] got: ["."] (compared using ==) # /tmp/d20131202-25737-kx8n7g/spec.rb:13:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 2) #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of Failure/Error: '.....??????&ggggggh'.longest_sequence.should =~ ['g', '?'] expected collection contained: ["?", "g"] actual collection contained: ["."] the missing elements were: ["?", "g"] the extra elements were: ["."] # /tmp/d20131202-25737-kx8n7g/spec.rb:22:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00767 seconds 4 examples, 2 failures Failed examples: rspec /tmp/d20131202-25737-kx8n7g/spec.rb:9 # #longest_sequence for a string with only one longest sequence should return only the symbol that it is comprised of rspec /tmp/d20131202-25737-kx8n7g/spec.rb:18 # #longest_sequence for a string with multiple longest sequences should return an array containg the symbols they are comprised of
.... Finished in 0.00665 seconds 4 examples, 0 failures
.... Finished in 0.00663 seconds 4 examples, 0 failures
.... Finished in 0.00637 seconds 4 examples, 0 failures
.... Finished in 0.00649 seconds 4 examples, 0 failures
.... Finished in 0.00652 seconds 4 examples, 0 failures
.... Finished in 0.00761 seconds 4 examples, 0 failures
.... Finished in 0.00632 seconds 4 examples, 0 failures
.... Finished in 0.00825 seconds 4 examples, 0 failures
.... Finished in 0.00696 seconds 4 examples, 0 failures
...F Failures: 1) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] expected collection contained: ["a", "b"] actual collection contained: ["a", "a", "b"] the extra elements were: ["a"] # /tmp/d20131202-25737-19uicbr/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00824 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20131202-25737-19uicbr/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once
.... Finished in 0.00651 seconds 4 examples, 0 failures
.... Finished in 0.00831 seconds 4 examples, 0 failures
.... Finished in 0.0211 seconds 4 examples, 0 failures
.... Finished in 0.00729 seconds 4 examples, 0 failures
...F Failures: 1) #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once Failure/Error: 'aaabbbaaa'.longest_sequence.should =~ ['a', 'b'] expected collection contained: ["a", "b"] actual collection contained: ["a", "a", "b"] the extra elements were: ["a"] # /tmp/d20131202-25737-q56tik/spec.rb:27:in `block (4 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00671 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20131202-25737-q56tik/spec.rb:26 # #longest_sequence for a string with multiple longest sequences comprised of the same symbol should return an array that contains the symbol only once