def run():
    DIRECTORY = "http://commondatastorage.googleapis.com/codeskulptor-assets/"
    DATA_3108_URL = DIRECTORY + "data_clustering/unifiedCancerData_3108.csv"
    DATA_896_URL = DIRECTORY + "data_clustering/unifiedCancerData_896.csv"
    DATA_290_URL = DIRECTORY + "data_clustering/unifiedCancerData_290.csv"
    DATA_111_URL = DIRECTORY + "data_clustering/unifiedCancerData_111.csv"

    data_table = load_data_table(DATA_3108_URL)
    
    singleton_list = []
    for line in data_table:
        singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4]))

    codeskulptor.set_timeout(200)
    
    cluster_list = hierarchical_clustering(singleton_list, 15)
    print "Displaying", len(cluster_list), "hierarchical clusters"

    #cluster_list = kmeans_clustering(singleton_list, 15, 5)	
    #print "Displaying", len(cluster_list), "k-means clusters"

    
    viz.plot_it(data_table, cluster_list)
import random
import urllib2
import alg_cluster
import project3 as p3
import matplotlib.pyplot as plt

# conditional imports
if DESKTOP:
    #import alg_project3_solution      # desktop project solution
    import project3 as alg_project3_solution
    import alg_clusters_matplotlib
else:
    #import userXX_XXXXXXXX as alg_project3_solution   # CodeSkulptor project solution
    import alg_clusters_simplegui
    import codeskulptor
    codeskulptor.set_timeout(30)


###################################################
# Code to load data tables

# URLs for cancer risk data tables of various sizes
# Numbers indicate number of counties in data table

DIRECTORY = "http://commondatastorage.googleapis.com/codeskulptor-assets/"
DATA_3108_URL = DIRECTORY + "data_clustering/unifiedCancerData_3108.csv"
DATA_896_URL = DIRECTORY + "data_clustering/unifiedCancerData_896.csv"
DATA_290_URL = DIRECTORY + "data_clustering/unifiedCancerData_290.csv"
DATA_111_URL = DIRECTORY + "data_clustering/unifiedCancerData_111.csv"

Note that you must download the file
http://www.codeskulptor.org/#alg_clusters_matplotlib.py
to use the matplotlib version of this code
"""

# Flavor of Python - desktop or CodeSkulptor
DESKTOP = False

import math
import random
import urllib2
import alg_cluster
import user40_qqmi7jGqbVyG2vK_0 as cl
import codeskulptor

codeskulptor.set_timeout(1000)
# conditional imports
#if DESKTOP:
#    import alg_project3_solution      # desktop project solution
#    import alg_clusters_matplotlib
#else:
    #import userXX_XXXXXXXX as alg_project3_solution   # CodeSkulptor project solution
#    import alg_clusters_simplegui
#    import codeskulptor
#    codeskulptor.set_timeout(30)


###################################################
# Code to load data tables

# URLs for cancer risk data tables of various sizes
"""
Mini-max Tic-Tac-Toe Player
"""

#import user39_lmN64yPcJ3_11 as poc_ttt_gui
#import poc_ttt_provided as provided
import poc_ttt_gui
import poc_ttt_provided as provided

# Set timeout, as mini-max can take a long time
import codeskulptor
codeskulptor.set_timeout(120)

# SCORING VALUES - DO NOT MODIFY
SCORES = {provided.PLAYERX: 1,
          provided.DRAW: 0,
          provided.PLAYERO: -1}

def mm_move(board, player):    
    """
    Make a move on the board.
    
    Returns a tuple with two elements.  The first element is the score
    of the given board and the second element is the desired move as a
    tuple, (row, col).
    """    
    if board.check_win() != None:
        if board.check_win() == provided.PLAYERX:            
            
            return SCORES[provided.PLAYERX], (-1, -1)
        elif board.check_win() == provided.PLAYERO:                        
slow_closest_pair(cluster_list)
fast_closest_pair(cluster_list)
closest_pair_strip(cluster_list, horiz_center, half_width)
hierarchical_clustering(cluster_list, num_clusters)
kmeans_clustering(cluster_list, num_clusters, num_iterations)

where cluster_list is a 2D list of clusters in the plane
"""

import math
import random
import alg_cluster
import time
import codeskulptor
codeskulptor.set_timeout(200)
import simpleplot




