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
setwd("C:/big data/kaggle/titanic/") | |
library(ggplot2) | |
library(caret) | |
library(doParallel) | |
library(randomForest) | |
library(stringr) | |
registerDoParallel(detectCores()) |
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
function f = eq(z) | |
x=z(1); | |
y=z(2); | |
s=z(3); | |
f(1)=3*x - 24; | |
f(2)=x + y - 25; | |
f(3)=y - s - 8; | |
end | |
guess=[2 3 4] |
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
# you can use print for debugging purposes, e.g. | |
# print "this is a debug message" | |
def solution(N): | |
q = [(1,)] | |
visited = set() | |
for seq in q: | |
s = sum(seq) | |
if s == N: |
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
library(ggplot2) | |
library(reshape2) | |
# Multiple plot function | |
# | |
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) | |
# - cols: Number of columns in layout | |
# - layout: A matrix specifying the layout. If present, 'cols' is ignored. | |
# | |
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), |
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 solution(T): | |
amplitudes = [] | |
if (T[1] is None and T[2] is None): | |
return 0 | |
if (T[1] is not None): | |
walk(T[1], T[0], T[0], amplitudes) | |
if (T[2] is not None): | |
walk(T[2], T[0], T[0], amplitudes) | |
return max(amplitudes) |
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 timeit | |
def get_table(): | |
table = [] | |
with open("IntegerArray.txt", 'r') as f: | |
for line in f: | |
table.append(int(line)) | |
return table |
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
from collections import Counter | |
from itertools import chain | |
import timeit | |
from bisect import insort | |
import numpy as np | |
from collections import namedtuple | |
def get_data(): | |
return [(1920, 1939), (1911, 1944), (1920, 1955), (1938, 1939), (1937, 1940), |
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 quicksort(arr): | |
""" Quicksort a list | |
:type arr: list | |
:param arr: List to sort | |
:returns: list -- Sorted list | |
""" | |
if not arr: | |
return [] |
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
# method helps with fact that enumerate from reversed | |
# won't yield reversed indexes | |
def reverse_enum(L): | |
# guaranteed to NOT make any extra copy or search operations, O(1) | |
for index in reversed(xrange(len(L))): | |
yield index, L[index] | |
def solution(A): | |
top = list() |
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 solution(A): | |
min_avg_value = (A[0] + A[1])/2.0 # The mininal average | |
min_avg_pos = 0 # The begin position of the first | |
# slice with mininal average | |
for index in xrange(0, len(A)-2): | |
# Try the next 2-element slice | |
if (A[index] + A[index+1]) / 2.0 < min_avg_value: | |
min_avg_value = (A[index] + A[index+1]) / 2.0 | |
min_avg_pos = index |
OlderNewer