世界前20仙人掌(21秒969毫秒)

0 点赞
编程农场
转载

本指南包含5个程序:1)多无人机摇瓶排序(41秒626毫秒,排名118)2)多无人机仙人掌移栽(约46秒514毫秒,排名130)3)单无人机摇瓶排序(22秒814毫秒,排名20)4)单无人机带列表摇瓶排序(21秒969毫秒,排名20)5)单无人机仙人掌移栽,适合编写懒人代码(1分10秒,排名131)6)混合本教程包含5个程序: 1. 摇瓶排序,多无人机(41秒626毫秒,第118名) 2. 简单仙人掌换盆,多无人机(46秒514毫秒,约第130名) 3. 摇瓶排序,单无人机(22秒814毫秒,第20名) 4. 带叶片的摇瓶排序,单无人机(21秒969毫秒,第20名) 5. 简单仙人掌换盆,单无人机,如果你真想要懒人代码(1分10秒,第131名) 6. 多无人机混合排序(29秒631毫秒,第50名)视频攻略

1) Shaker Sort, many drones (41 seconds 626 milliseconds, 118 place) 1) Шейкерная сортировка много дронов (41 секунда 626 миллисекунд 118 место) Возможно улучшу её взяв из 4 программы лист. I might improve it by taking list from program 4. clear() #go_to new position def move_to(new_pos_x, new_pos_y): new_pos_x -= get_pos_x() new_pos_y -= get_pos_y() if new_pos_x > 16: new_pos_x = new_pos_x - 32 elif new_pos_x < -16: new_pos_x = new_pos_x + 32 if new_pos_y > 16: new_pos_y = new_pos_y - 32 elif new_pos_y < -16: new_pos_y = new_pos_y + 32 if new_pos_y > 0: for i in range(new_pos_y): move(North) elif new_pos_y < 0: for i in range(abs(new_pos_y)): move(South) if new_pos_x > 0: for i in range(new_pos_x): move(East) elif new_pos_x < 0: for i in range(abs(new_pos_x)): move(West) def water(): if get_water() < 0.5: use_item(Items.Water) use_item(Items.Fertilizer) def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: #harvest() plant(Entities.Cactus) def can_swap(direction): current = measure() neighbor = measure(direction) # Нельзя свапать, если кто-то не готов if current == None or neighbor == None: return False elif direction == North and get_pos_y() != get_world_size()-1 or direction == East and get_pos_x() != get_world_size()-1: # Текущий должен быть <= соседа return current > neighbor # если НАРУШЕНО — меняем elif direction == South and get_pos_y() != 0 or direction == West and get_pos_x() != 0: # Текущий должен быть >= соседа return current < neighbor # если НАРУШЕНО — меняем else: return False def pro_swap(direction): if can_swap(direction): swap(direction) return True else: return False def pro_cactus_gorizontal(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_x() + 1: if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 move(East) if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 if not swapped: break if k > 3: ind_max -= (k-2) / 2 ind_max -= 1 if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_x() - 1: if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 move(West) if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 if k > 3: ind_min += (k-2) / 2 ind_min += 1 if not swapped: break if ind_max <= ind_min: break def pro_cactus_vertical(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 for i in range(WorldSize): PlantCactus() pro_swap(South) move(North) while True: swapped = False k = 0 while ind_max > get_pos_y() + 1: if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 move(North) if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if k > 4: ind_max -= (k-3) / 3 ind_max -= 1 if not swapped: break if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_y() - 1: if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 move(South) if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if k > 4: ind_min += (k-3) / 3 ind_min += 1 if not swapped: break if ind_max <= ind_min: break while num_items(Items.Cactus) < 33554432: for i in range(max_drones()-1): spawn_drone(pro_cactus_vertical) move(East) pro_cactus_vertical() move_to(0, get_pos_y()) while num_drones() > 1: pass for i in range(max_drones()-1): spawn_drone(pro_cactus_gorizontal) move(North) pro_cactus_gorizontal() while num_drones() > 1: pass harvest() move_to(get_pos_x(), 0) 2) Simple Cacti Repotting, many drones (46 seconds 514 milliseconds, approximately 130 place) 2) Просто пересадка кактусов много дронов (46 секунд 514 миллисекунд 130 место примерно) clear() def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: plant(Entities.Cactus) def intelegense_measure(): mes = measure() mesS = measure(South) mesW = measure(West) if mes != None and mesS != None and mesW != None and get_pos_x() != 0 and mes >= mesW and get_pos_y() != 0 and mes >= mesS: return False elif mes != None and mesS != None and get_pos_x() == 0 and get_pos_y() != 0 and mes >= mesS: return False elif mes != None and mesW != None and get_pos_x() != 0 and get_pos_y() == 0 and mes >= mesW: return False elif get_pos_y() == 0 and get_pos_x() == 0: return False else: return True def strange_cactus(): for i in range(get_world_size()): PlantCactus() while measure() !=4: till() PlantCactus() move(North) while not can_harvest(): pass while num_items(Items.Cactus) < 33554432: for i in range(max_drones()-1): spawn_drone(strange_cactus) move(East) strange_cactus() while num_drones() > 1: pass do_a_flip() harvest() 3) Shaker Sort, one drone (22 seconds 814 milliseconds, 20 place) 3) Шейкерная сортировка один дрон (22 секунды 814 миллисекунд 20 место) clear() def go_and_swap_to_start_vertical(i): y = get_pos_y()-1 if i != 0: move(East) if y > 0: for j in range(y): pro_swap(North) pro_swap(South) move(South) def go_and_swap_to_start_gorizontal(i): x = get_pos_x()-1 if i != 0: move(North) if x > 0: for j in range(x): pro_swap(East) pro_swap(West) move(West) def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: plant(Entities.Cactus) def can_swap(direction): current = measure() neighbor = measure(direction) # Нельзя свапать, если кто-то не готов if current == None or neighbor == None: return False elif direction == North and get_pos_y() != get_world_size()-1 or direction == East and get_pos_x() != get_world_size()-1: # Текущий должен быть <= соседа return current > neighbor # если НАРУШЕНО — меняем elif direction == South and get_pos_y() != 0 or direction == West and get_pos_x() != 0: # Текущий должен быть >= соседа return current < neighbor # если НАРУШЕНО — меняем else: return False def pro_swap(direction): if can_swap(direction): swap(direction) return True else: return False def pro_cactus_gorizontal(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_x() + 1: if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 move(East) if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 if not swapped: break if k > 3: ind_max -= (k-2) / 2 ind_max -= 1 if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_x() - 1: if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 move(West) if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 if k > 3: ind_min += (k-2) / 2 ind_min += 1 if not swapped: break if ind_max <= ind_min: break def pro_cactus_vertical(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_y() + 1: if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 move(North) if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if k > 4: ind_max -= (k-3) / 3 ind_max -= 1 if not swapped: break if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_y() - 1: if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 move(South) if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if k > 4: ind_min += (k-3) / 3 ind_min += 1 if not swapped: break if ind_max <= ind_min: break #set_world_size(8) WorldSize = get_world_size() while num_items(Items.Cactus) < 131072: for i in range(WorldSize*WorldSize): PlantCactus() pro_swap(North) pro_swap(West) pro_swap(South) pro_swap(East) move_like_snake(0, 0, WorldSize, WorldSize) for i in range(WorldSize): go_and_swap_to_start_vertical(i) pro_cactus_vertical() for j in range(WorldSize): go_and_swap_to_start_gorizontal(j) pro_cactus_gorizontal() harvest() 4) Shaker Sort with Leaf, one drone (21 seconds 969 milliseconds, 20th place) 4) Шейкерная сортировка с листом один дрон (21 секунда 969 миллисекунд 20 место) clear() def mega_pro_swap(dir1, dir2): if pro_swap(dir1): if pro_swap(dir2): #if pro_swap(dir1): #return True return True return True elif pro_swap(dir2): if pro_swap(dir1): #if pro_swap(dir2): #return True return True return True else: return False def go_and_swap_to_start_vertical(i): y = get_pos_y()-1 if i != 0: move(East) if y > 0: for j in range(y): mega_pro_swap(North, South) move(South) def go_and_swap_to_start_gorizontal(i): x = get_pos_x()-1 if i != 0: move(North) if x > 0: for j in range(x): mega_pro_swap(East, West) move(West) def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: plant(Entities.Cactus) def can_swap(direction): current = measure() neighbor = measure(direction) # Нельзя свапать, если кто-то не готов if current == None or neighbor == None: return False elif direction == North and get_pos_y() != get_world_size()-1 or direction == East and get_pos_x() != get_world_size()-1: # Текущий должен быть <= соседа return current > neighbor # если НАРУШЕНО — меняем elif direction == South and get_pos_y() != 0 or direction == West and get_pos_x() != 0: # Текущий должен быть >= соседа return current < neighbor # если НАРУШЕНО — меняем else: return False def pro_swap(direction): if can_swap(direction): swap(direction) return True else: return False def pro_cactus_gorizontal(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_x() + 1: if mega_pro_swap(East, West): swapped = True k = 0 else: k += 1 move(East) if mega_pro_swap(East, West): swapped = True k = 0 else: k += 1 if not swapped: break if k > 1: ind_max -= k else: ind_max -= 1 if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_x() - 1: if mega_pro_swap(West, East): swapped = True k = 0 else: k += 1 move(West) if mega_pro_swap(West, East): swapped = True k = 0 else: k += 1 if not swapped: break if k > 1: ind_min += k else: ind_min += 1 if ind_max <= ind_min: break def pro_cactus_vertical(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_y() + 1: if mega_pro_swap(North, South): swapped = True k = 0 else: k += 1 move(North) if mega_pro_swap(North, South): swapped = True k = 0 else: k += 1 if not swapped: break if k > 1: ind_max -= k else: ind_max -= 1 if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_y() - 1: if mega_pro_swap(South, North): swapped = True k = 0 else: k += 1 move(South) if mega_pro_swap(South, North): swapped = True k = 0 else: k += 1 if not swapped: break if k > 1: ind_min += k else: ind_min += 1 if ind_max <= ind_min: break #set_world_size(8) WorldSize = get_world_size() while num_items(Items.Cactus) < 131072: for i in range(WorldSize*WorldSize): PlantCactus() pro_swap(North) pro_swap(West) pro_swap(South) pro_swap(East) move_like_snake(0, 0, WorldSize, WorldSize) for i in range(WorldSize): go_and_swap_to_start_vertical(i) pro_cactus_vertical() for j in range(WorldSize): go_and_swap_to_start_gorizontal(j) pro_cactus_gorizontal() harvest() 5) Simple Cacti Repotting, one drone, if you really want lazy code (1 minute 10 seconds, 131 place) 5) Просто пересадка кактусов один дрон, ну если очень хочется ленивый код (1 минута 10 секунд 131 место) clear() def move_like_snake(x0, y0, xmax, ymax): xnew = get_pos_x() - x0 ynew = get_pos_y() - y0 if xnew == 0 and ynew > 0: move(South) elif ynew % 2 == 0: if xnew == xmax-1: move(North) else: move(East) elif xnew == 1 and ynew != ymax-1: move(North) else: move(West) def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: plant(Entities.Cactus) WorldSize = get_world_size() while num_items(Items.Cactus) < 131072: for i in range(WorldSize*WorldSize): PlantCactus() while measure() !=4: till() PlantCactus() move_like_snake(0, 0, WorldSize, WorldSize) while not can_harvest(): pass harvest() 6) Hybrid sorting of many drones (29 seconds 631 milliseconds, 50th place) 6) Гибридная сортировка много дронов (29 секунд 631 миллисекунда 50 место) clear() #go_to new position def move_to(new_pos_x, new_pos_y): new_pos_x -= get_pos_x() new_pos_y -= get_pos_y() if new_pos_x > 16: new_pos_x = new_pos_x - 32 elif new_pos_x < -16: new_pos_x = new_pos_x + 32 if new_pos_y > 16: new_pos_y = new_pos_y - 32 elif new_pos_y < -16: new_pos_y = new_pos_y + 32 if new_pos_y > 0: for i in range(new_pos_y): move(North) elif new_pos_y < 0: for i in range(abs(new_pos_y)): move(South) if new_pos_x > 0: for i in range(new_pos_x): move(East) elif new_pos_x < 0: for i in range(abs(new_pos_x)): move(West) def water(): if get_water() < 0.5: use_item(Items.Water) use_item(Items.Fertilizer) def PlantCactus(): if get_ground_type() != Grounds.Soil: till() while get_entity_type() != Entities.Cactus: #harvest() plant(Entities.Cactus) if get_pos_x() + get_pos_y() > get_world_size() * 1.3 and measure() >= 6: pass elif get_pos_x() + get_pos_y() <= get_world_size() * 1.3 and get_pos_x() + get_pos_y() >= get_world_size() * 0.7 and measure() >= 3 and measure() <= 6: pass elif get_pos_x() + get_pos_y() < get_world_size() * 0.7 and measure() <= 3: pass else: till() till() def can_swap(direction): current = measure() neighbor = measure(direction) # Нельзя свапать, если кто-то не готов if current == None or neighbor == None: return False elif direction == North and get_pos_y() != get_world_size()-1 or direction == East and get_pos_x() != get_world_size()-1: # Текущий должен быть <= соседа return current > neighbor # если НАРУШЕНО — меняем elif direction == South and get_pos_y() != 0 or direction == West and get_pos_x() != 0: # Текущий должен быть >= соседа return current < neighbor # если НАРУШЕНО — меняем else: return False def pro_swap(direction): if can_swap(direction): swap(direction) return True else: return False def pro_cactus_gorizontal(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 while True: swapped = False k = 0 while ind_max > get_pos_x() + 1: if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 move(East) if pro_swap(East): swapped = True k = 0 else: k += 1 if pro_swap(West): swapped = True k = 0 else: k += 1 if not swapped: break if k > 3: ind_max -= (k-2) / 2 ind_max -= 1 if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_x() - 1: if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 move(West) if pro_swap(West): swapped = True k = 0 else: k += 1 if pro_swap(East): swapped = True k = 0 else: k += 1 if k > 3: ind_min += (k-2) / 2 ind_min += 1 if not swapped: break if ind_max <= ind_min: break def pro_cactus_vertical(): WorldSize = get_world_size() ind_max = WorldSize - 1 ind_min = 0 for i in range(WorldSize): PlantCactus() pro_swap(South) move(North) while True: swapped = False k = 0 while ind_max > get_pos_y() + 1: if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 move(North) if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if k > 4: ind_max -= (k-3) / 3 ind_max -= 1 if not swapped: break if ind_max <= ind_min: break swapped = False k = 0 while ind_min < get_pos_y() - 1: if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 move(South) if pro_swap(North): swapped = True k = 0 else: k += 1 if pro_swap(South): swapped = True k = 0 else: k += 1 if pro_swap(North): swapped = True k = 0 else: k += 1 if k > 4: ind_min += (k-3) / 3 ind_min += 1 if not swapped: break if ind_max <= ind_min: break while num_items(Items.Cactus) < 33554432: for i in range(max_drones()-1): spawn_drone(pro_cactus_vertical) move(East) pro_cactus_vertical() move_to(0, get_pos_y()) while num_drones() > 1: pass for i in range(max_drones()-1): spawn_drone(pro_cactus_gorizontal) move(North) pro_cactus_gorizontal() while num_drones() > 1: pass harvest() move_to(get_pos_x(), 0)