This file contains 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
listofMultiples factor1 factor2 l = | |
let p x = | |
| x `mod` factor1 == 0 = True | |
| x `mod` factor2 == 0 = True | |
| otherwise = False | |
in filter p [1..l] |
This file contains 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
def warshall(matrix): | |
n = len(matrix) | |
for k in range(n): | |
for i in range(n): | |
for j in range(n): | |
if matrix[i][k] and matrix[k][j]: | |
matrix[i][j] = 1 | |
return matrix | |
matrix = [[0, 0, 0, 1], |
This file contains 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
cheeses={'cheddar':('A235-4','A236-1','A236-2','A236-3','A236-5','C31-1','C31-2'),'mozarella':('Q456-9','Q456-8','A234-5','Q457-1','Q457-2'),'gombost':('ZLAFS55-4','ZLAFS55-9','GOMBOS-7','A236-4'),'geitost':('SPAZ-1','SPAZ-3','EMACS45-0'),'portsalut':('B15-1','B15-2','B15-3','B15-4','B16-1','B16-2','B16-4'),'camembert':('A243-1','A234-2','A234-3','A234-4','A235-1','A235-2','A235-3'),'ridder':('GOMBOS-4','B16-3'),} | |
for item in cheeses.items(): | |
infected = ["A234","A235", "B13", "B14", "B15", "C31"] | |
for shelves in item[1:]: | |
if any(infected_shelf in shelf for infected_shelf in infected for shelf in shelves): | |
print(item[0]) | |
break |
This file contains 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
### Keybase proof | |
I hereby claim: | |
* I am andbroby on github. | |
* I am andbroby (https://keybase.io/andbroby) on keybase. | |
* I have a public key whose fingerprint is 1F9A A6E9 8E59 19F2 2D6D 2D83 3EB0 E4FE EE3C B2A1 | |
To claim this, I am signing this object: |
This file contains 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
import java.util.regex.Pattern; | |
public class EmailPattern { | |
private static Pattern pattern = Pattern.compile("(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\ |
This file contains 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
def f(x): | |
def g(y): | |
def h(z): | |
print(x,y,z) | |
return h | |
return g |
This file contains 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
import string | |
import sys | |
def re_to_postfix(infix): | |
precedence = { | |
'|': 1, | |
'.': 2, | |
'*': 3, | |
'+': 3, | |
'?': 3 |
This file contains 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
def shunting_yard(infix): | |
precedence = { | |
'^': 3, | |
'*': 2, | |
'/': 2, | |
'+': 1, | |
'-': 1 | |
} | |
operators = precedence.keys() | |
l_associative = ['*', '/', '+', '-'] |
This file contains 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
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show, Read, Eq) | |
singleton :: a -> Tree a | |
singleton x = Node x EmptyTree EmptyTree | |
treeInsert :: (Ord a) => a -> Tree a -> Tree a | |
treeInsert x EmptyTree = singleton x | |
treeInsert x (Node a left right) | |
| x == a = Node x left right | |
| x < a = Node a (treeInsert x left) right |