This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from math import floor,sqrt | |
| class Spiral(): | |
| """ | |
| This class creates a spiral starting from 1..elements | |
| """ | |
| # | |
| # Define up/down & left/right step functions | |
| # | |
| def move_right(self,x, y): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Advent problem from day one - http://adventofcode.com/2017/day/1 | |
| # | |
| def captcha(myStr): | |
| return sum([int(myStr[c]) for c in range(-1,len(myStr)-1) if myStr[c]==myStr[c+1]]) | |
| myStrs = {'1122':3,'1111':4,'1234':0,'91212129':9} | |
| if __name__ == '__main__': | |
| for m in myStrs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Toy function that has 1 required arg, then allows a simple open-ended list of args (tuple) | |
| # and finally handles key=val list arguments stored as a dict | |
| # | |
| def varargs(req, *args, **kwargs): | |
| print("req=",req) | |
| if args: | |
| print("args=",args) | |
| if kwargs: | |
| print("kwargs=",kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Very simple "Hello World" type machine learning intro program that uses a decision tree classifier | |
| # | |
| from sklearn import tree | |
| # | |
| print("Features = [Weight, skin-type] e.g.[140 gms, 'smooth' = 1] , [180 gms, 'bumpy' = 0 ]") | |
| features = [[140,1],[130,1],[150,1],[170,0],[190,0]] | |
| print("Raw data = ",features) | |
| # | |
| print("For each label => apple (0) , orange (1)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import * | |
| def show(iterable): | |
| first = None | |
| for i, item in enumerate(iterable, 1): | |
| if first != item[0]: | |
| if first is not None: | |
| print() | |
| first = item[0] | |
| print(''.join(item), end=' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| The Number Guess Game | |
| Guess the random number the computer has chosen. | |
| After each try, if unsuccessful, the program will help by narrowing the bounds to guess in. | |
| This helps to teach binary searches, where you chop midway between the ranges each time to | |
| minimize the number of guesses required | |
| Type 'q' to quit the program | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Calculate pi using Nilakantha series | |
| http://www.codeproject.com/Articles/813185/Calculating-the-Number-PI-Through-Infinite-Sequenc | |
| π = 3 + (4/(2*3*4)) - (4/(4*5*6)) + (4/(6*7*8)) - (4/(8*9*10)) ... | |
| Or another series | |
| http://www-history.mcs.st-andrews.ac.uk/Biographies/Nilakantha.html |