Телефони и клавиатури

Краен срок
01.11.2015 12:00

Срокът за предаване на решения е отминал

Телефони и клавиатури

Представете си (не толкова) далечното минало. Няма "умни телефони", няма iPhone, но пък има ей такива клетъчни телефони:

motorolla nokia sony-ericsson lg

...и естествено, всеки ден си счупвате пръстите от писане на SMS-и.

Клавиатурите

Цифрови клавиатури ("във формата на шоколад") с 4 реда и 3 бутона на ред ("общо 12 блокчета шоколад... хммм... а сега ти се яде шоколад... изяж един шоколад... сега... но да е тъмен шоколад... по-полезен е..."):

------- ------- -------
|     | | ABC | | DEF |
|  1  | |  2  | |  3  |
------- ------- -------
------- ------- -------
| GHI | | JKL | | MNO |
|  4  | |  5  | |  6  |
------- ------- -------
------- ------- -------
|PQRS | | TUV | | WXYZ|
|  7  | |  8  | |  9  |
------- ------- -------
------- ------- -------
|     | |space| |     |
|  *  | |  0  | |  #  |
------- ------- -------

За да въведете символ (например буква от азбуката или запетая), натискате определна цифра няколко пъти. Това се нарича multi-tap въвеждане на текст.

Например, за да въведете буквата K, натискате бутона 5 два пъти (символите се въртят така J -> K -> L -> 5, което означава: едно натискане - J, две натискания - K, три натискания - L, четири натискания - 5).

Особености:

  • Бутон остава въведен, ако бъде натиснат друг бутон или след кратка пауза. Тоест не ни е нужно допълнително натискане, за да изберем буква.
  • Бутонът 1 въвежда единица (1) с едно натискане. Нищо повече. Ако натиснем бутонът n пъти, ще въведем n единици.
  • Бутонът 0 въвежда празно място или нула в реда space -> 0.
  • Бутоните * и # работят на принципа на бутона 1.

Следователно, за да се изпрати съобщението "WHERE DO U WANT 2 MEET L8R" са нужни 47 бутон-натискания.

Бутон-натискания

Бутон-натискане е термин, означаващ натискане на произволен бутон от клавиатурата на телефона.

В края на деня е жизненоважно да знаете колко бутон-натискания сте направили в писане на SMS-и!

Дефинирайте методът button_presses(message), който приема съобщение и връща броя бутон-натискания, необходими за изписване на съобщението.

Примери:

button_presses('nvm') # => 6
button_presses('WHERE DO U WANT 2 MEET L8R') # => 47

Забележки

  • space означава низ с празно място - ' '
  • Игнорираме пунктуацията (но само за целта на предизвикателството!)
  • Приемаме, че телефоните не правят разлика между главни/малки букви, но методът трябва да може да приема и главни, и малки букви
  • Ще ви гледаме много лошо до края на света, ако hardcode-нете броя на бутон-натисканията за всеки символ. Нещо подобно на:

    {'a' = 1, 'b' = 2, ..., 'o' = 3, ...}
    

Решения

Алекс Николов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Алекс Николов
def button_presses(message)
total_presses = 0
message.each_char do |c|
current_presses = case c
when 'A'..'R', 't'..'y', '0'
(c.ord - 2) % 3 + 1
when 'a'..'r'
(c.ord - 1) % 3 + 1
when 'T'..'Y'
c.ord % 3 + 1
when '1', '*', '#', ' '
1
when '2'..'6', '8', 's', 'S', 'z', 'Z'
4
when '7', '9'
5
end
total_presses += current_presses
end
total_presses
end
.........

Finished in 0.00491 seconds
9 examples, 0 failures
Станимира Влаева
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Станимира Влаева
def remove_period_three(number)
if number % 3 == 0
3
elsif (number+1) % 3 == 0
2
else
1
end
end
def button_presses(message)
alphabet_position = -> (ascii_code) { ascii_code - 64}
message.upcase.
split('').
map(&:ord).
map do |ascii_code|
case ascii_code
when 49, 32, 35, 42 # Characters 1 (ascii code 49), space (ascii code 32), # (ascii code 35) and * (ascii code 42) take just 1 press
1
when 48 # The character 0 (ascii code 48) and it takes 2 presses
2
when 50..54, 56 # Digits from 2 to 6 (ascii codes 50-54) and the digit 8 (ascii code 56) takes 4 presses
4
when 55, 57 # Digits 7 and 9 (ascii code 55 and 57) take 5 presses
5
when 65..82
remove_period_three alphabet_position.call(ascii_code)
when 84..89
remove_period_three alphabet_position.call(ascii_code)-1
when 83, 90
4
end
end.
reduce(:+)
end
.........

