P
P
pshy_soch2020-05-26 16:50:21
ruby
pshy_soch, 2020-05-26 16:50:21

How to consistently use word lengths in a string as an exponent?

There is a string, you need to get the length of each word and raise them to a power one by one in reverse order.
For example: "Masha pila sok" => 5, 4, 3 => ( 3 ^ 4 ) ^ 5 => 3486784401.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-26
@pshy_soch

str.split(' ').map{|w| w.length}.reverse.reduce{|b, p| b ** p}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question