예제 #1
0
import picasso

p = picasso.Picasso("my_example")
p.draw_best_fitting_line = True

for i in range(1000):
	p.add_point(i, i)
# p.add_point(0, 10)
# p.add_point(1, 20)
# p.add_point(2, 30)
# p.add_point(3, 40)
p.export()
예제 #2
0
import picasso
import numpy.random as r


def bubble_sort(a):
    swapped = True

    while swapped:
        swapped = False

        for i in range(len(a) - 1):
            if a[i] > a[i + 1]:
                swapped = True
                a[i], a[i + 1] = a[i + 1], a[i]

    return a


p = picasso.Picasso('bubble_sort')
p.draw_best_fitting_line = True
for i in range(0, 15001, 1000):
    p.start(i)
    a = r.random_integers(0, i, i)
    bubble_sort(a)
    p.end()
    p.export()
예제 #3
0


	while True:
		for i in range(len(a)):
			mid_index = (end+start)/2
			mid_value = a[mid_index]
			if v == mid_value:
				return mid_index
			elif v > mid_value:
				start = mid_index + 1
			elif v < mid_value:
				end = mid - 1





a = range(0, 10, 1)
print linear_search(a, 1)

p = picasso.Picasso('linear_search')
p.draw_best_fitting_line = True
for i in range(0, 15001, 1000):
    p.start(i)
    a = r.random_integers(0, i, i)
    linear_search(a, 1)
    p.end()
    p.export()

예제 #4
0
def solution_c(max):
    sum_of_factors_of_3 = solution_c_helper(3, max)
    sum_of_factors_of_5 = solution_c_helper(5, max)
    sum_of_factors_of_15 = solution_c_helper(15, max)
    s = sum_of_factors_of_3 + sum_of_factors_of_5 - sum_of_factors_of_15
    return s


def solution_c_helper(number, max):
    n = int((max - 1) / number)
    sum = number * (n * (n + 1)) / 2
    return int(sum)


p1 = picasso.Picasso('solution_a')
p2 = picasso.Picasso('solution_b')
p3 = picasso.Picasso('solution_c')

p1.draw_best_fitting_line = True
p2.draw_best_fitting_line = True
p3.draw_best_fitting_line = True

for i in range(0, 15001, 1000):
    p1.start(i)
    solution_a(i)
    p1.end()

    p2.start(i)
    solution_b(i)
    p2.end()
예제 #5
0
        print start, end, mid_index
        mid_value = a[mid_index]
        if v == mid_value:
            return mid_index
        elif v > mid_value:
            start = mid_index + 1
        elif v < mid_value:
            end = mid_index - 1

        print start, end


a = range(0, 20, 1)
print "Index of target:" + str(binary_search(a, 17))

p = picasso.Picasso('linear_search')
p.draw_best_fitting_line = True
for i in range(0, 15001, 1000):
    p.start(i)
    a = r.random_integers(0, i, i)
    linear_search(a, -1)
    p.end()
    p.export()

p = picasso.Picasso('binary_search')
p.draw_best_fitting_line = True
for i in range(0, 15001, 1000):
    p.start(i)
    a = range(0, i)
    binary_search(a, -1)
    p.end()
예제 #6
0
import picasso
p = picasso.Picasso("hello_world")
p.draw_best_fitting_line = True

p.add_point(0, 10)
p.add_point(1, 20)
p.add_point(2, 30)
p.add_point(3, 40)
p.export()
# move sorted list
import picasso
# take a[i] and figure out where to insert it on the left

import numpy.random as r


def insertion_sort(a):
    #unsorted list - i is the beginning of the unsorted list
    for i in range(len(a)):
        temp = a[i]
        j = i
        #sorted list - j is end of sorted list
        while (j > 0) and (
                a[j - 1] > temp
        ):  #second condition is for when the value to the left of j is greater than j
            a[j] = a[j - 1]
            j -= 1

        a[j] = temp
    return a


a = [5, 4, 3, 2, 1]
print insertion_sort(a)

# temp is the number that we are looking to insert to the left of it

p = picasso.Picasso('insertion_sort')
p.draw_best_fitting_line = True