Finished in 0.00548 seconds
9 examples, 0 failures
Станимир Богданов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Станимир Богданов
MULTITAP_KEYBOARD = [
['1'],
['a','b','c','2'],
['d','e','f','3'],
['g','h','i','4'],
['j','k','l','5'],
['m','n','o','6'],
['p','q','r','s','7'],
['t','u','v','8'],
['w','x','y','z','9'],
['*'],
[' ','0'],
['#'],
]
def button_presses(message)
message.downcase.each_char.map do|c|
MULTITAP_KEYBOARD.select { |button| button.include?(c) }.flatten.index(c) + 1
end.inject(:+)
end
.........

Finished in 0.00479 seconds
9 examples, 0 failures
Кузман Белев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Кузман Белев
def button_presses(message)
ya_skill = 0
message.downcase.each_char { |knowledge| ya_skill += translate(knowledge) }
ya_skill
end
def translate(truth)
return 1 if '1adgjmptw*# '.include?(truth)
return 2 if 'behknqux0'.include?(truth)
return 3 if 'cfilorvy'.include?(truth)
return 4 if '23456s8z'.include?(truth)
return 5 if '79'.include?(truth)
return 0
end
.........

Finished in 0.00446 seconds
9 examples, 0 failures
Димитър Терзиев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Терзиев
SINGLE_BUTTONS = ['1','*','#',' ']
FIRST_LETTERS = ['A', 'D', 'G', 'J', 'M', 'P', 'T', 'W']
def button_presses(message)
total = 0
message.upcase.each_char do |char|
case char
when *SINGLE_BUTTONS then total += 1
when '0' then total += 2
when '1'..'9' then total += (['7','9'].include? char)? 5 : 4
when 'A'..'Z' then total +=
char.ord - FIRST_LETTERS.select{|num| num.ord < char.ord+1}.max.ord + 1
end
end
total
end
.........

Finished in 0.00513 seconds
9 examples, 0 failures
Александър Дражев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Дражев
def button_presses(message)
message.downcase.tr('a-z0-9*# ', '123123123123123123412312342144444545111').chars.map(&:to_i).reduce(0, :+)
end
.........

Finished in 0.00519 seconds
9 examples, 0 failures
Теодор Климентов
  • Некоректно
  • 0 успешни тест(а)
  • 9 неуспешни тест(а)
Теодор Климентов
def button_press(sms)
keyboard = %w(1 abc2 def3 ghi4 jkl5 mno5 pqrs7 tuv8 wxyz9 # \ 0 *)
sms.downcase.split(//).reduce(0) do |total_presses, symbol|
key = keyboard.select { |key| key.include? symbol }.first
total_presses + key.index(symbol).next
end
end
FFFFFFFFF

Failures:

  1) button_presses works for simple words
     Failure/Error: expect(button_presses('LOL')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa27e2568>
     # /tmp/d20151101-11217-jjod9i/spec.rb:3:in `block (2 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) button_presses works for phrases with spaces
     Failure/Error: expect(button_presses('HOW R U')).to eq 13
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa27e3918>
     # /tmp/d20151101-11217-jjod9i/spec.rb:7:in `block (2 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) button_presses works for phrases with numbers
     Failure/Error: expect(button_presses('WHERE DO U WANT 2 MEET L8R')).to eq 47
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa27d66a0>
     # /tmp/d20151101-11217-jjod9i/spec.rb:11:in `block (2 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) button_presses allows input in lowercase
     Failure/Error: expect(button_presses('lol')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa27b7bb0>
     # /tmp/d20151101-11217-jjod9i/spec.rb:15:in `block (2 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)>'

  5) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('0')).to eq 2
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa27b5d38>
     # /tmp/d20151101-11217-jjod9i/spec.rb:19:in `block (2 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)>'

  6) button_presses handles the 1 digit
     Failure/Error: expect(button_presses('1')).to eq 1
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa2606ac8>
     # /tmp/d20151101-11217-jjod9i/spec.rb:24:in `block (2 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)>'

  7) button_presses handles digits only
     Failure/Error: expect(button_presses('2015')).to eq 11
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa25fddb0>
     # /tmp/d20151101-11217-jjod9i/spec.rb:29:in `block (2 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)>'

  8) button_presses handles *
     Failure/Error: expect(button_presses('**OMG**')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa25fca28>
     # /tmp/d20151101-11217-jjod9i/spec.rb:33:in `block (2 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)>'

  9) button_presses handles #
     Failure/Error: expect(button_presses('canon in c#')).to eq 22
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4fa25e93b0>
     # /tmp/d20151101-11217-jjod9i/spec.rb:37:in `block (2 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.00346 seconds
9 examples, 9 failures

Failed examples:

