Skip to content

Instantly share code, notes, and snippets.

@Kur0den
Created February 24, 2024 11:16
Show Gist options
  • Select an option

  • Save Kur0den/dac48780f274407fd535442d99a40be6 to your computer and use it in GitHub Desktop.

Select an option

Save Kur0den/dac48780f274407fd535442d99a40be6 to your computer and use it in GitHub Desktop.
bogo sort
import random
import time
def main():
length = int(input("length: "))
sort_list = [i for i in range(1, length + 1)]
c = 0
start_time = time.time()
while True:
c += 1
flag = True
random.shuffle(sort_list)
print(sort_list, f"count: {c}")
for i, j in enumerate(sort_list):
if i == 0:
continue
if j != sort_list[i - 1] + 1:
flag = False
break
if flag:
break
end_time = time.time()
print(f"実行時間: {round(end_time - start_time, 3)}s")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment