+ 53

[M💙 Challenge] Grid Walking ⬛▪🏃▪⬛

Monday Blue 💙 Challenge Series #6 Let's get moving this week! This time we will calculate the Euclidean distance from point A to B based on the path travelled on an unbounded grid. 💼 TASK Write a program to accept a string to indicate the path travelled with the following symbol:- [ N ] orth ⬆️ [ E ] ast ➡️ [ W ] est ⬅️ [ S ] outh ⬇️ and then output the straight-line (shortest) distance between the original position and final position. In case you're unfamiliar, you'll need to apply the distance formula from Pythagorean Theorem for this challenge. 😉 🔧 TEST CASE "NE" 1.41 "WWW" 3.00 "NNNNN" 5.00 "EEENNNN" 5.00 "ENENENN" 5.00 "EEEWWW" 0.00 "SSWENNEW" 0.00 "SWSWSWSWSWSWSESWSESWSES" 13.00 ❤ BONUS Creative and clear-cut approach is encouraged. Happy Coding!!! 😁💻

23rd Oct 2017, 12:25 PM
Zephyr Koo
Zephyr Koo - avatar
85 Answers
+ 11
I let the reader put this in one line by combining the 2 functions https://code.sololearn.com/cUPx5fvha9h2/?ref=app
23rd Oct 2017, 4:24 AM
VcC
VcC - avatar
23rd Oct 2017, 4:16 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 32
so here is my try 👇 ⬜🌹🌹🌹🌹🌹⬜ 🌹⬜⬜⬜⬜⬜⬜ 🌹⬜⬜⬜⬜⬜⬜ 🌹⬜⬜⬜🌹🌹🌹 🌹⬜⬜⬜⬜⬜🌹 🌹⬜⬜⬜⬜⬜🌹 ⬜🌹🌹🌹🌹🌹⬜ https://code.sololearn.com/cqRNu7gdlpg7/?ref=app
23rd Oct 2017, 1:12 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 29
hey , see my try 😃
23rd Oct 2017, 2:05 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 24
Oh WOW, there HE comes! Sir Krishna!!! 😱
23rd Oct 2017, 4:18 AM
Zephyr Koo
Zephyr Koo - avatar
23rd Oct 2017, 11:07 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 22
Again, glad you all enjoy the challenge! 😄 We got a few interesting submissions by now and I always believe there's a tradeoff between readability and performance. For example, using native count approach will significantly shorten the code without if/else and switch but will force to scan the entire string up to 4 times (i.e. N, E, W & S) whereas a single scan can be done more efficiently by inspecting character one-by-one. Let's see if we got any more submissions with unique approach until the next challenge. 😉
25th Oct 2017, 5:27 AM
Zephyr Koo
Zephyr Koo - avatar
+ 17
Glad you all enjoy the challenge! 😄
23rd Oct 2017, 1:43 PM
Zephyr Koo
Zephyr Koo - avatar
+ 17
@Tuan Kiet Tran Good try! You may further improve the code performance by reducing the no. of iteration. 😉
23rd Oct 2017, 1:44 PM
Zephyr Koo
Zephyr Koo - avatar
+ 16
By the way, congratulation to stay ahead of Sir Krishna's submission this time, I guess he's pretty busy today! 😂
23rd Oct 2017, 4:05 AM
Zephyr Koo
Zephyr Koo - avatar
+ 16
@luka Nope it's purely my idea for the #MondayBlue challenge series. I'll definitely give credit if I adopt the challenge from somewhere else. I'm happy to attach the link if anyone found any similar challenge or from other source too. 😉
23rd Oct 2017, 5:26 AM
Zephyr Koo
Zephyr Koo - avatar
+ 15
@Swapnil Srivastava No late at all, #MondayBlue challenge best answer will be selected every week! 😉
23rd Oct 2017, 1:04 PM
Zephyr Koo
Zephyr Koo - avatar
+ 13
@Pegasus Yes you may handle the exception if you prefer but it's safe to assume the string consists of character N, E, W and S only. Regarding the decimal places, 2 is recommended but it's not mandatory as it's just for formatting purpose. 😉
23rd Oct 2017, 4:02 AM
Zephyr Koo
Zephyr Koo - avatar
+ 13
Thanks everyone for your participation! I'm really glad to reach a new milestone of #MondayBlue challenge although I didn't make it into COTD with over 50 submissions. I've read through all the codes and finally decided to pick VcC's Python solution which showcase the good use of lambda. In fact, you all had done a good job so please don't feel bad if your solution didn't get picked as we still got more to come! I hope you all enjoy and let's move on to the next challenge! ❤ https://www.sololearn.com/Discuss/824362/?ref=app
30th Oct 2017, 4:13 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
https://code.sololearn.com/c3FuD28Y0jYk/?ref=app My understanding coded into Python
23rd Oct 2017, 3:49 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
23rd Oct 2017, 3:53 AM
sayan chandra
sayan chandra - avatar
+ 12
@Suika King You've done a pretty good job! Keep it up!!! 😉👍
28th Oct 2017, 10:19 AM
Zephyr Koo
Zephyr Koo - avatar
23rd Oct 2017, 4:08 AM
Calviղ
Calviղ - avatar
23rd Oct 2017, 6:56 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
23rd Oct 2017, 8:03 AM
wolfsan
wolfsan - avatar