rspec /tmp/d20151101-11217-jjod9i/spec.rb:2 # button_presses works for simple words
rspec /tmp/d20151101-11217-jjod9i/spec.rb:6 # button_presses works for phrases with spaces
rspec /tmp/d20151101-11217-jjod9i/spec.rb:10 # button_presses works for phrases with numbers
rspec /tmp/d20151101-11217-jjod9i/spec.rb:14 # button_presses allows input in lowercase
rspec /tmp/d20151101-11217-jjod9i/spec.rb:18 # button_presses handles the 0 digit
rspec /tmp/d20151101-11217-jjod9i/spec.rb:23 # button_presses handles the 1 digit
rspec /tmp/d20151101-11217-jjod9i/spec.rb:28 # button_presses handles digits only
rspec /tmp/d20151101-11217-jjod9i/spec.rb:32 # button_presses handles *
rspec /tmp/d20151101-11217-jjod9i/spec.rb:36 # button_presses handles #
Бойко Караджов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Бойко Караджов
KEYBOARD = ['1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9', '*', ' 0', '#']
def character_map()
result = Hash.new(0)
KEYBOARD.each do |button|
button.each_char { |c| result[c] = button.index(c) + 1 }
end
result
end
def button_presses(message)
presses_per_character = character_map()
message.downcase.chars.map { |c| presses_per_character[c] }.reduce(:+) || 0
end
.........

Finished in 0.0054 seconds
9 examples, 0 failures
Георги Киряков
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Киряков
def is_i?(char)
char == char.to_i.to_s
end
def number_to_taps(number)
if number == 1
1
elsif number == 0
2
elsif number != 7 && number != 9
4
else
5
end
end
def char_to_taps(char)
c = char.downcase
if is_i? c
number_to_taps(c.to_i)
elsif c < 'a'
1
elsif c < 's'
((c.ord - 94)%3 + 1)
elsif c > 's' && c < 'z'
((c.ord - 113)%3 + 1)
else
4
end
end
def button_presses(message)
presses = 0
message.each_char do |char|
presses = presses + char_to_taps(char)
end
presses
end
.........

Finished in 0.0043 seconds
9 examples, 0 failures
Николай Станев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Станев
$buttons = [['1'], ['A', 'B', 'C', '2'], ['D', 'E', 'F', '3'], ['G', 'H', 'I', '4'],
['J', 'K', 'L', '5'], ['M', 'N', 'O', '6'], ['P', 'Q', 'R', 'S', '7'], ['T', 'U', 'V', '8'],
['W', 'X', 'Y', 'Z', '9'], [' ', '0'], ['*'], ['#']]
def button_presses(message)
all_clicks = 0
message.upcase.split("").each do |symbol|
all_clicks += return_clicks(symbol)
end
all_clicks
end
def return_clicks(symbol)
clicks = 0
$buttons.each do |x|
if x.include?(symbol)
clicks = (x.index(symbol) + 1)
end
end
puts clicks
clicks
end
3
3
3
.2
3
1
1
3
1
2
.1
2
2
3
2
1
1
3
1
2
1
1
1
2
1
1
4
1
1
2
2
1
1
3
4
3
.3
3
3
.2
4
2
3
2
.1
3
4
1
2
2
1
1
3
2
1
1
1
2
2
3
2
.4
2
1
4
.1
1
3
1
1
1
1
.3
1
2
3
2
1
3
2
1
3
1
.

Finished in 0.00599 seconds
9 examples, 0 failures
Пепа Симеонова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Пепа Симеонова
def button_presses(message)
count = 0
message.each_char do |char|
count += count_presses(char)
end
count
end
def count_presses(char)
keyboard = [['1'], ['*'], ["#"],
['a', 'b', 'c', '2'],
['d', 'e', 'f', '3'],
['g', 'h', 'i', '4'],
['j', 'k', 'l', '5'],
['m', 'n', 'o', '6'],
['p', 'q', 'r', 's', '7'],
['t', 'u', 'v', '8'],
['w', 'x', 'y', 'z', '9'],
[' ', '0'],
]
keyboard.each do |key|
return key.index(char.downcase) + 1 if key.include? char.downcase
end
end
.........

Finished in 0.00582 seconds
9 examples, 0 failures
Мария Рангелова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Рангелова
KEYBOARD =
[%w(1), %w(a b c 2), %w(d e f 3), %w(g h i 4), %w(j k l 5), %w(m n o 6),
%w(p q r s 7), %w(t u v 8), %w(w x y z 9), ['*'], [' ', '0'], ['#']]
BUTTON_PRESSES = KEYBOARD.map { |button| button.each.with_index(1).to_h}.reduce(&:merge)
def button_presses(message)
message.downcase.each_char.map { |char| BUTTON_PRESSES[char]}.reduce(0,:+)
end
.........

Finished in 0.01406 seconds
9 examples, 0 failures
Георги Стефанов
  • Некоректно
  • 7 успешни тест(а)
  • 2 неуспешни тест(а)
Георги Стефанов
def button_presses(message)
number = 0
message = message.downcase
message.each_byte do |letter|
case letter
when 112..118
number += (letter%4 + 1)
when 119..122
number += (letter%4 - 2)
when 32, 35, 42, 49
number += 1
when 55, 57
number += 5
when 50..54, 56
number += 4
else
case letter%3
when 1
number += 1
when 2
number += 2
when 0
number += 3
end
end
end
number
end
....F.F..

