Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
def insertion_sort():
n = get_world_size()
# SORT THE ROWS
go_to(0,0)
for y in range(n):
for x in range(n):
go_to(x,y)
while get_pos_x() != 0 and measure() < measure(West):
swap(West)
move(West)
# SORT THE COLUMNS
go_to(0,0)
for x in range(n):
for y in range(n):
go_to(x,y)
while get_pos_y() != 0 and measure() < measure(South):
swap(South)
move(South)
I realised that my solution had a slight difference, which is why I needed to loop the sort, after changing that, it seems to work
Supposing i have understood your example correct, it looks like this initially:
4 1
3 2
After sorting columns, you get:
4 2
3 1
After sorting rows we then have:
2 4
1 3
Which is the correct result.
If i interpreted your example wrong, please write the example down in a graphic way, like i did.
Lastly, this cactus problem is a rather standard problem in coding. Therefore i'd be very surprised if the widespread standard solution "sort both rows and columns" is wrong here ;)
For anyone interested, my way around this is just to loop over the whole sorting process until both are sorted
Otherwise good guide though