Cody

# Problem 44815. Word Distance - Sum

Solution 3433318

Submitted on 27 Oct 2020 by Jens Kjærgaard Boldsen
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
assert(isequal(word_distance_sum('hello'),13))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 13

2   Pass
assert(isequal(word_distance_sum('Hello'),13))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 13

3   Pass
assert(isequal(word_distance_sum('HELLO'),13))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 13

4   Pass
assert(isequal(word_distance_sum('way'),46))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 46

5   Pass
assert(isequal(word_distance_sum('Sway'),50))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 50

6   Pass
[d] = word_distance_sum({'hello','Sway'}); assert(isequal(d(1),13)) assert(isequal(d(2),50))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 13 50

7   Pass
assert(isequal(word_distance_sum('Matlab'),51))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 51

8   Pass
assert(isequal(word_distance_sum('aBCdEfghIJkLmNOPqrStUVwxyZ'),25))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 25

9   Pass
assert(isequal(word_distance_sum('qwerty'),44))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 44

10   Pass

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 10

11   Pass
assert(isequal(word_distance_sum('payday'),87))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 87

12   Pass
assert(isequal(word_distance_sum('bookkeeper'),58))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 58

13   Pass
[d] = word_distance_sum({'one','TWO','Three','FouR','fiVe','six','sEvEn','EiGHt','NINe','ten'}); assert(isequal(d(1),10)) assert(isequal(d(2),11)) assert(isequal(d(3),35)) assert(isequal(d(4),18)) assert(isequal(d(5),33)) assert(isequal(d(6),25)) assert(isequal(d(7),57)) assert(isequal(d(8),19)) assert(isequal(d(9),19)) assert(isequal(d(10),24))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 10 11 35 18 33 25 57 19 19 24

14   Pass
assert(isequal(word_distance_sum('crazier'),91))

fct = function_handle with value: @(s)sum(abs(diff(1+lower(s)-'a'))) d = 91

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!