Failures:

  1) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('0')).to eq 2
       
       expected: 2
            got: 3
       
       (compared using ==)
     # /tmp/d20151101-11217-84n73f/spec.rb:19:in `block (2 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) button_presses handles digits only
     Failure/Error: expect(button_presses('2015')).to eq 11
       
       expected: 11
            got: 12
       
       (compared using ==)
     # /tmp/d20151101-11217-84n73f/spec.rb:29:in `block (2 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.00426 seconds
9 examples, 2 failures

Failed examples:

rspec /tmp/d20151101-11217-84n73f/spec.rb:18 # button_presses handles the 0 digit
rspec /tmp/d20151101-11217-84n73f/spec.rb:28 # button_presses handles digits only
Живка Пейчинова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Живка Пейчинова
BUTTONS = [
"1", "ABC2", "DEF3",
"GHI4", "JKL5", "MNO6",
"PQRS7", "TUV8", "WXYZ9",
"*"," 0", "#"
]
def button_presses(message)
head, *tail = message.upcase.scan(/./)
count_head = tail.count(head) + 1
if count_head > 1
tail.delete_if { |i| i == head }
end
presses = (BUTTONS.find { |i| i.include? head}.index(head) + 1) * count_head
tail.length == 0 ? presses : presses += button_presses(tail.reduce(:+))
end
.........

Finished in 0.00575 seconds
9 examples, 0 failures
Денис Михайлов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Денис Михайлов
def get_letters
key_number = 1
letters = ("a".."o").each_slice(3).map do |characters|
key_number += 1
characters << key_number.to_s
end
letters << (('p'..'s').to_a << '7')
letters << (('t'..'v').to_a << '8') << (('w'..'z').to_a << '9')
end
CHARACTERS = [["1"], *get_letters, ["*"], [" ", "0"], ["#"]]
def presses_for_character(character)
letters = CHARACTERS.find do |characters|
characters.include?(character.downcase)
end
if letters.class.method_defined?(:find_index) then
letters.find_index(character.downcase) + 1
else
0
end
end
def button_presses(message)
message.split("").reduce(0) do |presses, character|
presses + presses_for_character(character)
end
end
.........

