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
''' | |
http://rosettacode.org/wiki/Knapsack_problem/0-1 | |
Knapsack problem/0-1 | |
A tourist wants to make a good trip at the weekend with his friends. | |
They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. | |
He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it, and it will have to last the whole day. |
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
''' | |
http://rosettacode.org/wiki/Hash_join | |
Implement the "hash join" algorithm, and demonstrate that it passes the test-case listed below. | |
You should represent the tables as data structures that feel natural in your programming language. | |
Guidance | |
The "hash join" algorithm consists of two steps: | |
Hash phase: Create a multimap from one of the two tables, mapping from each join column value to all the rows that contain it. |
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
''' | |
Take the following inputs in shorthand range, and translate them to longhand range. | |
1,6,4,9,1,6 => [1, 6, 14, 19, 21, 26] | |
2,9..9,9 => [2, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 29] | |
5,7,0,1,9,4 => [5, 7, 10, 11, 19, 24] | |
''' |
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
''' | |
http://rosettacode.org/wiki/Jaro_distance | |
d = 0 if no matching characters | |
otherwise d = (1/3) * (m/len(s1) + m/len(s2) + (m-(transpose/2))/m ) | |
characters match if distance >= (max(len(s1), len(s2))/2)-1 | |
if distance != 0, counts as a transpose | |
''' | |
def JaroDistance(s1, s2): |
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
''' | |
Following up on yesterday... Given a sorted list of distinct integers, write a function that returns whether there *any subset combinations* in the list that add up to 0. For example, you would return true if `[-8, 3, 5, 11]` are in the list, because -8 + 3 + 5 = 0. Also return true if 0 appears in the list. | |
''' | |
from itertools import combinations | |
def findSubset(mylist): | |
if len(mylist)==0: return False | |
elif len(mylist)==1: return(mylist[0]==0) | |
else: |
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
''' | |
An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond. | |
Replace letters with digits, by converting each character from base 36 to base 10, e.g. AU0000XVGZA3 →1030000033311635103. | |
Perform the Luhn test on this base-10 number. | |
US0378331005:TRUE | |
US0373831005:FALSE | |
U50378331005:FALSE | |
AU0000XVGZA3:TRUE |
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
''' | |
rosettacode.org/wiki/Rep-string | |
Given a series of ones and zeroes in a string, define a repeated string or rep-string as a string which is created by repeating a substring of the first N characters of the string truncated on the right to the length of the input string, and in which the substring appears repeated at least twice in the original. | |
For example, the string 10011001100 is a rep-string as the leftmost four characters of 1001 are repeated three times and truncated on the right to give the original string. | |
Note that the requirement for having the repeat occur two or more times means that the repeating unit is never longer than half the length of the input string. | |
10011 10011 |
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
''' | |
rosettacode.org/wiki/Sum_to_100 | |
brute force solution | |
https://repl.it/Hmhz/20 | |
''' | |
# http://stackoverflow.com/questions/34559663/convert-decimal-to-ternarybase3-in-python | |
def decimalToTernary (n): | |
if n == 0: | |
return '0' |
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
''' | |
Given a sorted list of distinct integers, write a function that returns whether there are two integers in the list that add up to 0. For example, you would return true if both -14435 and 14435 are in the list, because -14435 + 14435 = 0. Also return true if 0 appears in the list. | |
[1, 2, 3] -> false | |
[-5, -3, -1, 2, 4, 6] -> false | |
https://repl.it/HmSh/10 | |
''' | |
test1 = [] #False |
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 PIL import Image, ImageDraw | |
import os, math | |
#SETTINGS | |
WIDTH_RATIO = 3 #Ratio of image min width to watermark width | |
MIN_WIDTH = 200 #Minimum width of watermark. In my watermark, it is 1/3 of the normal width | |
MIN_HEIGHT = 40 #Minimum height of watermark. In my watermark ,it is 1/3 of the normal height | |
WATERMARK_LOCATION = "watermark.png" | |
#Most helpful source: http://stackoverflow.com/questions/13662184/python-pil-lighten-transparent-image-and-paste-to-another-one |