Пример #1
0
def timeTrial(n):
    a = stdarray.create1D(n, 0)
    for i in range(n):
        a[i] = stdrandom.uniformInt(-1000000, 1000000)
    watch = Stopwatch()
    count = threesum.countTriples(a)
    return watch.elapsedTime()
Пример #2
0
def timeTrial(n):
    a = stdarray.create1D(n, 0)
    for i in range(n):
        a[i] = stdrandom.uniformInt(-1000000, 1000000)
    watch = Stopwatch()
    count = threesum.countTriples(a)
    return watch.elapsedTime()
Пример #3
0
def main():
    n = int(sys.argv[1])

    cx = [0.000, 1.000, 0.500]
    cy = [0.000, 0.000, 0.866]

    x = 0.0
    y = 0.0

    stddraw.setPenRadius(0.0)
    for i in range(n):
        r = stdrandom.uniformInt(0, 3)
        x = (x + cx[r]) / 2.0
        y = (y + cy[r]) / 2.0
        stddraw.point(x, y)
    stddraw.show()
Пример #4
0
def main():
    n = int(sys.argv[1])

    cx = [0.000, 1.000, 0.500]
    cy = [0.000, 0.000, 0.866]

    x = 0.0
    y = 0.0

    stddraw.setPenRadius(0.0)
    for i in range(n):
        r = stdrandom.uniformInt(0, 3)
        x = (x + cx[r]) / 2.0
        y = (y + cy[r]) / 2.0
        stddraw.point(x, y)
    stddraw.show()
Пример #5
0
 def sample(self):
     length = len(self._a)
     r = stdrandom.uniformInt(0, length)
     return self._a[r]
Пример #6
0
 def dequeue(self):
     length = len(self._a)
     r = stdrandom.uniformInt(0, length)
     self._a[length - 1], self._a[r] = self._a[r], self._a[length - 1]
     return self._a.pop()
Пример #7
0
def twodice():
    a1 = stdrandom.uniformInt(0, 6)
    a2 = stdrandom.uniformInt(0, 6)
    return a1 + a2 + 2
Пример #8
0
def twodice():
    a1 = stdrandom.uniformInt(1, 7)
    a2 = stdrandom.uniformInt(1, 7)
    return a1 + a2
Пример #9
0
def SicheDice():
    d1 = [1, 3, 4, 5, 6, 8]
    d2 = [1, 2, 2, 3, 3, 4]
    a1 = stdrandom.uniformInt(0, 6)
    a2 = stdrandom.uniformInt(0, 6)
    return d1[a1] + d2[a2]
Пример #10
0
 def sample(self):
     length = len(self._a)
     r = stdrandom.uniformInt(0, length)
     return self._a[r]
Пример #11
0
 def dequeue(self):
     length = len(self._a)
     r = stdrandom.uniformInt(0, length)
     self._a[length-1], self._a[r] = self._a[r], self._a[length-1]
     return self._a.pop()
Пример #12
0
# Accept a command-line argument argument which is a file name. Read
# an image from that file. Apply an image filter that makes it look
# like the image is being seen through glass. This effect is
# accomplished by plotting each pixel the color of a random
# neighboring pixel. Display the original image and the new one.

pic1 = Picture(sys.argv[1])

width = pic1.width()
height = pic1.height()

pic2 = Picture(width, height)

for col in range(width):
    for row in range(height):
        cc = (width + col + stdrandom.uniformInt(-5, 6)) % width
        rr = (height + row + stdrandom.uniformInt(-5, 6)) % height
        c = pic1.get(cc, rr)
        pic2.set(col, row, c)

stddraw.setCanvasSize(width, height)
stddraw.picture(pic2)
stddraw.show()

#-----------------------------------------------------------------------

# python glass.py mandrill.jpg

# python glass.py mandrill.png

# python glass.py darwin.jpg