Finished in 0.00487 seconds
9 examples, 0 failures
Пламена Петрова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Пламена Петрова
def number_of_clicks(symbol)
keybord = [["1"], ["a", "b", "c", "2"], ["d", "e", "f", "3"], ["g", "h", "i", "4"],
["j", "k", "l", "5"], ["m", "n", "o", "6"], ["p", "q", "r", "s", "7"],
["t", "u", "v", "8"], ["w", "x", "y", "z", "9"], ["*"], [" ", "0"], ["#"]]
keybord.find_all{|value| value.include?(symbol)}.flatten.index(symbol) + 1
end
def button_presses(word_given)
word_given.downcase.split(//).map{|symbol| number_of_clicks(symbol)}.reduce(&:+)
end
.........

Finished in 0.0063 seconds
9 examples, 0 failures
Ивайло Христов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Христов
def button_presses(message)
letter_buttons = [*'a'..'z', ' '].join.unpack('a3a3a3a3a3a4a3a4a1').map { |button| button.split(//) }
number_buttons = ([[]] + letter_buttons).zip([*'1'..'9', '0']).map { |button| button.flatten(1) }
phone_buttons = number_buttons + [["*"], ["#"]]
message.split(//).reduce(0) do |tap_count, char|
if (char.is_a?(String))
char = char.downcase
end
taps = 0
phone_buttons.each do |button|
taps = button.index(char) and break
end
tap_count + taps + 1;
end
end
.........

Finished in 0.00844 seconds
9 examples, 0 failures
Бони Бонев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Бони Бонев
def button_presses(message)
clicks_hash = get_clicks_hash
result = 0
for i in message.downcase.chars
result += clicks_hash[i]
end
return result
end
def get_clicks_hash()
keys = ['1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9', '*', ' 0', '#']
key_clicks_count = Hash.new
for key in keys
key.each_char { |current| key_clicks_count[current] = key.index(current) + 1 }
end
return key_clicks_count
end
.........

Finished in 0.00495 seconds
9 examples, 0 failures
Петър Иванов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Иванов
KEYBOARD = {
2 => 'abc2',
3 => 'def3',
4 => 'ghi4',
5 => 'jkl5',
6 => 'mno6',
7 => 'pqrs7',
8 => 'tuv8',
9 => 'wxyz9',
0 => ' 0',
}
def button_presses(str)
str = str.downcase
presses = 0
str.split("").each do |i|
presses += get_symbol_presses(i)
end
presses
end
def get_symbol_presses(symbol)
presses = 0
if symbol == '1' or symbol == '*' or symbol == '#' then presses += 1 end
KEYBOARD.keys.each do |key|
if KEYBOARD[key].include?(symbol)
presses += (KEYBOARD[key].index(symbol) + 1)
end
end
presses
end
.........

Finished in 0.00479 seconds
9 examples, 0 failures
Добромир Иванов
  • Некоректно
  • 0 успешни тест(а)
  • 9 неуспешни тест(а)
Добромир Иванов
def button_press(message)
keyboard = ["abc2", "def3", "ghi4", "jkl5", "mno6", "pqrs7", "tuv8",
"wxyz9", " 0"]
presses = 0
message.each_char do |char|
key_group = keyboard.select {|group| group.index(char.downcase) != nil}
presses += key_group.first.index(char.downcase) + 1
end
presses
end
FFFFFFFFF

Failures:

  1) button_presses works for simple words
     Failure/Error: expect(button_presses('LOL')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bd0c2198>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:3:in `block (2 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) button_presses works for phrases with spaces
     Failure/Error: expect(button_presses('HOW R U')).to eq 13
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bd0b7ba8>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:7:in `block (2 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) button_presses works for phrases with numbers
     Failure/Error: expect(button_presses('WHERE DO U WANT 2 MEET L8R')).to eq 47
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bd0b6230>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:11:in `block (2 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) button_presses allows input in lowercase
     Failure/Error: expect(button_presses('lol')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bd097588>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:15:in `block (2 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)>'

  5) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('0')).to eq 2
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bd095850>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:19:in `block (2 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)>'

  6) button_presses handles the 1 digit
     Failure/Error: expect(button_presses('1')).to eq 1
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bcee4da8>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:24:in `block (2 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)>'

  7) button_presses handles digits only
     Failure/Error: expect(button_presses('2015')).to eq 11
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bcedd968>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:29:in `block (2 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)>'

  8) button_presses handles *
     Failure/Error: expect(button_presses('**OMG**')).to eq 9
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bcecb218>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:33:in `block (2 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)>'

  9) button_presses handles #
     Failure/Error: expect(button_presses('canon in c#')).to eq 22
     NoMethodError:
       undefined method `button_presses' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f52bcec9008>
     # /tmp/d20151101-11217-1gpwc1p/spec.rb:37:in `block (2 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.0038 seconds
9 examples, 9 failures

Failed examples:

rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:2 # button_presses works for simple words
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:6 # button_presses works for phrases with spaces
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:10 # button_presses works for phrases with numbers
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:14 # button_presses allows input in lowercase
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:18 # button_presses handles the 0 digit
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:23 # button_presses handles the 1 digit
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:28 # button_presses handles digits only
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:32 # button_presses handles *
rspec /tmp/d20151101-11217-1gpwc1p/spec.rb:36 # button_presses handles #
Десислава Цветкова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Десислава Цветкова
module Mapping
module_function
FIRST_NUMBER_CHARACTER_VALUE = 1
SECOND_NUMBER_CHARACTER_VALUE = 2
LAST_NUMBER_CHARACTER_VALUE = 5
NUMBERS_CHARACTER_VALUE = 4
LAST_CHARACTER_VALUE = 4
FIRST_CHARACTER_VALUE = 1
# chars per button
CHARS = 3
def mapper(char)
case char
when '0'..'9'
numbers_cases(char)
when 'a'..'z'
character_cases(char)
else
FIRST_CHARACTER_VALUE
end
end
def numbers_cases(char)
if ['7', '9'].member? char
LAST_NUMBER_CHARACTER_VALUE
elsif char == '1'
FIRST_NUMBER_CHARACTER_VALUE
elsif char == '0'
SECOND_NUMBER_CHARACTER_VALUE
else
NUMBERS_CHARACTER_VALUE
end
end
def character_cases(char)
ord_to_presses = -> (x) { x % CHARS == 0? CHARS : x % CHARS}
if ['z', 's'].member? char
LAST_CHARACTER_VALUE
elsif ('s'...'z').member? char
# moving the characters to the left
ord_to_presses.call(char.ord - 1)
else
ord_to_presses.call(char.ord)
end
end
end
def button_presses(sentence)
sentence.downcase.each_char.map(&Mapping.method(:mapper)).reduce(0, &:+)
end
.........

Finished in 0.00559 seconds
9 examples, 0 failures
Мирослав Лалев
  • Некоректно
  • 6 успешни тест(а)
  • 3 неуспешни тест(а)
Мирослав Лалев
# First convert the word to upcase characters only
# Secondly replace all symbols with others that are nearby either 'A' or 'Z'
# => I choose to replace them with symbols before 'A'
# Next convert each symbol to ascii code
# Map it to value, showing the number of clicks that are required to get the symbol (52 is the ascii code of '4')
# Lastly, sum the array
def button_presses(word)
word.upcase.tr("0123456789 *#", "456789:;<=@?>").bytes.map do |byte|
"43213214321321321321321321112545444441"[52-byte..-1][0].to_i
end.reduce(:+)
end
....F.F.F

Failures:

  1) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('0')).to eq 2
       
       expected: 2
            got: 4
       
       (compared using ==)
     # /tmp/d20151101-11217-1vxcfwb/spec.rb:19:in `block (2 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) button_presses handles digits only
     Failure/Error: expect(button_presses('2015')).to eq 11
       
       expected: 11
            got: 13
       
       (compared using ==)
     # /tmp/d20151101-11217-1vxcfwb/spec.rb:29:in `block (2 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) button_presses handles #
     Failure/Error: expect(button_presses('canon in c#')).to eq 22
       
       expected: 22
            got: 23
       
       (compared using ==)
     # /tmp/d20151101-11217-1vxcfwb/spec.rb:37:in `block (2 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.00884 seconds
