Haskell can't solve the codeeeval problem

Asked 2 years ago, Updated 2 years ago, 129 views

ReverseWords in CodeEval cannot be solved.
https://www.codeeval.com/open_challenges/8/

I'd like to reverse the list in the solution.
Repeat the string for the elements in the list.

How do you think you can solve this problem?

import System.Environment(getArgs)

solve:: [String] - > [String]
solves = fmap reverse ss

main=do
    contents<-getContents
    mapM_putStrLn$solve$lines contents

haskell

2022-09-30 18:16

1 Answers

In this case, you should first consider creating a list like ["Hello", "World"] separated by white space and then reversing it.

In words

>words "This is a pen"
>["This", "is", "a", "pen" ]

In unwords

>unwords ["pen", "a", "is", "This" ]
>"pen a is This"

You can do the same translation as .

The correct solve is listed below (mouse over).

solve::[String]->[String]
solve=fmap(unwords.reverse.words)


2022-09-30 18:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.