SHARE
TWEET

Untitled

a guest Dec 6th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import *
  2.  
  3. def PSP(n):
  4.     for _ in range(10):
  5.         l = 0
  6.         bal = 0
  7.         s = ''
  8.         for i in range(n):
  9.             if bal == 0:
  10.                 s += '('
  11.                 l += 1
  12.                 bal += 1
  13.             elif bal + 1 > n - l - 1:
  14.                 s += ')'
  15.                 l += 1
  16.                 bal -= 1
  17.             else:
  18.                 par = randint(0, 1)
  19.                 if par == 0:
  20.                     s += '('
  21.                     l += 1
  22.                     bal += 1
  23.                 else:
  24.                     s += ')'
  25.                     l += 1
  26.                     bal -= 1
  27.         print(s)
  28.        
  29. def unique_generator(n, k):
  30.     if k < 5 * n:
  31.         a = list(range(1, k + 1))
  32.         shuffle(a)
  33.         a = a[:n]
  34.         print(a)
  35.     else:
  36.         s = set()
  37.         while len(s) < n:
  38.             s.add(randint(1, k))
  39.         s = list(s)
  40.         shuffle(s)
  41.         print(s)
  42.        
  43. def bad_generator_sum(n, S):
  44.     a = []
  45.     summ = 0
  46.     for i in range(n - 1):
  47.         cur = randint(0, S - summ)
  48.         a.append(cur)
  49.         summ += cur
  50.     a.append(S - summ)
  51.     print(a)
  52.    
  53. def generator_sum(n, S):
  54.     border = []
  55.     for i in range(n - 1):
  56.         border.append(randint(0, S))
  57.     border.sort()
  58.     border = [0] + border + [S]
  59.     a = []
  60.     for i in range(1, n + 1):
  61.         a.append(border[i] - border[i - 1])
  62.     print(a)
  63.    
  64. for i in range(5):
  65.     bad_generator_sum(10, 100)
  66.    
  67. print()
  68.  
  69. for i in range(5):
  70.     generator_sum(10, 100)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top