######################################################
# Code for closest pairs of clusters

def pair_distance(cluster_list, idx1, idx2):
    """
    Helper function that computes Euclidean distance between two clusters in a list

    Input: cluster_list is list of clusters, idx1 and idx2 are integer indices for two clusters
    
    Output: tuple (dist, idx1, idx2) where dist is distance between
"""
Provided code for Application portion of Module 1

Imports physics citation graph 
"""

# general imports
import urllib2
from user40_VFBeihtqqa_45 import *
import simpleplot
import math

# Set timeout for CodeSkulptor if necessary
import codeskulptor
codeskulptor.set_timeout(45)


###################################
# Code for loading citation graph

CITATION_URL = "http://storage.googleapis.com/codeskulptor-alg/alg_phys-cite.txt"

def load_graph(graph_url):
    """
    Function that loads a graph given the URL
    for a text representation of the graph
    
    Returns a dictionary that models a graph
    """
    graph_file = urllib2.urlopen(graph_url)
    graph_text = graph_file.read()
Example #7
0
import math

import matplotlib.pyplot as plt
import urllib2

import alg_cluster

# conditional imports
if DESKTOP:
    import ALG_Closest_Pairs_and_Clustering as alg_project3_solution  # desktop project solution
    import alg_clusters_matplotlib
else:
    import user41_HIEOP4ld7Q_2 as alg_project3_solution  # CodeSkulptor project solution
    import alg_clusters_simplegui
    import codeskulptor
    codeskulptor.set_timeout(30)

###################################################
# Code to load data tables

# URLs for cancer risk data tables of various sizes
# Numbers indicate number of counties in data table

# DIRECTORY = "http://commondatastorage.googleapis.com/codeskulptor-assets/"
# DATA_3108_URL = DIRECTORY + "data_clustering/unifiedCancerData_3108.csv"
# DATA_896_URL = DIRECTORY + "data_clustering/unifiedCancerData_896.csv"
# DATA_290_URL = DIRECTORY + "data_clustering/unifiedCancerData_290.csv"
# DATA_111_URL = DIRECTORY + "data_clustering/unifiedCancerData_111.csv"

DATA_3108_URL = "unifiedCancerData_3108.csv"
DATA_896_URL = "unifiedCancerData_896.csv"
Example #8
0
https://bitbucket.org/OPiMedia/simpleguics2pygame

GPLv3 --- Copyright (C) 2013 Olivier Pirson
http://www.opimedia.be/
"""

import math

try:
    from user27_5LlszPPJxQHFMbk import codeskulptor_is, hex2

    import simplegui

    from codeskulptor import set_timeout

    set_timeout(10)
except ImportError:
    from SimpleGUICS2Pygame.codeskulptor_lib import codeskulptor_is, hex2

    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

    simplegui.Frame._hide_status = True


#
# Global constants
###################
_FPS_AVERAGE = not codeskulptor_is()  # draw FPS average
                                      #   (only with SimpleGUICS2Pygame)

CANVAS_WIDTH = 256
"""
Cookie Clicker Simulator
"""

import simpleplot, math, codeskulptor
# import poc_simpletest

# Used to increase the timeout, if necessary
codeskulptor.set_timeout(30)  # adujst as needed

import poc_clicker_provided as provided

# Constants
# SIM_TIME = 10000000000.0
SIM_TIME = 50.0