9 examples, 3 failures

Failed examples:

rspec /tmp/d20151101-11217-1vxcfwb/spec.rb:18 # button_presses handles the 0 digit
rspec /tmp/d20151101-11217-1vxcfwb/spec.rb:28 # button_presses handles digits only
rspec /tmp/d20151101-11217-1vxcfwb/spec.rb:36 # button_presses handles #
Ивелина Христова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Ивелина Христова
def button_presses(message)
symbols = ['1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6',
'pqrs7', 'tuv8', 'wxyz9', '*', ' 0', '#']
message = message.downcase
sum_presses = 0
message.each_char do |char|
symbols.each do |symbols|
count_presses = symbols.index(char)
unless count_presses.nil?
sum_presses += count_presses + 1
end
end
end
sum_presses
end
.........

Finished in 0.00573 seconds
9 examples, 0 failures
Иван Стоилов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Стоилов
def letters(a, b)
(a..b).map { |i| i.chr}
end
def generate_keyboard
keyboard = (letters(97, 114) + letters(116, 121)).each_slice(3).to_a.unshift([])
keyboard[-1] << "z"
keyboard[-3] << "s"
(0..8).each { |i| keyboard[i] << (i + 1).to_s}
keyboard.push(["*"], [" ", "0"], ["#"])
end
def button_presses(message)
presses = 0
keyboard = generate_keyboard
message.downcase.split("").each do |symbol|
keyboard.each { |key| presses += (key.index(symbol) or 0)}
end
presses + message.length
end
.........

Finished in 0.00516 seconds
9 examples, 0 failures
Рали Ралев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Рали Ралев
class Button
attr_accessor :code
attr_accessor :symbols
def initialize(code, symbols)
@code = code
@symbols = symbols
end
end
def button_presses(message)
button_1 = Button.new(1, ['1'])
button_2 = Button.new(2, ['a', 'b', 'c', '2'])
button_3 = Button.new(3, ['d', 'e', 'f', '3'])
button_4 = Button.new(4, ['g', 'h', 'i', '4'])
button_5 = Button.new(5, ['j', 'k', 'l', '5'])
button_6 = Button.new(6, ['m', 'n', 'o', '6'])
button_7 = Button.new(7, ['p', 'q', 'r', 's', '7'])
button_8 = Button.new(8, ['t', 'u', 'v', '8'])
button_9 = Button.new(9, ['w', 'x', 'y', 'x', '9'])
button_0 = Button.new(0, [' ', '0'])
button_hash = Button.new('#', ['#'])
button_asterix = Button.new('*', ['*'])
buttons_list = []
buttons_list << button_1
buttons_list << button_2
buttons_list << button_3
buttons_list << button_4
buttons_list << button_5
buttons_list << button_6
buttons_list << button_7
buttons_list << button_8
buttons_list << button_9
buttons_list << button_0
buttons_list << button_hash
buttons_list << button_asterix
answer = 0
message.downcase.split("").each do |symbol|
buttons_list.each do |button|
symbol_index = button.symbols.find_index(symbol);
answer += symbol_index + 1 if not symbol_index.nil?
end
end
answer
end
....F....

Failures:

  1) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('ZER0')).to eq 11
       
       expected: 11
            got: 7
       
       (compared using ==)
     # /tmp/d20151101-11217-18tsfdb/spec.rb:20:in `block (2 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.00602 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20151101-11217-18tsfdb/spec.rb:18 # button_presses handles the 0 digit
Ивайло Чернев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Чернев
def button_presses(text)
presses = -> (a) do
if a == '1' or a == '*' or a == '#' or a == ' '
1
elsif a == '0'
2
elsif a == 's' or a == 'z'
4
elsif a >= '1' and a <'9'
(a != '7' and a != '9') ? 4 : 5
else
a < 's' ? ((a.ord - 'a'.ord) % 3) + 1 : ((a.ord - 'a'.ord - 1) % 3) + 1
end
end
text.downcase.chars.map { |c| presses.call(c) }.inject(:+)
end
.........

Finished in 0.00509 seconds
9 examples, 0 failures
Методи Димитров
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
KEYBOARD = ".1...,abc2,def3,ghi4,jkl5,mno6,pqrs7tuv8,wxyz9 0..,*...,#...."
def button_presses(message)
message.downcase.chars.map { |char| KEYBOARD.index(char) % 5 }.reduce(&:+)
end
.........

Finished in 0.00418 seconds
9 examples, 0 failures
Александрина Каракехайова
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Александрина Каракехайова
def button_presses(message)
array = message.codepoints
length = array.length
count, presses= 0, 0
while count < length
if (array[count] > 96 and array[count] < 112) or array[count] == 49
if array[count] % 3 == 0
presses += 3
else presses += array[count] % 3
end
elsif (array[count] > 64 and array[count] < 80) or array[count] == 32 or array[count] == 48
if array[count] % 3 == 2
presses += 1
else presses += array[count] % 3 + 2
end
elsif (array[count] > 79 and array[count]< 87) or (array[count] > 111 and array[count] < 119)
presses += array[count] % 4 + 1
elsif (array[count] > 118 and array[count] < 123) or (array[count] > 86 and array[count] < 91) or array[count]==35
presses += 4 - (array[count] % 4)
elsif (array[count] > 49 and array[count] < 55) or array[count] == 56
presses += 4
elsif array[count] == 55 or array[count] == 57
presses += 5
elsif array[count] == 42
presses += 1
end
count += 1
end
presses
end
....F....

Failures:

  1) button_presses handles the 0 digit
     Failure/Error: expect(button_presses('ZER0')).to eq 11
       
       expected: 11
            got: 9
       
       (compared using ==)
     # /tmp/d20151101-11217-i5y8fu/spec.rb:20:in `block (2 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.00422 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20151101-11217-i5y8fu/spec.rb:18 # button_presses handles the 0 digit
Адриана Стефанова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Адриана Стефанова
def button_presses(message)
values = [["1"],["a", "b", "c", "2"], ["d", "e", "f", "3"],
["g", "h", "i", "4"], ["j", "k", "l", "5"], ["m", "n", "o", "6"],
["p", "q", "r", "s", "7"], ["t", "u", "v", "8"],["w", "x", "y", "z", "9"],
["*"], [" ", "0"], ["#"]]
presses = 0
message.downcase.split('').each{ |symbol|
values.each{ |button|
if button.include?(symbol)
presses = presses + button.index(symbol) + 1
end
}
}
presses
end
.........

Finished in 0.00799 seconds
9 examples, 0 failures
Мартин Симеонов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Симеонов
KEYBOARD = ['1', 'ABC2', 'DEF3',
'GHI4', 'JKL5', 'MNO6',
'PQRS7', 'TUV8', 'WXYZ9',
'*', ' 0', '#', ]
def button_presses(message)
sum = 0
message.each_char do |character|
button = KEYBOARD.find { |button| button.include? character.upcase }
button.each_char do |symbol|
sum += 1
break if symbol == character.upcase
end
end
sum
end
.........

Finished in 0.00542 seconds
9 examples, 0 failures
Виктор Радивчев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Радивчев
def button_presses(message)
number_of_presses = 0
counter = 0
while counter < message.size
symbol = message[counter].ord
if symbol >= "A".ord and symbol <= "Z".ord
symbol = symbol + "a".ord - "A".ord
end
if symbol == "1".ord or symbol == "#".ord or symbol == "*".ord or symbol == " ".ord
number_of_presses += 1
elsif symbol == "0".ord
number_of_presses += 2
elsif symbol > "1".ord and symbol < "9".ord and symbol != "7".ord
number_of_presses += 4
elsif symbol == "7".ord or symbol == "9".ord
number_of_presses += 5
elsif symbol >= "a".ord and symbol <= "o".ord
number_of_presses += (symbol - "a".ord ) % 3 + 1
elsif symbol >= "p".ord and symbol <= "s".ord
number_of_presses += symbol - "p".ord + 1
elsif symbol >= "t".ord and symbol <= "v".ord
number_of_presses += symbol - "t".ord + 1
elsif symbol >= "w".ord and symbol <= "z".ord
number_of_presses += symbol - "w".ord + 1
end
counter += 1
end
number_of_presses
end
.........

Finished in 0.00563 seconds
9 examples, 0 failures
Петър Нетовски
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Нетовски
def button_presses(sms)
buttons = {'1' => ['1'], '2' => ['A', 'B', 'C', '2'], '3' => ['D', 'E', 'F', '3'],
'4' => ['G', 'H', 'I', '4'], '5' => ['J', 'K', 'L', '5'], '6' => ['M', 'N', 'O', '6'],
'7' => ['P', 'Q', 'R', 'S', '7'], '8' => ['T', 'U', 'V', '8'], '9' => ['W', 'X', 'Y', 'Z', '9'],
'*' => ['*'], '0' => [' ', '0'], '#' => ['#'],}
number_of_presses = 0
sms.upcase.each_char do |symbol|
if buttons.has_key?(symbol)
number_of_presses += buttons[symbol].index(symbol) + 1
else
buttons.each_value do |symbols|
if symbols.include?(symbol)
number_of_presses += symbols.index(symbol) + 1
end
end
end
end
number_of_presses
end
.........

Finished in 0.00538 seconds
9 examples, 0 failures
Георги Стефанов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стефанов
def button_presses(message)
presses = 0
press_table = [
['1', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w', '*', ' ', '#'],
['b', 'e', 'h', 'k', 'n', 'q', 'u', 'x', '0'],
['c', 'f', 'i', 'l', 'o', 'r', 'v', 'y'],
['2', '3', '4', '5', '6', 's', '8', 'z'],
['7','9']
]
message.each_char do |character|
press_table.each_with_index {|row, index| presses += 1 + index if row.include?(character.downcase)}
end
presses
end
.........

Finished in 0.0046 seconds
9 examples, 0 failures
Здравко Андонов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Здравко Андонов
def button_presses(message)
downcase_message = message.downcase
buttons = %w[1 abc2 def3 ghi4 jkl5 mno6 pqrs7 tuv8 wxyz9 * \ 0 #]
symbols_grouped_by_presses = ["", "", "", "", ""]
buttons.each { |button| button.each_char.with_index { |symbol, presses_count| symbols_grouped_by_presses[presses_count] << symbol } }
total_presses = 0
downcase_message.each_char { |symbol| total_presses += 1 + symbols_grouped_by_presses.index { |symbols_group| symbols_group.include?(symbol) } }
total_presses
end
.........

Finished in 0.00477 seconds
9 examples, 0 failures
Андрея Костов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Андрея Костов
SYM_PRESS = { '1adgjmptw*# ' => 1, 'behknqux0' => 2, 'cfilorvy' => 3, '23456s8z' => 4, '79' => 5 }
def button_presses(input)
sum = 0
input.downcase.each_char { |c| SYM_PRESS.select { |k, _| k.include?(c) }.each_value { |v| sum += v } }
sum
end
.........

Finished in 0.00573 seconds
9 examples, 0 failures
Димитър Узунов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Узунов
class String
def presses_for_char()
case self
when 'B', 'E', 'H', 'K', 'N', 'Q', 'U', 'X', '0' then 2
when 'C', 'F', 'I', 'L', 'O', 'R', 'V', 'Y' then 3
when '2', '3', '4', '5', '6', '8', 'S', 'Z' then 4
when '7', '9' then 5
else 1
end
end
end
def button_presses(message)
message.upcase.each_char.map(&:presses_for_char).reduce(:+)
end
.........

Finished in 0.00424 seconds
9 examples, 0 failures
Малина Демирова
  • Некоректно
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)
Малина Демирова
class Hash
# Оставям докъдето стигнах за малък коментар
def []=(*args)
*keys, vals = args # if this doesn't work in your version of ruby, use "keys, vals = args[0...-1], args.last"
merge! Hash[keys.zip(vals.respond_to?(:each) ? vals : [vals])]
end
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
def button_length
array = [[1], ['a', ['b', 'c', 2]],['d',['e','f',3]],['g',['h','i',4]],['j',['k','l',5]],['m',['n','o',6]],['p',['q','r','s',[7]]],['t',['u','v',8]],['w',['x','y','z',[9]]],['*'],[' '],['#']]
values_second_array = array.map {|a, (b,c,d,(e))| a, b,c,d,e = [1,[2,3,4,[5]]]}
merged_arrays = {}
merged_arrays = array.deep_merge(values_second_array)
# merged_arrays = Hash[array.zip(values_second_array.map{|i| i.include?(',') ? i.split(',') : i})]
merged_arrays.each do |k, v|
puts "#{k} : #{v}"
end
end
end
/data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/matchers/operator_matcher.rb:12:in `register': undefined method `[]=' for nil:NilClass (NoMethodError)
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/matchers.rb:712:in `<module:Matchers>'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/matchers.rb:178:in `<module:RSpec>'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/matchers.rb:16:in `<top (required)>'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/expectations.rb:2:in `require'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-expectations-2.99.2/lib/rspec/expectations.rb:2:in `<top (required)>'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:555:in `require'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:555:in `block in expect_with'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:550:in `map'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:550:in `expect_with'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:517:in `expectation_frameworks'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1058:in `configure_expectation_framework'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:404:in `ensure_example_groups_are_configured'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:418:in `set_it_up'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:368:in `subclass'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:342:in `describe'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/dsl.rb:18:in `describe'
	from /tmp/d20151101-11217-1jfefe/spec.rb:1:in `<top (required)>'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
	from /data/rails/evans-2015/shared/bundle/ruby/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'
Кристиан Цветков
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
ALPHABET = ("A".."Z").to_a
def button_presses(message)
presses = message.upcase.chars.map do |symbol|
button_presses_count symbol
end
presses.reduce(0, :+)
end
def button_presses_count(symbol)
case symbol
when *ALPHABET
if symbol == "S" or symbol == "Z"
4
else
((ALPHABET - ["S", "Z"]).index(symbol)%3).succ
end
when "1", "*", " ", "#"
1
when "0"
2
when "2".."6", "8"
4
when "7", "9"
5
end
end
.........

Finished in 0.00503 seconds
9 examples, 0 failures