Skip to main content
edited body
Source Link
orlp
  • 39.4k
  • 8
  • 82
  • 197
import random def is_sorted(l): for x in range(lengthlen(l)-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps 
import random def is_sorted(l): for x in range(length-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps 
import random def is_sorted(l): for x in range(len(l)-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps 
add `return steps` to Python code
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285
import random def is_sorted(l): for x in range(length-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l)   while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps 
import random def is_sorted(l): for x in range(length-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while not is_sorted(l): i, j = index_chooser(length) assert(i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 
import random def is_sorted(l): for x in range(length-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l)   while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps 
added 4 characters in body
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216
import random def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffleis_sorted(l) while True:   for x in range(length-1):   if l[x] > l[x+1]: return False  break return True  def score(length, index_chooser):  steps = else:0 l = list(range(length))  random.shuffle(l)  return steps while not is_sorted(l): i, j = index_chooser(length) assert(i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 
import random def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while True:   for x in range(length-1):   if l[x] > l[x+1]: break else: return steps i, j = index_chooser(length) assert(i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 
import random def is_sorted(l): for x in range(length-1): if l[x] > l[x+1]: return False   return True  def score(length, index_chooser):  steps = 0 l = list(range(length))  random.shuffle(l)   while not is_sorted(l): i, j = index_chooser(length) assert(i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 
Tweeted twitter.com/StackCodeGolf/status/1052439156314595328
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216
Loading