class ClickerState:
    """
    Simple class to keep track of the game state.
    """

    def __init__(self):
        self._time = 0.0
        self._current_cookies = 0.0
        self._total_cookies = 0.0
        self._cps = 1.0
        self._history = [(0.0, None, 0.0, 0.0)]

    def __str__(self):
        """
Example #10
0
"""
Student code for Word Wrangler game
"""

import urllib2
import codeskulptor
import poc_wrangler_provided as provided

codeskulptor.set_timeout(100)

WORDFILE = "assets_scrabble_words3.txt"

# Functions to manipulate ordered word lists


def remove_duplicates(list1):
    """
    Eliminate duplicates in a sorted list.

    Returns a new sorted list with the same elements in list1, but
    with no duplicates.

    This function can be iterative.
    """
    result = []
    for item in list1:
        if item not in result:
            result.append(item)
    return result

Example #11
0
"""
Provided code for Application portion of Module 2
"""

# general imports
import urllib2
import random
import time
import math
import poc_queue

# CodeSkulptor import
import simpleplot
import codeskulptor
codeskulptor.set_timeout(2400)

# Desktop imports
#import matplotlib.pyplot as plt

############################################
# Provided code


def copy_graph(graph):
    """
    Make a copy of a graph
    """
    new_graph = {}
    for node in graph:
        new_graph[node] = set(graph[node])
    return new_graph
Example #12
0
import math
import random
import urllib2
import alg_cluster
import simpleplot

# conditional imports
if DESKTOP:
    import alg_project3_solution  # desktop project solution
    import alg_clusters_matplotlib
else:
    import user41_3cfYOvazCo_14 as alg_project3_solution  # CodeSkulptor project solution
    import alg_clusters_simplegui
    import codeskulptor
    codeskulptor.set_timeout(9600)

###################################################
# Code to load data tables

# URLs for cancer risk data tables of various sizes
# Numbers indicate number of counties in data table

DIRECTORY = "http://commondatastorage.googleapis.com/codeskulptor-assets/"
DATA_3108_URL = DIRECTORY + "data_clustering/unifiedCancerData_3108.csv"
DATA_896_URL = DIRECTORY + "data_clustering/unifiedCancerData_896.csv"
DATA_290_URL = DIRECTORY + "data_clustering/unifiedCancerData_290.csv"
DATA_111_URL = DIRECTORY + "data_clustering/unifiedCancerData_111.csv"


def load_data_table(data_url):
Example #13
0
# -*- encoding: utf-8 -*-
""" Cookie Clicker Simulator - analysis for choosing the best strategy """
# use following link to test the program in 'codeskulptor': http://www.codeskulptor.org/#user45_YHl0aZhb0i_3.py

import math
import poc_clicker_provided as provided
try:
    import simpleplot  # access to plotting module
    import codeskulptor
    codeskulptor.set_timeout(20)  # Used to increase the timeout, if necessary
except ImportError:
    import SimpleGUICS2Pygame.simpleplot as simpleplot  # CodeSkulptor plotting module stand alone version - 'simpleplot._block()' required to prevent the plotting window from disappearing

# Constants
SIM_TIME = 10000000000.0  # this is the SIMULATION TIME, for testing, we will keep it smaller


class ClickerState:
    """ Simple class to keep track of the game state. """
    def __init__(self):
        self._total_cookies = 0.0
        self._current_cookies = 0.0
        self._time = 0.0
        self._cps = 1.0
        self._history = [
            (0.0, None, 0.0, 0.0)
        ]  # Each tuple in the list will contain 4 values: a time, an item that was bought at that time (or None), the cost of the item, and the total number of cookies produced by that time

    def __str__(self):
        """ Return human readable state """
        message = "Curent time       : " + str(self.get_time())+ "\nCurrent cookies   : " + str(self.get_cookies()) + "\nCurrent CPS       : " + str(self.get_cps()) \
Example #14
0
"""
Cookie Clicker Simulator
"""

import simpleplot

# Used to increase the timeout, if necessary
import codeskulptor, math
codeskulptor.set_timeout(4)

import poc_clicker_provided as provided

# Constants
SIM_TIME = 10000000000.0


class ClickerState:
    """
    Simple class to keep track of the game state.
    """
    def __init__(self):
        self._total_cookies = 0.0
        self._current_cookies = 0
        self._current_time = 0.0
        self._cps = 1.0
        self._item = None
        self._cost = 0.0
        self._lst = [(0.0, None, 0.0, 0.0)]

    def __str__(self):
        """
https://bitbucket.org/OPiMedia/simpleguics2pygame

GPLv3 --- Copyright (C) 2013, 2014 Olivier Pirson
http://www.opimedia.be/
"""

import math

try:
    from user38_ZmhOVHGm2lhVRhk import codeskulptor_is, hex2

    import simplegui

    from codeskulptor import set_timeout

    set_timeout(10)
except ImportError:
    from SimpleGUICS2Pygame.codeskulptor_lib import codeskulptor_is, hex2

    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

    simplegui.Frame._hide_status = True


#
# Global constants
###################
_FPS_AVERAGE = not codeskulptor_is()  # draw FPS average
                                      #   (only with SimpleGUICS2Pygame)

CANVAS_WIDTH = 256