code stringlengths 1 1.49M | vector listlengths 0 7.38k | snippet listlengths 0 7.38k |
|---|---|---|
# sandbox for ast...
import ast
source = '''s=s+x'''
node = ast.parse(source, mode='exec')
from pprint import pprint
pprint( ast.dump(node, annotate_fields=False, include_attributes=False) )
#~ print (eval(compile(node, '<string>', mode='eval')))
"""
Module(
body=[
Assign(
targets=[Name(id=... | [
[
1,
0,
0.0392,
0.0196,
0,
0.66,
0,
809,
0,
1,
0,
0,
809,
0,
0
],
[
14,
0,
0.0784,
0.0196,
0,
0.66,
0.1429,
703,
1,
0,
0,
0,
0,
3,
0
],
[
14,
0,
0.098,
0.0196,
0,
0... | [
"import ast",
"source = '''s=s+x'''",
"node = ast.parse(source, mode='exec')",
"from pprint import pprint",
"pprint( ast.dump(node, annotate_fields=False, include_attributes=False) )",
"\"\"\"\nModule(\n body=[\n Assign(\n targets=[Name(id='s', ctx=Store())],\n value=BinOp(... |
# http://stackoverflow.com/questions/1515357/simple-example-of-how-to-use-ast-nodevisitor
#~ http://docs.python.org/3/library/ast.html
#~ http://eli.thegreenplace.net/wp-content/uploads/2009/11/codegen.py
#~ http://dev.pocoo.org/hg/sandbox/file/852a1248c8eb/ast/codegen.py
#~ https://github.com/llvmpy/llvmpy/blob/mas... | [
[
14,
0,
0.0571,
0.0217,
0,
0.66,
0,
908,
1,
0,
0,
0,
0,
3,
0
],
[
14,
0,
0.0897,
0.0326,
0,
0.66,
0.0588,
798,
1,
0,
0,
0,
0,
3,
0
],
[
14,
0,
0.1332,
0.0435,
0,
0... | [
"code_example1 = \"\"\"\nx = 5\nx = x + 3\n\"\"\"",
"code_example2 = \"\"\"\nL = [4, 5, 2]\nif L[0] > 4:\n print( L[0] )\nL[1] = 10\n\"\"\"",
"code_example3b = \"\"\"\nA = [2, 0, 4, 3]\nmax = 0\nfor x in A:\n if x > max : \n max = x\n print( x, max )\n\"\"\"",
"code_example3 = \"\"\"\nA ... |
# -*- coding: utf-8 -*-
"""
codegen
~~~~~~~
Extension to ast that allow ast -> CPP code generation.
:copyright: Copyright 2008 by Armin Ronacher (adapted for C++ by Jurgis Pralgauskis)
:license: BSD.
https://pypi.python.org/pypi/codegen
also similar: http://svn.python.org/view/python/tru... | [
[
8,
0,
0.0106,
0.0174,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.0199,
0.0012,
0,
0.66,
0.0833,
809,
0,
1,
0,
0,
809,
0,
0
],
[
14,
0,
0.0255,
0.005,
0,
0.66... | [
"\"\"\"\n codegen\n ~~~~~~~\n\n Extension to ast that allow ast -> CPP code generation.\n\n :copyright: Copyright 2008 by Armin Ronacher (adapted for C++ by Jurgis Pralgauskis)\n :license: BSD.",
"from ast import *",
"BOOLOP_SYMBOLS = {\n And: 'and', # &&\n Or: 'or' # ||\n}... |
cat_sub_path='Testas-X'
def set_cat_sub_path( new ):
global cat_sub_path
cat_sub_path = new
__print_category("")
def __print_category(cat_name):
if cat_sub_path: cat_name = cat_sub_path+'/'+cat_name
cat_name = cat_name.rstrip('/')
print("\n\n$CATEGORY: $system$/%s\n" % cat_name )
... | [
[
14,
0,
0.0149,
0.0075,
0,
0.66,
0,
992,
1,
0,
0,
0,
0,
3,
0
],
[
2,
0,
0.041,
0.0299,
0,
0.66,
0.0909,
380,
0,
1,
0,
0,
0,
0,
1
],
[
14,
1,
0.0448,
0.0075,
1,
0.9... | [
"cat_sub_path='Testas-X'",
"def set_cat_sub_path( new ):\n global cat_sub_path\n cat_sub_path = new\n __print_category(\"\")",
" cat_sub_path = new",
" __print_category(\"\")",
"def __print_category(cat_name):\n if cat_sub_path: cat_name = cat_sub_path+'/'+cat_name\n cat_name = cat_nam... |
#~ TYPE = "GIFT"
#~ questions_file = "loops"
#~ questions_file = "matrix"
#~ questions_file = "functions"
#~ questions_file = "variables_and_conditions"
TYPE = "CLOZE"
questions_file = "fill_missing_var_if_while_lists"
#~ questions_file = "fill_missing_2_defs_morelists_dicts_etc"
#~ questions_file = "fill_missing_test... | [
[
14,
0,
0.0405,
0.0058,
0,
0.66,
0,
387,
1,
0,
0,
0,
0,
3,
0
],
[
14,
0,
0.0462,
0.0058,
0,
0.66,
0.0417,
155,
1,
0,
0,
0,
0,
3,
0
],
[
14,
0,
0.0694,
0.0058,
0,
0... | [
"TYPE = \"CLOZE\"",
"questions_file = \"fill_missing_var_if_while_lists\"",
"questions_file = 'Questions_tpl.' + questions_file",
"CONVERT2CPP=False",
"TRACE_STACK = False",
"MENTION_UNGENERATED_QUESTIONS = False",
"import inspect",
"from importlib import __import__",
"import sys",
"import linecac... |
import re
import helpers
import random
import hashlib
tpl = """#include <iostream>
/*directives*/
using namespace std;
/*functions*/
int main(){
/*code*/
return 0;
}
"""
COMPILE = False
with open('Questions_tpl/'+'questions_cpp_Errors.cpp') as f:
examples = f.read()
examples = examples.split('//')
quest... | [
[
1,
0,
0.0069,
0.0069,
0,
0.66,
0,
540,
0,
1,
0,
0,
540,
0,
0
],
[
1,
0,
0.0139,
0.0069,
0,
0.66,
0.0833,
510,
0,
1,
0,
0,
510,
0,
0
],
[
1,
0,
0.0208,
0.0069,
0,
... | [
"import re",
"import helpers",
"import random",
"import hashlib",
"tpl = \"\"\"#include <iostream>\n/*directives*/\n\nusing namespace std;\n\n/*functions*/\n\nint main(){",
"COMPILE = False",
" examples = f.read()",
"examples = examples.split('//')",
"questions = []",
"answers = []",
"counter... |
import re
import os
import helpers
#~ TASK = 'py2cpp' #can convert: py2img, cpp2img, py2cpp
#~ TASK = 'cpp2img' #can convert: py2cpp, py2img, cpp2img, *2img
TASK = 'cpp2img'
#~ NAME_SEARCH = ''
NAME_SEARCH = 'nonrandom'
LINENOS4IMG = False
html_entities = {
'"': '"',
'&': '&',
' ': ' ',... | [
[
1,
0,
0.0039,
0.0039,
0,
0.66,
0,
540,
0,
1,
0,
0,
540,
0,
0
],
[
1,
0,
0.0079,
0.0039,
0,
0.66,
0.0769,
688,
0,
1,
0,
0,
688,
0,
0
],
[
1,
0,
0.0118,
0.0039,
0,
... | [
"import re",
"import os",
"import helpers",
"TASK = 'cpp2img'",
"NAME_SEARCH = 'nonrandom'",
"LINENOS4IMG = False",
"html_entities = {\n '"': '\"',\n '&': '&',\n ' ': ' ',\n}",
"html_entities_more_less ={\n '>': '>',\n '<': '<',\n}",
"html_entities.update( html_ent... |
try:
from tpl_helpers import __rand_questions, __print_category
except ImportError:
from .tpl_helpers import __rand_questions, __print_category
def Loop_C( _list=[2, 8, 4, 6, 9, 0, 1] ): # {=%(track['S`1'])s}
S = 0 # >>>S`0
n = 0
for x in _list:
n = n + 1; S = S + x; print(S) # >>>S`... | [
[
7,
0,
0.05,
0.08,
0,
0.66,
0,
0,
0,
1,
0,
0,
0,
0,
0
],
[
1,
1,
0.04,
0.02,
1,
0.85,
0,
125,
0,
2,
0,
0,
125,
0,
0
],
[
1,
1,
0.08,
0.02,
1,
0.85,
0,
125,... | [
"try:\n from tpl_helpers import __rand_questions, __print_category\nexcept ImportError:\n from .tpl_helpers import __rand_questions, __print_category",
" from tpl_helpers import __rand_questions, __print_category",
" from .tpl_helpers import __rand_questions, __print_category",
"def Loop_C( _list=... |
import tpl_helpers # calls parent_dir_2path() -- to let imports
from generate_via_decorators import generate_calls, set_cat_sub_path, call_functions_by_decorators
@generate_calls(
#_pinigai = [-10, 0, 1, 5, 9] ,
#groups = ["less", 1, "equal", 1, "more", 3] ,
_pini... | [
[
1,
0,
0.0112,
0.0112,
0,
0.66,
0,
125,
0,
1,
0,
0,
125,
0,
0
],
[
1,
0,
0.0225,
0.0112,
0,
0.66,
0.2,
246,
0,
3,
0,
0,
246,
0,
0
],
[
2,
0,
0.1461,
0.0787,
0,
0.6... | [
"import tpl_helpers # calls parent_dir_2path() -- to let imports",
"from generate_via_decorators import generate_calls, set_cat_sub_path, call_functions_by_decorators",
"def ifMoreLess0_noEqual( _pinigai ): \n pinigai = _pinigai \n if pinigai > 0:\n print( \"Turim\", pinigai )\n if pinigai <... |
try:
from tpl_helpers import __rand_questions, __print_category
except ImportError:
from .tpl_helpers import __rand_questions, __print_category
from random import randint as rint, choice
# **********************************
__print_category('Variables and Conditions', sub_path="FillGaps", _type="CLOZE")
... | [
[
7,
0,
0.0153,
0.0245,
0,
0.66,
0,
0,
0,
1,
0,
0,
0,
0,
0
],
[
1,
1,
0.0123,
0.0061,
1,
0.48,
0,
125,
0,
2,
0,
0,
125,
0,
0
],
[
1,
1,
0.0245,
0.0061,
1,
0.48,
... | [
"try:\n from tpl_helpers import __rand_questions, __print_category\nexcept ImportError:\n from .tpl_helpers import __rand_questions, __print_category",
" from tpl_helpers import __rand_questions, __print_category",
" from .tpl_helpers import __rand_questions, __print_category",
"from random import... |
from random import randint
#~ from helpers import *
#~ __print_category('FUNCTIONS')
def __rand_questions(fun, args_intervals, how_many):
__print_category(fun.__name__+'_RANDOM')
for i in range(how_many):
args = [randint(*interval) for interval in args_intervals]
fun( *args )
def __... | [
[
1,
0,
0.0086,
0.0043,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
2,
0,
0.0386,
0.0215,
0,
0.66,
0.0286,
325,
0,
3,
0,
0,
0,
0,
4
],
[
8,
1,
0.0343,
0.0043,
1,
0.... | [
"from random import randint",
"def __rand_questions(fun, args_intervals, how_many):\n __print_category(fun.__name__+'_RANDOM')\n for i in range(how_many):\n args = [randint(*interval) for interval in args_intervals]\n fun( *args )",
" __print_category(fun.__name__+'_RANDOM')",
" for... |
from random import randint, choice
#~ from helpers import *
#~ __print_category('FUNCTIONS')
def __rand_questions(fun, args_intervals, how_many):
__print_category(fun.__name__+'_RANDOM')
for i in range(how_many):
args = [randint(*interval) for interval in args_intervals]
fun( *args )
import ... | [
[
1,
0,
0.0057,
0.0029,
0,
0.66,
0,
715,
0,
2,
0,
0,
715,
0,
0
],
[
2,
0,
0.0229,
0.0143,
0,
0.66,
0.0233,
325,
0,
3,
0,
0,
0,
0,
4
],
[
8,
1,
0.0201,
0.0029,
1,
0.... | [
"from random import randint, choice",
"def __rand_questions(fun, args_intervals, how_many):\n __print_category(fun.__name__+'_RANDOM')\n for i in range(how_many):\n args = [randint(*interval) for interval in args_intervals]\n fun( *args )",
" __print_category(fun.__name__+'_RANDOM')",
... |
# Also of interest:
# http://docs.moodle.org/25/en/Programmed_responses_question_type
# http://docs.moodle.org/25/en/question/type/correctwriting -- sakinio struktūros klausimai
# http://docs.moodle.org/25/en/Multinumerical_question_type
# http://docs.moodle.org/dev/Opaque
#~ from random import randint
#~ def Arith... | [
[
7,
0,
0.1555,
0.0336,
0,
0.66,
0,
0,
0,
1,
0,
0,
0,
0,
0
],
[
1,
1,
0.1513,
0.0084,
1,
0.5,
0,
125,
0,
2,
0,
0,
125,
0,
0
],
[
1,
1,
0.1681,
0.0084,
1,
0.5,
0... | [
"try:\n from tpl_helpers import __rand_questions, __print_category\nexcept ImportError:\n from .tpl_helpers import __rand_questions, __print_category",
" from tpl_helpers import __rand_questions, __print_category",
" from .tpl_helpers import __rand_questions, __print_category",
"def Arithmetics_si... |
from random import randint
import os
import inspect
def __print_category(cat_name, sub_path='Testas-X', _type="GIFT"):
if sub_path: cat_name = sub_path+'/'+cat_name
if _type=="GIFT":
print("\n$CATEGORY: $system$/%s\n" % cat_name )
if _type=="CLOZE":
print("""
<... | [
[
1,
0,
0.0149,
0.0149,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.0299,
0.0149,
0,
0.66,
0.125,
688,
0,
1,
0,
0,
688,
0,
0
],
[
1,
0,
0.0448,
0.0149,
0,
0... | [
"from random import randint",
"import os",
"import inspect",
"def __print_category(cat_name, sub_path='Testas-X', _type=\"GIFT\"):\n\n if sub_path: cat_name = sub_path+'/'+cat_name\n \n if _type==\"GIFT\":\n print(\"\\n$CATEGORY: $system$/%s\\n\" % cat_name )\n \n if _type==\"CLOZE\... |
# http://docs.python.org/3.2/tutorial/errors.html
# http://docs.python.org/3.2/library/exceptions.html#bltin-exceptions
"""
invalid syntax
name '….' is not defined
unindent does not match any
outer indentation level
expected an indented block
can't assign to operator
can't assign to literal
"""
"""
a = 1
while b <... | [
[
8,
0,
0.0567,
0.0638,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
8,
0,
0.1454,
0.0993,
0,
0.66,
0.0909,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.2553,
0.0213,
0,
0.66,
... | [
"\"\"\"\ninvalid syntax \nname '….' is not defined\nunindent does not match any \nouter indentation level \nexpected an indented block\ncan't assign to operator\ncan't assign to literal",
"\"\"\"\na = 1\nwhile b < 20\n Print(b)\n tmp = b\n if a > b:\n print(\"a daugiau\n eli... |
try:
from tpl_helpers import __rand_questions, __print_category
except ImportError:
from .tpl_helpers import __rand_questions, __print_category
def test_gap_with_alternatives(_a=7):
x = _a
if x > 10: # alternative could be in C: "or" vs "||" HIDE(x >)~(=x>\=)
print("big")
else: ... | [
[
7,
0,
0.0287,
0.046,
0,
0.66,
0,
0,
0,
1,
0,
0,
0,
0,
0
],
[
1,
1,
0.023,
0.0115,
1,
0.85,
0,
125,
0,
2,
0,
0,
125,
0,
0
],
[
1,
1,
0.046,
0.0115,
1,
0.85,
0,... | [
"try:\n from tpl_helpers import __rand_questions, __print_category\nexcept ImportError:\n from .tpl_helpers import __rand_questions, __print_category",
" from tpl_helpers import __rand_questions, __print_category",
" from .tpl_helpers import __rand_questions, __print_category",
"def test_gap_with_... |
import inspect
import pygments
import re
#~ from Questions_tpl.variables_and_conditions import *
from pygments.lexers import PythonLexer, CppLexer
pylexer = lexer = PythonLexer(ensurenl=False)
cpplexer = CppLexer(ensurenl=False)
def adapt_code_spacing(code, unneeded='', needed_once=' ', ignore_space_after_escape_... | [
[
1,
0,
0.0197,
0.0066,
0,
0.66,
0,
878,
0,
1,
0,
0,
878,
0,
0
],
[
1,
0,
0.0263,
0.0066,
0,
0.66,
0.0909,
638,
0,
1,
0,
0,
638,
0,
0
],
[
1,
0,
0.0329,
0.0066,
0,
... | [
"import inspect",
"import pygments",
"import re",
"from pygments.lexers import PythonLexer, CppLexer",
"pylexer = lexer = PythonLexer(ensurenl=False)",
"cpplexer = CppLexer(ensurenl=False)",
"def adapt_code_spacing(code, unneeded='', needed_once=' ', ignore_space_after_escape_chars=True, lang='py' ): #... |
# -*- coding: utf-8 -*-
"""
codegen
~~~~~~~
Extension to ast that allow ast -> python code generation.
:copyright: Copyright 2008 by Armin Ronacher.
:license: BSD.
"""
from ast import *
BOOLOP_SYMBOLS = {
And: 'and',
Or: 'or'
}
BINOP_SYMBOLS = {
Add: '+',
S... | [
[
8,
0,
0.0105,
0.0157,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.0192,
0.0017,
0,
0.66,
0.0833,
809,
0,
1,
0,
0,
809,
0,
0
],
[
14,
0,
0.027,
0.007,
0,
0.66,... | [
"\"\"\"\n codegen\n ~~~~~~~\n\n Extension to ast that allow ast -> python code generation.\n\n :copyright: Copyright 2008 by Armin Ronacher.\n :license: BSD.",
"from ast import *",
"BOOLOP_SYMBOLS = {\n And: 'and',\n Or: 'or'\n}",
"BINOP_SYMBOLS = {\n Add: '+',\n ... |
s = 5
for x in [1, 3, 2]:
print('1st', x)
if x > 2:
for z in range(2): print('2nd')
print('bla')
for i in range(x):
a = i
print('3rd', i)
print('back to 1st')
print('end')
| [
[
14,
0,
0.0909,
0.0909,
0,
0.66,
0,
553,
1,
0,
0,
0,
0,
1,
0
],
[
6,
0,
0.5455,
0.8182,
0,
0.66,
0.5,
190,
0,
0,
0,
0,
0,
0,
7
],
[
8,
1,
0.2727,
0.0909,
1,
0.42,
... | [
"s = 5",
"for x in [1, 3, 2]:\n print('1st', x)\n if x > 2:\n for z in range(2): print('2nd')\n print('bla')\n for i in range(x):\n a = i\n print('3rd', i)",
" print('1st', x)",
" if x > 2:\n for z in range(2): print('2nd')\n print('bla')\n ... |
import re
re_docs = re.compile(r'"""(.*?)"""', re.DOTALL)
import py2cpp
from pygments.lexers import PythonLexer
lexer = PythonLexer(ensurenl=False)
def delete_comments(src, containing=''):
lines = src.split('\n')
for nr, line in enumerate(lines):
for t in lexer.get_tokens( line ):
... | [
[
1,
0,
0.0041,
0.0041,
0,
0.66,
0,
540,
0,
1,
0,
0,
540,
0,
0
],
[
14,
0,
0.0083,
0.0041,
0,
0.66,
0.0526,
679,
3,
2,
0,
0,
821,
10,
1
],
[
1,
0,
0.0207,
0.0041,
0,
... | [
"import re",
"re_docs = re.compile(r'\"\"\"(.*?)\"\"\"', re.DOTALL)",
"import py2cpp",
"from pygments.lexers import PythonLexer",
"lexer = PythonLexer(ensurenl=False)",
"def delete_comments(src, containing=''):\n lines = src.split('\\n')\n for nr, line in enumerate(lines):\n for t in lexer.ge... |
import json
import re
file_name = 'a' #'demo'
with open(file_name+'.trace.json', 'r') as f:
trace_json_txt = f.read()
#~ data = json.load ( trace_json_txt )
data = eval ( trace_json_txt )
code = data['code']
linecodes = code.split('\n')
trace = data['trace']
print ( '\n### TRACE: ', json.dumps(trace, sort_keys... | [
[
1,
0,
0.0033,
0.0033,
0,
0.66,
0,
463,
0,
1,
0,
0,
463,
0,
0
],
[
1,
0,
0.0066,
0.0033,
0,
0.66,
0.0323,
540,
0,
1,
0,
0,
540,
0,
0
],
[
14,
0,
0.0133,
0.0033,
0,
... | [
"import json",
"import re",
"file_name = 'a' #'demo'",
" trace_json_txt = f.read()",
"data = eval ( trace_json_txt )",
"code = data['code']",
"linecodes = code.split('\\n')",
"trace = data['trace']",
"print ( '\\n### TRACE: ', json.dumps(trace, sort_keys=True, indent=2) )",
"print ( '\\n### COD... |
#! /usr/bin/env python
# coding=utf8
class TBaseGraph:
def GetVertexCount(self):
return 0
def GetAdj(self, vertexNum):
return []
def GetWeight(self, fromV, toV):
return 0
class TGraphMatrix(TBaseGraph):
def __init__(self, matrix):
self.Matrix = matrix
def GetVert... | [
[
3,
0,
0.0615,
0.0692,
0,
0.66,
0,
996,
0,
3,
0,
0,
0,
0,
0
],
[
2,
1,
0.0423,
0.0154,
1,
0.78,
0,
313,
0,
1,
1,
0,
0,
0,
0
],
[
13,
2,
0.0462,
0.0077,
2,
0.84,
... | [
"class TBaseGraph:\n def GetVertexCount(self):\n return 0\n\n def GetAdj(self, vertexNum):\n return []\n\n def GetWeight(self, fromV, toV):",
" def GetVertexCount(self):\n return 0",
" return 0",
" def GetAdj(self, vertexNum):\n return []",
" return [... |
import numpy as np
import numpy.random as nprand
import matplotlib.pyplot as plt
def spline(x, y, yp1 = 1e30, ypn = 1e30):
"""Spline method from nrbook. Computes theorical 2nd derivative on every point"""
n = len(x)
u=range(1,n)
y2 = [0]*n
if yp1 > 0.99e30:
y2[0]= 0.0
u[0]=0.0
else:
y2[0] = -0.5
u[0]=(... | [
[
1,
0,
0.0062,
0.0062,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0124,
0.0062,
0,
0.66,
0.1,
181,
0,
1,
0,
0,
181,
0,
0
],
[
1,
0,
0.0186,
0.0062,
0,
0.6... | [
"import numpy as np",
"import numpy.random as nprand",
"import matplotlib.pyplot as plt",
"def spline(x, y, yp1 = 1e30, ypn = 1e30):\n\t\"\"\"Spline method from nrbook. Computes theorical 2nd derivative on every point\"\"\"\n\tn = len(x)\n\tu=range(1,n)\n\ty2 = [0]*n\n\tif yp1 > 0.99e30:\n\t\ty2[0]= 0.0\n\t\t... |
import numpy as np
import re # regexp
import matplotlib.pyplot as plt
import splines as sp
################################################################
# Airfoil : load profile of a wing
#
# Reads a file whose lines contain coordinates of points,
# separated by an empty line.
# Every line not containing a couple o... | [
[
1,
0,
0.0213,
0.0213,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0426,
0.0213,
0,
0.66,
0.0909,
540,
0,
1,
0,
0,
540,
0,
0
],
[
1,
0,
0.0638,
0.0213,
0,
... | [
"import numpy as np",
"import re # regexp",
"import matplotlib.pyplot as plt",
"import splines as sp",
"def load_foil(file):\n f = open(file, 'r')\n matchline = lambda line: re.match(r\"\\s*([\\d\\.-]+)\\s*([\\d\\.-]+)\", line)\n extra = []; intra = []\n rextra = False; rintra = False\n f... |
import numpy as np
import splines as sp
import matplotlib.pyplot as plt
import time
import numpy.random as nprand
def Left(f, a, b):
return (b - a) * f(a)
def Middle(f, a, b):
return (b - a) * f( (a+b)/2. )
def Middle_raf(f, a, b, epsilon, val = None):
bma = b-a
if (val == None):
val = bma * f( (a+b)/2. )
va... | [
[
1,
0,
0.0065,
0.0065,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.013,
0.0065,
0,
0.66,
0.0667,
774,
0,
1,
0,
0,
774,
0,
0
],
[
1,
0,
0.0195,
0.0065,
0,
0... | [
"import numpy as np",
"import splines as sp",
"import matplotlib.pyplot as plt",
"import time",
"import numpy.random as nprand",
"def Left(f, a, b):\n\treturn (b - a) * f(a)",
"\treturn (b - a) * f(a)",
"def Middle(f, a, b):\n\treturn (b - a) * f( (a+b)/2. )",
"\treturn (b - a) * f( (a+b)/2. )",
"... |
import numpy as np
import pylab as pl
import splines as sp
from integration import Length
from load_foil import load_foil
def f_lambda(f, Lambda, h):
"Returns the function f_lambda, with h = hmin or hmax"
return lambda x: (1 - Lambda) * f(x) + 3 * Lambda * h
def show_colored(f, a, b, colour = (0,0,1), width = 4... | [
[
1,
0,
0.0125,
0.0125,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.025,
0.0125,
0,
0.66,
0.1111,
735,
0,
1,
0,
0,
735,
0,
0
],
[
1,
0,
0.0375,
0.0125,
0,
0... | [
"import numpy as np",
"import pylab as pl",
"import splines as sp",
"from integration import Length",
"from load_foil import load_foil",
"def f_lambda(f, Lambda, h):\n\t\"Returns the function f_lambda, with h = hmin or hmax\"\n\treturn lambda x: (1 - Lambda) * f(x) + 3 * Lambda * h",
"\t\"Returns the fu... |
__author__ = 'grigory'
import sympy as smp
import copy
import scipy as sc
def ch(alpha, index, is_plus):
beta = copy.copy(alpha)
if is_plus:
if beta[2 * index + 1] > 0:
beta[2 * index + 1] -= 1
beta[2 * index] += 1
return beta
else:
if beta[2 * index] >... | [
[
14,
0,
0.0038,
0.0038,
0,
0.66,
0,
777,
1,
0,
0,
0,
0,
3,
0
],
[
1,
0,
0.0113,
0.0038,
0,
0.66,
0.0625,
533,
0,
1,
0,
0,
533,
0,
0
],
[
1,
0,
0.015,
0.0038,
0,
0.... | [
"__author__ = 'grigory'",
"import sympy as smp",
"import copy",
"import scipy as sc",
"def ch(alpha, index, is_plus):\n beta = copy.copy(alpha)\n if is_plus:\n if beta[2 * index + 1] > 0:\n beta[2 * index + 1] -= 1\n beta[2 * index] += 1\n return beta\n else:... |
import numpy as np
import pylab as plt
import matplotlib.pyplot as mp
### Methodes de choix du pas ###
def step_euler(y, t, h, f):
return h*f(y,t) + y
def step_ptmilieu(y, t, h, f):
return y + h*f( y + (h/2.) * f(y,t) , t+(h/2.) )
def step_heun(y,t,h,f):
return y + (h/2.) * ( f(y,t) + f( y + h*f(y,t) ... | [
[
1,
0,
0.0122,
0.0122,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0244,
0.0122,
0,
0.66,
0.1,
735,
0,
1,
0,
0,
735,
0,
0
],
[
1,
0,
0.0366,
0.0122,
0,
0.6... | [
"import numpy as np",
"import pylab as plt",
"import matplotlib.pyplot as mp",
"def step_euler(y, t, h, f):\n return h*f(y,t) + y",
" return h*f(y,t) + y",
"def step_ptmilieu(y, t, h, f):\n return y + h*f( y + (h/2.) * f(y,t) , t+(h/2.) )",
" return y + h*f( y + (h/2.) * f(y,t) , t+(h/2.) )"... |
#-*- coding=utf-8 -*-
import numpy as np
import matplotlib.pyplot as mp
from matplotlib.animation import ArtistAnimation
import partie1_methodes as p1
def SolveMaillon1(theta, w, g, l, N, times, meth):
"Fonction resolvant le problème du pendule simple"
h = times/N
eq = [(0.,[theta, w]),lambda X,t:np.array([X[1],(... | [
[
1,
0,
0.0065,
0.0032,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0097,
0.0032,
0,
0.66,
0.0556,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.0129,
0.0032,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"from matplotlib.animation import ArtistAnimation",
"import partie1_methodes as p1",
"def SolveMaillon1(theta, w, g, l, N, times, meth):\n\t\"Fonction resolvant le problème du pendule simple\"\n\th = times/N\n\teq = [(0.,[theta, w]),lambda X,t:np.array... |
import numpy as np
import matplotlib.pyplot as mp
import partie1_methodes as p1
### Test global ###
def test_meth():
"verifie l'exactitude de meth_epsilon (et donc de meth_n_step) dans plusieurs cas"
print "Tests de correction des methodes de resolution...\n"
# y = e^x
print "Equation : (y\'=y, y(0)=1) -> Solut... | [
[
1,
0,
0.0041,
0.0041,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0082,
0.0041,
0,
0.66,
0.0909,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.0123,
0.0041,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"import partie1_methodes as p1",
"def test_meth():\n\t\"verifie l'exactitude de meth_epsilon (et donc de meth_n_step) dans plusieurs cas\"\n\tprint(\"Tests de correction des methodes de resolution...\\n\")\n\t\n\t# y = e^x\n\tprint(\"Equation : (y\\'=y, ... |
import numpy as np
import partie1_methodes as meth
import matplotlib.pyplot as mp
def Malthus():
nmax = 200
x = np.arange(0.,10.+10./nmax,10./nmax)
mp.clf()
birth = 3.
death = 2.
eq = [(0., [7e9]), lambda X,t:np.array([(birth-death)*X[0]])]
res = meth.meth_n_step(eq, nmax, 10./nmax, m... | [
[
1,
0,
0.0076,
0.0076,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0153,
0.0076,
0,
0.66,
0.2,
50,
0,
1,
0,
0,
50,
0,
0
],
[
1,
0,
0.0229,
0.0076,
0,
0.66,... | [
"import numpy as np",
"import partie1_methodes as meth",
"import matplotlib.pyplot as mp",
"def Malthus():\n \n nmax = 200\n x = np.arange(0.,10.+10./nmax,10./nmax)\n\n mp.clf()\n birth = 3.\n death = 2.",
" nmax = 200",
" x = np.arange(0.,10.+10./nmax,10./nmax)",
" mp.clf()",... |
import numpy as np
import matplotlib.pyplot as mp
import partie1 as p1
def equation_2_corps(mA):
"""Cree une fonction decrivant les equations pour 2 corps pour le probleme de cauchy
Entree: mA reel masse du corps A
Sortie: f fonction equation du mouvement"""
def f(t,y):
return [y[2],y[3],(y... | [
[
1,
0,
0.0061,
0.0061,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0123,
0.0061,
0,
0.66,
0.1429,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.0184,
0.0061,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"import partie1 as p1",
"def equation_2_corps(mA):\n \"\"\"Cree une fonction decrivant les equations pour 2 corps pour le probleme de cauchy\n Entree: mA reel masse du corps A\n Sortie: f fonction equation du mouvement\"\"\"\n def f(t,y):\... |
import numpy as np
import matplotlib.pyplot as mp
import partie1 as p1
#######################################################
## Modele de population malthusiens (Malthus) ##
#######################################################
def EquationMalthus (b,d):
def f(t,y):
return [b*y[0]-d... | [
[
1,
0,
0.0115,
0.0115,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.023,
0.0115,
0,
0.66,
0.1111,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.0345,
0.0115,
0,
0... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"import partie1 as p1",
"def EquationMalthus (b,d):\n def f(t,y):\n return [b*y[0]-d*y[0]]\n return f",
" def f(t,y):\n return [b*y[0]-d*y[0]]",
" return [b*y[0]-d*y[0]]",
" return f",
"def ResolutionMalthus(y0, t... |
import numpy as np
import matplotlib.pyplot as mp
import partie5 as p5
import math
def Test_Video2Corps(r0,teta0,vr0,vteta0, t0, m, N, pas, nom):
res = p5.meca_2_corps(r0,teta0,vr0,vteta0,t0,m,N,pas)
minx = min(res[0])
maxx = max(res[0])
miny = min(res[1])
maxy = max(res[1])
for i in np.arange(... | [
[
1,
0,
0.0132,
0.0132,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0263,
0.0132,
0,
0.66,
0.1111,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.0395,
0.0132,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"import partie5 as p5",
"import math",
"def Test_Video2Corps(r0,teta0,vr0,vteta0, t0, m, N, pas, nom):\n res = p5.meca_2_corps(r0,teta0,vr0,vteta0,t0,m,N,pas)\n minx = min(res[0])\n maxx = max(res[0])\n miny = min(res[1])\n maxy = max(re... |
import numpy as np
import matplotlib.pyplot as mp
################################################
# Calcul d'un pas selon 4 methodes differentes #
################################################
def step_euler (y, t, h, f):
""" fonction calculant un seul pas par la methode d'Euler """
n = len(y)
fty = f... | [
[
1,
0,
0.0077,
0.0077,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0154,
0.0077,
0,
0.66,
0.1111,
596,
0,
1,
0,
0,
596,
0,
0
],
[
2,
0,
0.0885,
0.0615,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as mp",
"def step_euler (y, t, h, f):\n \"\"\" fonction calculant un seul pas par la methode d'Euler \"\"\"\n n = len(y)\n fty = f(t,y)\n res = []\n for i in np.arange(n):\n res.append(y[i]+h*fty[i])\n return res",
" \"\"\" fonction c... |
from os import listdir, system
from os.path import isfile, join
import re
import sys
import math
def digrafo(nodos, aristas, salida):
return '2 '+ str(nodos) + ' ' + str(aristas) + ' ' + '1' + ' ' + '1' + ' '\
+ salida +'_'+ str(nodos).zfill(5) +'_'+ str(aristas) + '.graph' + ' 0'
def dag(nodos, arista... | [
[
1,
0,
0.027,
0.027,
0,
0.66,
0,
688,
0,
2,
0,
0,
688,
0,
0
],
[
1,
0,
0.0541,
0.027,
0,
0.66,
0.1429,
79,
0,
2,
0,
0,
79,
0,
0
],
[
1,
0,
0.0811,
0.027,
0,
0.66,
... | [
"from os import listdir, system",
"from os.path import isfile, join",
"import re",
"import sys",
"import math",
"def digrafo(nodos, aristas, salida):\n\treturn '2 '+ str(nodos) + ' ' + str(aristas) + ' ' + '1' + ' ' + '1' + ' '\\\n\t+ salida +'_'+ str(nodos).zfill(5) +'_'+ str(aristas) + '.graph' + ' 0'"... |
from os import listdir, system
from os.path import isfile, join
import sys
from StringIO import StringIO
import re
if __name__ == '__main__':
mypath = '.'
output = sys.argv[1]
files = [ f for f in listdir(mypath) if isfile(join(mypath,f)) and re.match(output+'.*\.graph$', f) ]
mo = re.match('([0-9 a-z A... | [
[
1,
0,
0.037,
0.037,
0,
0.66,
0,
688,
0,
2,
0,
0,
688,
0,
0
],
[
1,
0,
0.0741,
0.037,
0,
0.66,
0.2,
79,
0,
2,
0,
0,
79,
0,
0
],
[
1,
0,
0.1111,
0.037,
0,
0.66,
... | [
"from os import listdir, system",
"from os.path import isfile, join",
"import sys",
"from StringIO import StringIO",
"import re",
"if __name__ == '__main__':\n\tmypath = '.'\n\toutput = sys.argv[1]\n\tfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) and re.match(output+'.*\\.graph$', f) ]\n... |
from os import listdir, system
from os.path import isfile, join
import re
import sys
import math
def digrafo(nodos, aristas, salida):
return '2 '+ str(nodos) + ' ' + str(aristas) + ' ' + '1' + ' ' + '1' + ' '\
+ salida +'_'+ str(nodos) +'_'+ str(aristas).zfill(5) + '.graph' + ' 0'
def dag(nodos, arista... | [
[
1,
0,
0.027,
0.027,
0,
0.66,
0,
688,
0,
2,
0,
0,
688,
0,
0
],
[
1,
0,
0.0541,
0.027,
0,
0.66,
0.1429,
79,
0,
2,
0,
0,
79,
0,
0
],
[
1,
0,
0.0811,
0.027,
0,
0.66,
... | [
"from os import listdir, system",
"from os.path import isfile, join",
"import re",
"import sys",
"import math",
"def digrafo(nodos, aristas, salida):\n\treturn '2 '+ str(nodos) + ' ' + str(aristas) + ' ' + '1' + ' ' + '1' + ' '\\\n\t+ salida +'_'+ str(nodos) +'_'+ str(aristas).zfill(5) + '.graph' + ' 0'"... |
import numpy as np
import newton as nw
import matplotlib.pyplot as plt
#------------------------------------------------------------------------#
# EQUILIBRE ELECTROSTATIQUE #
#------------------------------------------------------------------------#
def term_energy_E(n,k)... | [
[
1,
0,
0.0063,
0.0063,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0126,
0.0063,
0,
0.66,
0.0625,
270,
0,
1,
0,
0,
270,
0,
0
],
[
1,
0,
0.0189,
0.0063,
0,
... | [
"import numpy as np",
"import newton as nw",
"import matplotlib.pyplot as plt",
"def term_energy_E(n,k):\n \"Calcule les différents termes de la fonction à étudier\"\n def f(X): \n s = 0\n for i in np.arange(0,n):\n if(i != k):\n s = s + (1/(X[k]-X[i]))\n r... |
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
epsilon = 0.00000000000001
nmax = 1000
#------------------------------------------------------------------------#
# METHODE DE NEWTON-RAPHSON #
#-----------------------------------------------------... | [
[
1,
0,
0.0216,
0.0072,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0288,
0.0072,
0,
0.66,
0.0278,
596,
0,
1,
0,
0,
596,
0,
0
],
[
14,
0,
0.0432,
0.0072,
0,
... | [
"import numpy as np",
"import matplotlib.pyplot as plt",
"epsilon = 0.00000000000001",
"nmax = 1000",
"def newton_raphson(f, J, U0, N, epsilon):\n \"Implementation de la methode de newton-raphson pour une fonction f\"\n n = len(J[0]) #Dimension de l'espace de départ\n m = len(J) #Dimension de l'esp... |
#lista = [2,40,1,30,5] #en c se usa un vector n+1 dimension
def insertion_sort(list2):
for i in range(1, len(list2)):
j = i
while j > 0 and list2[j] < list2[j-1]:
list2[j], list2[j - 1] = list2[j-1], list2[j] #swap
j -= 1
return list2
def posMenor(ls,i,n):
posm = i
... | [
[
2,
0,
0.0645,
0.0753,
0,
0.66,
0,
413,
0,
1,
1,
0,
0,
0,
2
],
[
6,
1,
0.0645,
0.0538,
1,
0.69,
0,
826,
3,
0,
0,
0,
0,
0,
2
],
[
14,
2,
0.0538,
0.0108,
2,
0.12,
... | [
"def insertion_sort(list2):\n for i in range(1, len(list2)):\n j = i\n while j > 0 and list2[j] < list2[j-1]:\n list2[j], list2[j - 1] = list2[j-1], list2[j] #swap\n j -= 1\n return list2",
" for i in range(1, len(list2)):\n j = i\n while j > 0 and list... |
def facorial(n):
if n==1: return n
return n*facorial(n-1)
def multiplicar(a,b):
if b==1:
return a
return a+multiplicar(a,b-1)
def binario(n):
if n != 0:
binario(n/2)
print str(n%2),
def binario_ww(n):
if n<2:
print n%2,
else:
binario_ww(n/2)
print n%2,
def fibo(n):
if n<=2... | [
[
2,
0,
0.0909,
0.0909,
0,
0.66,
0,
833,
0,
1,
1,
0,
0,
0,
1
],
[
4,
1,
0.0909,
0.0303,
1,
0.55,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
[
13,
2,
0.0909,
0.0303,
2,
0.41,
... | [
"def facorial(n):\n if n==1: return n\n return n*facorial(n-1)",
" if n==1: return n",
" if n==1: return n",
" return n*facorial(n-1)",
"def multiplicar(a,b):\n if b==1:\n return a\n return a+multiplicar(a,b-1)",
" if b==1:\n return a",
" return a",
" return a+multiplicar(a,b-1)",
... |
#! /usr/bin/env python
from random import randint
from random import shuffle
import math
#n vertices y m aristas
# u
# b
# k
#defino el nombre de cada archivo
fo = open("instancias.in", "wb")
for q in range(500):
n = randint(5,200)
#calculo la cantidad de aristas del grafo completo
completo = n*(n-1)*0.5
#ar... | [
[
1,
0,
0.05,
0.0167,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.0667,
0.0167,
0,
0.66,
0.1667,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.0833,
0.0167,
0,
0.... | [
"from random import randint",
"from random import shuffle",
"import math",
"fo = open(\"instancias.in\", \"wb\")",
"for q in range(500):\n n = randint(5,200)\n #calculo la cantidad de aristas del grafo completo\n completo = n*(n-1)*0.5\n #aristas\n t = 1000\n m = int(completo)\n #k = randint(1,t)",
... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=15139669
"""
Write a method that takes a camilCase string as a parameter and returns underscore_case as output. Assume that input can be null or ... | [
[
8,
0,
0.1034,
0.0517,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1552,
0.0172,
0,
0.66,
0.125,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1724,
0.0172,
0,
0.66,... | [
"\"\"\"\nWrite a method that takes a camilCase string as a parameter and returns underscore_case as output. Assume that input can be null or empty. If CamilCase parametar starts with a capital letter turn it into lower case without puting underscore before it. How do you test this method?\n\"\"\"",
"import os, re... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14581715
#Google interview question
"""
Given an array of intergers. Write a program to print all the permu... | [
[
1,
0,
0.0244,
0.0244,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.0488,
0.0244,
0,
0.66,
0.1667,
654,
0,
1,
0,
0,
654,
0,
0
],
[
1,
0,
0.0732,
0.0244,
0,
... | [
"import os, re, sys, getopt",
"import time",
"from utils import *",
"def print_permutation_david_helper(prefix, arr, result):\n if not len(arr):\n result.append(\"\".join(prefix))\n return\n else:\n for i in range(0, len(arr)):\n prefix.append(arr[i])\n del arr... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=15029918
#Google interview question
"""
Given two string S1 and S2. S1 contains from A-Z and S2 contains A-Z, * and ?
Where * means any character ... | [
[
1,
0,
0.0133,
0.0133,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.0267,
0.0133,
0,
0.66,
0.1429,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.04,
0.0133,
0,
0.... | [
"import os, re, sys, getopt",
"import logging",
"import locale",
"def is_match_lobatt(s, pattern):\n print(\"s=\" + s + \"\\tpattern=\"+pattern)\n if len(s) == 0:\n if pattern == '*' or pattern == '?': return True\n return False\n if len(pattern) == 0 or pattern == '*': return True\n ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=11532811
"""
Given an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.
"""
from utils import *
@time_profile
def find_max_... | [
[
8,
0,
0.0938,
0.0469,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.125,
0.0156,
0,
0.66,
0.2,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.2969,
0.2656,
0,
0.66,
... | [
"\"\"\"\nGiven an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.\n\"\"\"",
"from utils import *",
"def find_max_diff_david(A):\n if not A: return (0, 0)\n length = len(A)\n pre_sequences = [(A[0], 0)]\n suf_sequences = [(A[-1], length - 1)]\n for i in range(1, length):\n ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=6227714491023360
'''
suppose a string is consists of a, b, and c
Now given a integer N, output the amount of all possible strings of length N th... | [
[
8,
0,
0.1014,
0.0725,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1594,
0.0145,
0,
0.66,
0.1111,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1739,
0.0145,
0,
0.66... | [
"'''\nsuppose a string is consists of a, b, and c \nNow given a integer N, output the amount of all possible strings of length N that don't of have consecutive a,b,c. \ne.g. given N=5, string bacca is invalid since the first 3 letters have consecutive a,b,c. and bbbbb is valid.\n'''",
"import os, re, sys, getopt"... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=15139669
"""
Write a method that takes a camilCase string as a parameter and returns underscore_case as output. Assume that input can be null or ... | [
[
8,
0,
0.1034,
0.0517,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1552,
0.0172,
0,
0.66,
0.125,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1724,
0.0172,
0,
0.66,... | [
"\"\"\"\nWrite a method that takes a camilCase string as a parameter and returns underscore_case as output. Assume that input can be null or empty. If CamilCase parametar starts with a capital letter turn it into lower case without puting underscore before it. How do you test this method?\n\"\"\"",
"import os, re... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14581715
#Google interview question
"""
Given an array of intergers. Write a program to print all the permu... | [
[
1,
0,
0.0244,
0.0244,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.0488,
0.0244,
0,
0.66,
0.1667,
654,
0,
1,
0,
0,
654,
0,
0
],
[
1,
0,
0.0732,
0.0244,
0,
... | [
"import os, re, sys, getopt",
"import time",
"from utils import *",
"def print_permutation_david_helper(prefix, arr, result):\n if not len(arr):\n result.append(\"\".join(prefix))\n return\n else:\n for i in range(0, len(arr)):\n prefix.append(arr[i])\n del arr... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=11532811
"""
Given an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.
"""
from utils import *
@time_profile
def find_max_... | [
[
8,
0,
0.0938,
0.0469,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.125,
0.0156,
0,
0.66,
0.2,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.2969,
0.2656,
0,
0.66,
... | [
"\"\"\"\nGiven an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.\n\"\"\"",
"from utils import *",
"def find_max_diff_david(A):\n if not A: return (0, 0)\n length = len(A)\n pre_sequences = [(A[0], 0)]\n suf_sequences = [(A[-1], length - 1)]\n for i in range(1, length):\n ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=6227714491023360
'''
suppose a string is consists of a, b, and c
Now given a integer N, output the amount of all possible strings of length N th... | [
[
8,
0,
0.1014,
0.0725,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1594,
0.0145,
0,
0.66,
0.1111,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1739,
0.0145,
0,
0.66... | [
"'''\nsuppose a string is consists of a, b, and c \nNow given a integer N, output the amount of all possible strings of length N that don't of have consecutive a,b,c. \ne.g. given N=5, string bacca is invalid since the first 3 letters have consecutive a,b,c. and bbbbb is valid.\n'''",
"import os, re, sys, getopt"... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14991189
#Google interview question
"""
Design an algorithm that, given a list of n elements in an array, finds all the elements that appear more ... | [
[
8,
0,
0.2414,
0.1034,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.3103,
0.0345,
0,
0.66,
0.1667,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.5862,
0.5172,
0,
0.66... | [
"\"\"\"\nDesign an algorithm that, given a list of n elements in an array, finds all the elements that appear more than n/3 times in the list. The algorithm should run in linear time. (n >=0 ) You are expected to use comparisons and achieve linear time. No hashing/excessive space/ and don't use standard linear time... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=5361917182869504
"""
a 32-bit integer could be splited into 32 small integers as:
1. bit 0~4
2. bit 1~5
...
31. bit 30~31 and... | [
[
8,
0,
0.0957,
0.0957,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1489,
0.0106,
0,
0.66,
0.0769,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1596,
0.0106,
0,
0.66... | [
"\"\"\"\na 32-bit integer could be splited into 32 small integers as: \n 1. bit 0~4 \n 2. bit 1~5 \n ... \n 31. bit 30~31 and bit 0~2 \n 32. bit 31 and bit 0~3 \n please find a 32-bit integer that could be splited into exactly 0~31 (the order doesn't matter).",
"import os, re, sys, getopt",
"i... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=14813758
"""
Given 2 arrays A,B, where x(A.length) < y(B.length), we want to
insert (y - x) 0's to A at various places such that A*B is minimum. ... | [
[
8,
0,
0.0872,
0.0698,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1279,
0.0116,
0,
0.66,
0.1429,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1395,
0.0116,
0,
0.66... | [
"\"\"\"\nGiven 2 arrays A,B, where x(A.length) < y(B.length), we want to\ninsert (y - x) 0's to A at various places such that A*B is minimum. For instance, if A = (1, -1) and\nB = (1,2, 3, 4), then inserting two 0's in the middle of A such that A = (1, 0, 0, -1) would minimize\nA*B. I think he was looking for a dyn... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=14736688
"""
The maximum suffix of a string is the lexicographically largest suffix of the string. The maximum
suffix problem is to find the maxi... | [
[
8,
0,
0.0684,
0.0421,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1053,
0.0105,
0,
0.66,
0.1111,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1158,
0.0105,
0,
0.66... | [
"\"\"\"\nThe maximum suffix of a string is the lexicographically largest suffix of the string. The maximum\nsuffix problem is to find the maximum suffix of a given string. Linear time algorithm required.\n\"\"\"",
"import os, re, sys, getopt",
"import logging",
"import locale",
"from utils import *",
"imp... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=15029918
#Google interview question
"""
Given two string S1 and S2. S1 contains from A-Z and S2 contains A-Z, * and ?
Where * means any character ... | [
[
1,
0,
0.0133,
0.0133,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.0267,
0.0133,
0,
0.66,
0.1429,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.04,
0.0133,
0,
0.... | [
"import os, re, sys, getopt",
"import logging",
"import locale",
"def is_match_lobatt(s, pattern):\n print(\"s=\" + s + \"\\tpattern=\"+pattern)\n if len(s) == 0:\n if pattern == '*' or pattern == '?': return True\n return False\n if len(pattern) == 0 or pattern == '*': return True\n ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
import random
import time
def random_arr(length = random.randint(10, 20), min = 0, max = 100):
result ... | [
[
1,
0,
0.1458,
0.0208,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.1667,
0.0208,
0,
0.66,
0.125,
654,
0,
1,
0,
0,
654,
0,
0
],
[
2,
0,
0.2292,
0.0625,
0,
0... | [
"import random",
"import time",
"def random_arr(length = random.randint(10, 20), min = 0, max = 100):\n result = [random.randint(min, max) for i in range(length)]\n return result",
" result = [random.randint(min, max) for i in range(length)]",
" return result",
"def random_str(length = random.... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=5361917182869504
"""
a 32-bit integer could be splited into 32 small integers as:
1. bit 0~4
2. bit 1~5
...
31. bit 30~31 and... | [
[
8,
0,
0.0957,
0.0957,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1489,
0.0106,
0,
0.66,
0.0769,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1596,
0.0106,
0,
0.66... | [
"\"\"\"\na 32-bit integer could be splited into 32 small integers as: \n 1. bit 0~4 \n 2. bit 1~5 \n ... \n 31. bit 30~31 and bit 0~2 \n 32. bit 31 and bit 0~3 \n please find a 32-bit integer that could be splited into exactly 0~31 (the order doesn't matter).",
"import os, re, sys, getopt",
"i... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=14736688
"""
The maximum suffix of a string is the lexicographically largest suffix of the string. The maximum
suffix problem is to find the maxi... | [
[
8,
0,
0.0684,
0.0421,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1053,
0.0105,
0,
0.66,
0.1111,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1158,
0.0105,
0,
0.66... | [
"\"\"\"\nThe maximum suffix of a string is the lexicographically largest suffix of the string. The maximum\nsuffix problem is to find the maximum suffix of a given string. Linear time algorithm required.\n\"\"\"",
"import os, re, sys, getopt",
"import logging",
"import locale",
"from utils import *",
"imp... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
# http://www.careercup.com/question?id=14813758
"""
Given 2 arrays A,B, where x(A.length) < y(B.length), we want to
insert (y - x) 0's to A at various places such that A*B is minimum. ... | [
[
8,
0,
0.0872,
0.0698,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1279,
0.0116,
0,
0.66,
0.1429,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1395,
0.0116,
0,
0.66... | [
"\"\"\"\nGiven 2 arrays A,B, where x(A.length) < y(B.length), we want to\ninsert (y - x) 0's to A at various places such that A*B is minimum. For instance, if A = (1, -1) and\nB = (1,2, 3, 4), then inserting two 0's in the middle of A such that A = (1, 0, 0, -1) would minimize\nA*B. I think he was looking for a dyn... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14991189
#Google interview question
"""
Design an algorithm that, given a list of n elements in an array, finds all the elements that appear more ... | [
[
8,
0,
0.2414,
0.1034,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.3103,
0.0345,
0,
0.66,
0.1667,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.5862,
0.5172,
0,
0.66... | [
"\"\"\"\nDesign an algorithm that, given a list of n elements in an array, finds all the elements that appear more than n/3 times in the list. The algorithm should run in linear time. (n >=0 ) You are expected to use comparisons and achieve linear time. No hashing/excessive space/ and don't use standard linear time... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=9820788
#Facebook interview question
"""
there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..
It looks something like ... | [
[
8,
0,
0.2326,
0.2093,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.3488,
0.0233,
0,
0.66,
0.3333,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.6047,
0.4419,
0,
0.66... | [
"\"\"\"\nthere is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..\nIt looks something like this \n1\n2 3\n4 5 6\nevery cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only fro... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=9332640
#Facebook interview question
"""
Really like the linear solution of this problem. You have an array of 0s and 1s and you want to output al... | [
[
8,
0,
0.3,
0.2857,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4571,
0.0286,
0,
0.66,
0.3333,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.6571,
0.3714,
0,
0.66,
... | [
"\"\"\"\nReally like the linear solution of this problem. You have an array of 0s and 1s and you want to output all the intervals (i, j) where the number of 0s and numbers of 1s are equal.\n\nExample\n\npos = 0 1 2 3 4 5 6 7 8\n0 1 0 0 1 1 1 1 0",
"from collections import defaultdict",
"def get_equal_intervals(... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
"""
http://www.careercup.com/question?id=14967793
You are given an input form such as the following
(1, (2, 3), (4, (5, 6), 7))
Each element is either a number or a list (whose element... | [
[
8,
0,
0.2833,
0.3333,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4667,
0.0333,
0,
0.66,
0.2,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.5,
0.0333,
0,
0.66,
... | [
"\"\"\"\nhttp://www.careercup.com/question?id=14967793\nYou are given an input form such as the following\n(1, (2, 3), (4, (5, 6), 7))\nEach element is either a number or a list (whose elements may also be numbers or other lists).\nOutput the numbers as they appear, stripped down into a single list.\nE.G. (1, 2, 3,... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=12945663
#Facebook interview question
"""
Write a function f(n) which computes the number of scoring sequences that add up to score n.
"""
def ca... | [
[
8,
0,
0.35,
0.15,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.675,
0.4,
0,
0.66,
0.3333,
85,
0,
3,
1,
0,
0,
0,
3
],
[
14,
1,
0.55,
0.05,
1,
0.3,
0,
51... | [
"\"\"\"\nWrite a function f(n) which computes the number of scoring sequences that add up to score n.\n\"\"\"",
"def calculate(num, scores, start_index):\n result = 0\n score = scores[start_index]\n if start_index == len(scores) - 1:\n return num % score == 0\n for i in range(0, num / score + 1... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14633700
#Facebook interview question
"""
Determine winner of 2/9 number game
Two players play the following game: they pick a random number N (l... | [
[
8,
0,
0.3393,
0.2857,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.6607,
0.2857,
0,
0.66,
0.25,
214,
0,
2,
1,
0,
0,
0,
2
],
[
4,
1,
0.5714,
0.0357,
1,
0.59,
... | [
"\"\"\"\nDetermine winner of 2/9 number game\n\nTwo players play the following game: they pick a random number N (less than 2 billion) then, \nstarting from 1, take turns multiplying the number from the previous turn with either 2 or 9 (their choice). \nWhoever reaches N first wins. \nThe candidate should write a f... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
import random
def find_point_intersect_most(arr):
points = [(interval[0], 0) for interval in arr] + [(... | [
[
1,
0,
0.2069,
0.0345,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
2,
0,
0.4828,
0.3793,
0,
0.66,
0.5,
462,
0,
1,
1,
0,
0,
0,
1
],
[
14,
1,
0.3448,
0.0345,
1,
0.5,... | [
"import random",
"def find_point_intersect_most(arr):\n points = [(interval[0], 0) for interval in arr] + [(interval[1], 1) for interval in arr]\n points.sort(key = lambda x: x[0])\n max_occu, occu, position = 0, 0, -1\n for point in points:\n if point[1]: occu -= 1\n else: occu += 1\n ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14681714
#Facebook interview question
"""
Given a set {1,2,3,4,5...n} of n elements, write code that outputs all subsets of length k. For example,... | [
[
8,
0,
0.2414,
0.1034,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.3966,
0.1379,
0,
0.66,
0.3333,
105,
0,
2,
0,
0,
0,
0,
2
],
[
14,
1,
0.3793,
0.0345,
1,
0.55,... | [
"\"\"\"\nGiven a set {1,2,3,4,5...n} of n elements, write code that outputs all subsets of length k. For example, if n = 4 and k = 2, the output would be {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}\n\"\"\"",
"def preint_subsets(n, k):\n arr = [i for i in range(1, n + 1)]\n existing = []\n print_sets(a... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=9332640
#Facebook interview question
"""
Really like the linear solution of this problem. You have an array of 0s and 1s and you want to output al... | [
[
8,
0,
0.3,
0.2857,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4571,
0.0286,
0,
0.66,
0.3333,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.6571,
0.3714,
0,
0.66,
... | [
"\"\"\"\nReally like the linear solution of this problem. You have an array of 0s and 1s and you want to output all the intervals (i, j) where the number of 0s and numbers of 1s are equal.\n\nExample\n\npos = 0 1 2 3 4 5 6 7 8\n0 1 0 0 1 1 1 1 0",
"from collections import defaultdict",
"def get_equal_intervals(... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
from utils import *
def find_non_adjacent_sub_sequence(arr):
if not arr: return (0, )
if len(arr) ... | [
[
1,
0,
0.1489,
0.0213,
0,
0.66,
0,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.4362,
0.5106,
0,
0.66,
0.3333,
326,
0,
1,
1,
0,
0,
0,
12
],
[
4,
1,
0.2128,
0.0213,
1,
0... | [
"from utils import *",
"def find_non_adjacent_sub_sequence(arr):\n if not arr: return (0, )\n if len(arr) == 1: return (1, arr[0])\n last_index, max_sum, max_sum_sequence = [], 0, []\n max_sum_index = -1\n\n for i in range(0, len(arr)):\n if i <= 1:",
" if not arr: return (0, )",
" ... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=12945663
#Facebook interview question
"""
Write a function f(n) which computes the number of scoring sequences that add up to score n.
"""
def ca... | [
[
8,
0,
0.35,
0.15,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.675,
0.4,
0,
0.66,
0.3333,
85,
0,
3,
1,
0,
0,
0,
3
],
[
14,
1,
0.55,
0.05,
1,
0.21,
0,
5... | [
"\"\"\"\nWrite a function f(n) which computes the number of scoring sequences that add up to score n.\n\"\"\"",
"def calculate(num, scores, start_index):\n result = 0\n score = scores[start_index]\n if start_index == len(scores) - 1:\n return num % score == 0\n for i in range(0, num / score + 1... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
import random
import time
def random_arr(length = random.randint(10, 20), min = 0, max = 100):
result ... | [
[
1,
0,
0.1458,
0.0208,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.1667,
0.0208,
0,
0.66,
0.125,
654,
0,
1,
0,
0,
654,
0,
0
],
[
2,
0,
0.2292,
0.0625,
0,
0... | [
"import random",
"import time",
"def random_arr(length = random.randint(10, 20), min = 0, max = 100):\n result = [random.randint(min, max) for i in range(length)]\n return result",
" result = [random.randint(min, max) for i in range(length)]",
" return result",
"def random_str(length = random.... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14633700
#Facebook interview question
"""
Determine winner of 2/9 number game
Two players play the following game: they pick a random number N (l... | [
[
8,
0,
0.3393,
0.2857,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.6607,
0.2857,
0,
0.66,
0.25,
214,
0,
2,
1,
0,
0,
0,
2
],
[
4,
1,
0.5714,
0.0357,
1,
0.64,
... | [
"\"\"\"\nDetermine winner of 2/9 number game\n\nTwo players play the following game: they pick a random number N (less than 2 billion) then, \nstarting from 1, take turns multiplying the number from the previous turn with either 2 or 9 (their choice). \nWhoever reaches N first wins. \nThe candidate should write a f... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14945498
#Google interview question
import os, re, sys, getopt
import logging
import locale
if __name__ == '__main__':
output = []
buf = ... | [
[
1,
0,
0.1429,
0.0238,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1667,
0.0238,
0,
0.66,
0.3333,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.1905,
0.0238,
0,
... | [
"import os, re, sys, getopt",
"import logging",
"import locale",
"if __name__ == '__main__':\n output = []\n buf = []\n while True:\n cur = sys.stdin.readline().rstrip('\\n')\n #end exit\n if cur == '$$':\n sys.exit(0)",
" output = []",
" buf = []",
" wh... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=9820788
#Facebook interview question
"""
there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..
It looks something like ... | [
[
8,
0,
0.2326,
0.2093,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.3488,
0.0233,
0,
0.66,
0.3333,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.6047,
0.4419,
0,
0.66... | [
"\"\"\"\nthere is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..\nIt looks something like this \n1\n2 3\n4 5 6\nevery cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only fro... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
"""
http://www.careercup.com/question?id=14967793
You are given an input form such as the following
(1, (2, 3), (4, (5, 6), 7))
Each element is either a number or a list (whose element... | [
[
8,
0,
0.2833,
0.3333,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4667,
0.0333,
0,
0.66,
0.2,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.5,
0.0333,
0,
0.66,
... | [
"\"\"\"\nhttp://www.careercup.com/question?id=14967793\nYou are given an input form such as the following\n(1, (2, 3), (4, (5, 6), 7))\nEach element is either a number or a list (whose elements may also be numbers or other lists).\nOutput the numbers as they appear, stripped down into a single list.\nE.G. (1, 2, 3,... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=13216725
#Facebook interview question
"""
An expression consisting of operands and binary operators can be written in Reverse Polish Notation (RPN... | [
[
8,
0,
0.277,
0.4054,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4865,
0.0135,
0,
0.66,
0.1667,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.6149,
0.2432,
0,
0.66,... | [
"\"\"\"\nAn expression consisting of operands and binary operators can be written in Reverse Polish Notation (RPN) by writing both the operands followed by the operator. For example, 3 + (4 * 5) can be written as \"3 4 5 * +\".\n\nYou are given a string consisting of x's and *'s. x represents an operand and * repre... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14945498
#Google interview question
import os, re, sys, getopt
import logging
import locale
if __name__ == '__main__':
output = []
buf = ... | [
[
1,
0,
0.1429,
0.0238,
0,
0.66,
0,
688,
0,
4,
0,
0,
688,
0,
0
],
[
1,
0,
0.1667,
0.0238,
0,
0.66,
0.3333,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.1905,
0.0238,
0,
... | [
"import os, re, sys, getopt",
"import logging",
"import locale",
"if __name__ == '__main__':\n output = []\n buf = []\n while True:\n cur = sys.stdin.readline().rstrip('\\n')\n #end exit\n if cur == '$$':\n sys.exit(0)",
" output = []",
" buf = []",
" wh... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
import random
import time
def random_arr(length = random.randint(10, 20), min = 0, max = 100):
result ... | [
[
1,
0,
0.1458,
0.0208,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
1,
0,
0.1667,
0.0208,
0,
0.66,
0.125,
654,
0,
1,
0,
0,
654,
0,
0
],
[
2,
0,
0.2292,
0.0625,
0,
0... | [
"import random",
"import time",
"def random_arr(length = random.randint(10, 20), min = 0, max = 100):\n result = [random.randint(min, max) for i in range(length)]\n return result",
" result = [random.randint(min, max) for i in range(length)]",
" return result",
"def random_str(length = random.... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14681714
#Facebook interview question
"""
Given a set {1,2,3,4,5...n} of n elements, write code that outputs all subsets of length k. For example,... | [
[
8,
0,
0.2414,
0.1034,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.3966,
0.1379,
0,
0.66,
0.3333,
105,
0,
2,
0,
0,
0,
0,
2
],
[
14,
1,
0.3793,
0.0345,
1,
0.15,... | [
"\"\"\"\nGiven a set {1,2,3,4,5...n} of n elements, write code that outputs all subsets of length k. For example, if n = 4 and k = 2, the output would be {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}\n\"\"\"",
"def preint_subsets(n, k):\n arr = [i for i in range(1, n + 1)]\n existing = []\n print_sets(a... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
import random
def find_point_intersect_most(arr):
points = [(interval[0], 0) for interval in arr] + [(... | [
[
1,
0,
0.2069,
0.0345,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
2,
0,
0.4828,
0.3793,
0,
0.66,
0.5,
462,
0,
1,
1,
0,
0,
0,
1
],
[
14,
1,
0.3448,
0.0345,
1,
0.82... | [
"import random",
"def find_point_intersect_most(arr):\n points = [(interval[0], 0) for interval in arr] + [(interval[1], 1) for interval in arr]\n points.sort(key = lambda x: x[0])\n max_occu, occu, position = 0, 0, -1\n for point in points:\n if point[1]: occu -= 1\n else: occu += 1\n ... |
import random
"""
http://www.careercup.com/question?id=14859694
Given an array and a key, sum min subarray whose sum is no less than key. O(n) Time needed
Assumption: all positive intergers in the array
"""
def minLength(arr, k):
min_length, sum, start = len(arr) + 1, 0, 0
s, e = -1, -1
for i in rang... | [
[
1,
0,
0.0133,
0.0133,
0,
0.66,
0,
715,
0,
1,
0,
0,
715,
0,
0
],
[
8,
0,
0.0733,
0.08,
0,
0.66,
0.2,
0,
1,
0,
0,
0,
0,
0,
0
],
[
2,
0,
0.2,
0.1467,
0,
0.66,
0.... | [
"import random",
"\"\"\"\nhttp://www.careercup.com/question?id=14859694\nGiven an array and a key, sum min subarray whose sum is no less than key. O(n) Time needed\n\nAssumption: all positive intergers in the array\n\"\"\"",
"def minLength(arr, k):\n min_length, sum, start = len(arr) + 1, 0, 0\n s, e = -1... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=13216725
#Facebook interview question
"""
An expression consisting of operands and binary operators can be written in Reverse Polish Notation (RPN... | [
[
8,
0,
0.277,
0.4054,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.4865,
0.0135,
0,
0.66,
0.1667,
193,
0,
1,
0,
0,
193,
0,
0
],
[
2,
0,
0.6149,
0.2432,
0,
0.66,... | [
"\"\"\"\nAn expression consisting of operands and binary operators can be written in Reverse Polish Notation (RPN) by writing both the operands followed by the operator. For example, 3 + (4 * 5) can be written as \"3 4 5 * +\".\n\nYou are given a string consisting of x's and *'s. x represents an operand and * repre... |
#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question
from utils import *
def find_non_adjacent_sub_sequence(arr):
if not arr: return (0, )
if len(arr) ... | [
[
1,
0,
0.1489,
0.0213,
0,
0.66,
0,
970,
0,
1,
0,
0,
970,
0,
0
],
[
2,
0,
0.4362,
0.5106,
0,
0.66,
0.3333,
326,
0,
1,
1,
0,
0,
0,
12
],
[
4,
1,
0.2128,
0.0213,
1,
0... | [
"from utils import *",
"def find_non_adjacent_sub_sequence(arr):\n if not arr: return (0, )\n if len(arr) == 1: return (1, arr[0])\n last_index, max_sum, max_sum_sequence = [], 0, []\n max_sum_index = -1\n\n for i in range(0, len(arr)):\n if i <= 1:",
" if not arr: return (0, )",
" ... |
'''
Created on Apr 16, 2012
@author: Gangli
'''
import argparse;
import re;
import sys;
logcodes = [];
def addlogcode(logcode):
global logcodes;
if logcode not in logcodes:
logcodes.append(logcode);
def inlogcodelist(logcode):
global logcodes;
return (logcode in logcodes... | [
[
8,
0,
0.0833,
0.1389,
0,
0.66,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0.1944,
0.0278,
0,
0.66,
0.1111,
325,
0,
1,
0,
0,
325,
0,
0
],
[
1,
0,
0.2222,
0.0278,
0,
0.66... | [
"'''\nCreated on Apr 16, 2012\n\n@author: Gangli\n'''",
"import argparse;",
"import re;",
"import sys;",
"logcodes = [];",
"def addlogcode(logcode):\n global logcodes;\n if logcode not in logcodes:\n logcodes.append(logcode);",
" if logcode not in logcodes:\n logcodes.append(logco... |
import sys;
import re;
from fnmatch import fnmatch;
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: extractcods.py <javaloader-dir-file>";
sys.exit(1);
nCount = 0;
with open(sys.argv[1], "rt") as fin:
for line in fin:
mo = re.search("^(\... | [
[
1,
0,
0.2,
0.2,
0,
0.66,
0,
509,
0,
1,
0,
0,
509,
0,
0
],
[
1,
0,
0.4,
0.2,
0,
0.66,
0.5,
540,
0,
1,
0,
0,
540,
0,
0
],
[
1,
0,
0.8,
0.2,
0,
0.66,
1,
626,... | [
"import sys;",
"import re;",
"from fnmatch import fnmatch;"
] |
import sys;
import os;
import os.path;
from fnmatch import fnmatch;
WHITELIST = ["build.xml" \
, "build-barebone.xml" \
, "build-component.xml" \
, "build-evacuated-component-macros.xml" \
, "build-core.xml" \
, "build-device.xml" \
];
if __name__ == '__main__':
if len(sys.argv) < 2:
prin... | [
[
1,
0,
0.1667,
0.1667,
0,
0.66,
0,
509,
0,
1,
0,
0,
509,
0,
0
],
[
1,
0,
0.3333,
0.1667,
0,
0.66,
0.3333,
688,
0,
1,
0,
0,
688,
0,
0
],
[
1,
0,
0.5,
0.1667,
0,
0.6... | [
"import sys;",
"import os;",
"import os.path;",
"from fnmatch import fnmatch;"
] |
import sys;
import os;
import os.path;
from fnmatch import fnmatch;
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: listpng.py <directory>";
sys.exit(1);
sDirectory = os.path.dirname(sys.argv[1]);
for (curdir, dirs, files) in os.walk(sDirectory):
... | [
[
1,
0,
0.1667,
0.1667,
0,
0.66,
0,
509,
0,
1,
0,
0,
509,
0,
0
],
[
1,
0,
0.3333,
0.1667,
0,
0.66,
0.3333,
688,
0,
1,
0,
0,
688,
0,
0
],
[
1,
0,
0.5,
0.1667,
0,
0.6... | [
"import sys;",
"import os;",
"import os.path;",
"from fnmatch import fnmatch;"
] |
import numpy as np
import numpy.linalg as nl
def stripe_length(A):
sup = -1
inf = -1
n = A.shape[0]
#calcul de la largeur de la bande sup: ballayage des lignes
#paralleles a la diagonale en commencant par la plus eloignee
#de la diagonale (i.e l'element A(1,n))
for i in np.arange(n):
... | [
[
1,
0,
0.004,
0.004,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0079,
0.004,
0,
0.66,
0.0089,
796,
0,
1,
0,
0,
796,
0,
0
],
[
2,
0,
0.0672,
0.1067,
0,
0.6... | [
"import numpy as np",
"import numpy.linalg as nl",
"def stripe_length(A):\n sup = -1\n inf = -1\n n = A.shape[0]\n\n #calcul de la largeur de la bande sup: ballayage des lignes\n #paralleles a la diagonale en commencant par la plus eloignee\n #de la diagonale (i.e l'element A(1,n))",
" su... |
import numpy as np
import matplotlib.pyplot as plt
import methodeIterative as mi
import methodeDirecte as md
#****************** Generations ************************************0
def generateMatrixHeat(n):
A = np.zeros([n*n,n*n])
A += np.diag(-4*np.ones(n*n, dtype=np.int),0)
A += np.diag(np.ones(n*n-1, dty... | [
[
1,
0,
0.0083,
0.0083,
0,
0.66,
0,
954,
0,
1,
0,
0,
954,
0,
0
],
[
1,
0,
0.0167,
0.0083,
0,
0.66,
0.0769,
596,
0,
1,
0,
0,
596,
0,
0
],
[
1,
0,
0.025,
0.0083,
0,
0... | [
"import numpy as np",
"import matplotlib.pyplot as plt",
"import methodeIterative as mi",
"import methodeDirecte as md",
"def generateMatrixHeat(n):\n A = np.zeros([n*n,n*n])\n A += np.diag(-4*np.ones(n*n, dtype=np.int),0)\n A += np.diag(np.ones(n*n-1, dtype=np.int),1)\n A += np.diag(np.ones(n*n... |
def spacify(input, dict):
"""Given a string and a dictionary, if it is possible to seperate the string
into a set of words that are in the dictionary, returns a string equivilant to
the input string but with spaces between the valid dictionary words. If there
is no way to break up the input string into... | [
[
2,
0,
0.4643,
0.8214,
0,
0.66,
0,
404,
0,
2,
1,
0,
0,
0,
7
],
[
8,
1,
0.1786,
0.1786,
1,
0.18,
0,
0,
1,
0,
0,
0,
0,
0,
0
],
[
4,
1,
0.3393,
0.0714,
1,
0.18,
0... | [
"def spacify(input, dict):\n \"\"\"Given a string and a dictionary, if it is possible to seperate the string\n into a set of words that are in the dictionary, returns a string equivilant to\n the input string but with spaces between the valid dictionary words. If there\n is no way to break up the input ... |
import codeJamUtils
def _build_board(case):
numRows, numCols, numMines = case
freeSpaces = numCols * numRows - numMines
board = []
doTransposeResult = False
# for convenience make sure the board is either square or wider than it is tall
if numRows > numCols:
numCols, numRows = numRows,... | [
[
1,
0,
0.0079,
0.0079,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
2,
0,
0.373,
0.7063,
0,
0.66,
0.25,
118,
0,
1,
1,
0,
0,
0,
13
],
[
14,
1,
0.0317,
0.0079,
1,
0.3... | [
"import codeJamUtils",
"def _build_board(case):\n numRows, numCols, numMines = case\n freeSpaces = numCols * numRows - numMines\n board = []\n doTransposeResult = False\n\n # for convenience make sure the board is either square or wider than it is tall\n if numRows > numCols:",
" numRows, n... |
import codeJamUtils
import operator
def _calculate_optimal_deletions(case):
numVerticies, adjacencyList = case
# The key insight here is that only a single node in any full binary tree may serve as the
# root (the only node with degree 2, as inner nodes have degree 3 and leaves degree 1).
# It is rela... | [
[
1,
0,
0.0092,
0.0092,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
1,
0,
0.0183,
0.0092,
0,
0.66,
0.2,
616,
0,
1,
0,
0,
616,
0,
0
],
[
2,
0,
0.0688,
0.055,
0,
0.66... | [
"import codeJamUtils",
"import operator",
"def _calculate_optimal_deletions(case):\n numVerticies, adjacencyList = case\n # The key insight here is that only a single node in any full binary tree may serve as the\n # root (the only node with degree 2, as inner nodes have degree 3 and leaves degree 1).\... |
import codeJamUtils
import sys
def _find_best_flip_num(case):
outletFlowStrs, deviceFlowStrs = case
if (len(outletFlowStrs) == 0 or len(outletFlowStrs) != len(deviceFlowStrs)):
return -1
L = len(outletFlowStrs[0])
# for each possible flip string, apply it to out outlet flows, and check that
... | [
[
1,
0,
0.012,
0.012,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
1,
0,
0.0241,
0.012,
0,
0.66,
0.25,
509,
0,
1,
0,
0,
509,
0,
0
],
[
2,
0,
0.2771,
0.4699,
0,
0.66,... | [
"import codeJamUtils",
"import sys",
"def _find_best_flip_num(case):\n outletFlowStrs, deviceFlowStrs = case\n if (len(outletFlowStrs) == 0 or len(outletFlowStrs) != len(deviceFlowStrs)):\n return -1\n\n L = len(outletFlowStrs[0])\n\n # for each possible flip string, apply it to out outlet fl... |
import codeJamUtils
def compute_badrand_probability_matrix(N):
M_nextiter = [[0.0 for _ in range(N)] for _ in range(N)]
M_previter = [[0.0 for _ in range(N)] for _ in range(N)]
i = N
swapProb = 1/N
noSwapProb = 1 - swapProb
# working backwards from the last iteration of badrand, we can compu... | [
[
1,
0,
0.012,
0.012,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
2,
0,
0.2831,
0.506,
0,
0.66,
0.25,
595,
0,
1,
1,
0,
0,
0,
11
],
[
14,
1,
0.0602,
0.012,
1,
0.53,
... | [
"import codeJamUtils",
"def compute_badrand_probability_matrix(N):\n\n M_nextiter = [[0.0 for _ in range(N)] for _ in range(N)]\n M_previter = [[0.0 for _ in range(N)] for _ in range(N)]\n i = N\n\n swapProb = 1/N\n noSwapProb = 1 - swapProb",
" M_nextiter = [[0.0 for _ in range(N)] for _ in r... |
import codeJamUtils
import sys
def _compute_time(case):
farmCost, farmRate, goal = case
maxRate = 2
prevTime = sys.maxsize
curTime = goal / 2
while curTime <= prevTime:
prevTime = curTime
# go back to before we went for goal
curTime -= goal/maxRate
# and this time... | [
[
1,
0,
0.0222,
0.0222,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
1,
0,
0.0444,
0.0222,
0,
0.66,
0.25,
509,
0,
1,
0,
0,
509,
0,
0
],
[
2,
0,
0.2778,
0.4,
0,
0.66,... | [
"import codeJamUtils",
"import sys",
"def _compute_time(case):\n farmCost, farmRate, goal = case\n\n maxRate = 2\n prevTime = sys.maxsize\n curTime = goal / 2\n\n while curTime <= prevTime:",
" farmCost, farmRate, goal = case",
" maxRate = 2",
" prevTime = sys.maxsize",
" curT... |
import codeJamUtils
def _compute_scores(case):
return (_compute_optimal_deceitful_war_score(case), _compute_optimal_war_score(case))
def _compute_optimal_war_score(case):
# in war, p1 has no information about the weights of p2's blocks. p1 can assume
# that p2 will use a greedy algorithm; for each block B... | [
[
1,
0,
0.0172,
0.0172,
0,
0.66,
0,
573,
0,
1,
0,
0,
573,
0,
0
],
[
2,
0,
0.0603,
0.0345,
0,
0.66,
0.2,
609,
0,
1,
1,
0,
0,
0,
2
],
[
13,
1,
0.069,
0.0172,
1,
0.78,... | [
"import codeJamUtils",
"def _compute_scores(case):\n return (_compute_optimal_deceitful_war_score(case), _compute_optimal_war_score(case))",
" return (_compute_optimal_deceitful_war_score(case), _compute_optimal_war_score(case))",
"def _compute_optimal_war_score(case):\n # in war, p1 has no informati... |
if __name__ == "__main__":
pass | [
[
4,
0,
0.9286,
0.2857,
0,
0.66,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
] | [
"if __name__ == \"__main__\":\n pass"
] |
def get_input_lines(filename):
with open("CodeJamSolutions\\Input\\" + filename) as inputFile:
return inputFile.readlines()
def write_output(filename, caseNum, result):
mode = "a"
if caseNum == 1:
mode = "w"
with open("CodeJamSolutions\\Output\\" + filename, mode) as outputFile:
... | [
[
2,
0,
0.2308,
0.2308,
0,
0.66,
0,
34,
0,
1,
1,
0,
0,
0,
2
],
[
13,
1,
0.3077,
0.0769,
1,
0.98,
0,
0,
3,
0,
0,
0,
0,
10,
1
],
[
2,
0,
0.7692,
0.5385,
0,
0.66,
... | [
"def get_input_lines(filename):\n with open(\"CodeJamSolutions\\\\Input\\\\\" + filename) as inputFile:\n return inputFile.readlines()",
" return inputFile.readlines()",
"def write_output(filename, caseNum, result):\n mode = \"a\"\n if caseNum == 1:\n mode = \"w\"\n\n with open(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.