+ 4
[EASTER CODING CHALLENGE] Round 1: Help the Easter bunny draw a map
This is the first of a number of coding challenges I will put out over the next few days. This should be an easy warm up for you, you may solve it in any language: The Easter bunny wants to visit all the friends it made on SoloLearn, as soon as it can take some time off. As it is very busy at the moment, it needs your help to plan the trip. It already has the coordinates of all its friends' houses, but it would like to see them on a map.
7 ответов
+ 3
Write a function, that takes a string of the form "a1,a2;b1,b2;c1,c2;d1,d2..." where each x1,x2 is a pair of integers, which constitutes the coordinates of a friend's house. The function should print out a grid containing "X" and "O" separated by either spaces or line breaks, where X marks the position of a friend's house. Moving one grid entry to the right, increases the x-coordinate by one, moving one down increases the y-coordinate by one. The grid should be as small as possible, while still showing all houses and the function's return value should be the coordinates of the upper left most grid entry.
Examples:
"2,2;2,3;3,3" should print
X O
X X
and return (2,2).
"5,8;8,5" should print
O O O X
O O O O
O O O O
X O O O
and return (5,5).
EDIT: Sample Solution:
https://code.sololearn.com/cwWLuFrT7P8w
+ 3
I can't make that work if I run the script with a concrete coordinate string. Am I missing something or is it the same for you?
+ 3
Works perfectly fine, I tested it with some other values as well. I read the code and I like it, well done! :)
+ 2
Yes, I made sure the script would wait for the element to load. But "2,2;3,3;2,3" produced an error.
0
I tried with "3;5" and it worked. It prints the map into an HTML element that requires to be loaded. Are you calling the function "onload"?
0
Oh, my bad, I didn't saw that coordinate pairs are separated by ";" but each coordinate is separated by ",". I'll update the code when I get to my house.
EDIT: Does it work fine if you separate all with ";"?