code
stringlengths
1
1.72M
language
stringclasses
1 value
s = i = 0 while True: term = 1.0 / (i*2+1) s += term * ((-1)**i) if term < 1e-6: break i += 1 print "%.6lf" % s
Python
from sys import stdin from decimal import * a, b, c = map(int, stdin.readline().strip().split()) getcontext().prec = c print Decimal(a) / Decimal(b)
Python
from sys import stdin n = int(stdin.readline().strip()) print "%.3lf" % sum([1.0/x for x in range(1,n+1)])
Python
from sys import stdin print len(stdin.readline().strip())
Python
from itertools import product from math import * def issqrt(n): s = int(floor(sqrt(n))) return s*s == n aabb = [a*1100+b*11 for a,b in product(range(1,10),range(10))] print ' '.join(map(str, filter(issqrt, aabb)))
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) print "%d %d %.3lf" % (min(a), max(a), float(sum(a)) / len(a))
Python
from sys import stdin def cycle(n): if n == 1: return 0 elif n % 2 == 1: return cycle(n*3+1) + 1 else: return cycle(n/2) + 1 n = int(stdin.readline().strip()) print cycle(n)
Python
from sys import stdin n = int(stdin.readline().strip()) count = n*2-1 for i in range(n): print ' '*i + '#'*count count -= 2
Python
for abc in range(123, 329): big = str(abc) + str(abc*2) + str(abc*3) if(''.join(sorted(big)) == '123456789'): print abc, abc*2, abc*3
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) print "%.5lf" % sum([1.0/i/i for i in range(n,m+1)])
Python
from sys import stdin data = map(int, stdin.readline().strip().split()) n, m = data[0], data[-1] data = data[1:-1] print len(filter(lambda x: x < m, data))
Python
from sys import stdin def solve(a, b, c): for i in range(10, 101): if i % 3 == a and i % 5 == b and i % 7 == c: print i return print 'No answer' a, b, c = map(int, stdin.readline().strip().split()) solve(a, b, c)
Python
from itertools import product sol = [a*100+b*10+c for a,b,c in product(range(1,10), range(10), range(10)) if a**3+b**3+c**3 == a*100+b*10+c] print '\n'.join(map(str, sol))
Python
from sys import stdin from math import * n = int(stdin.readline().strip()) print sum(map(factorial, range(1,n+1))) % (10**6)
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) print "%.3lf" % ((a+b+c)/3.0)
Python
from sys import stdin from math import * r, h = map(float, stdin.readline().strip().split()) print "Area = %.3lf" % (pi*r*r*2 + 2*pi*r*h)
Python
from sys import stdin from math import * n, = map(int, stdin.readline().strip().split()) rad = radians(n) print "%.3lf %.3lf" % (sin(rad), cos(rad))
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print n*(n+1)/2
Python
from sys import stdin a, b = map(int, stdin.readline().strip().split()) print b, a
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) a = (4*n-m)/2 b = n-a if m % 2 == 1 or a < 0 or b < 0: print "No answer" else: print a, b
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) money = n * 95 if money >= 300: money *= 0.85 print "%.2lf" % money
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print ["yes", "no"][n % 2]
Python
from sys import stdin from math import * x1, y1, x2, y2 = map(float, stdin.readline().strip().split()) print "%.3lf" % hypot((x1-x2), (y1-y2))
Python
from sys import stdin n = stdin.readline().strip().split()[0] print '%c%c%c' % (n[2], n[1], n[0])
Python
from sys import stdin x, = map(float, stdin.readline().strip().split()) print abs(x)
Python
from sys import stdin from calendar import isleap year, = map(int, stdin.readline().strip().split()) if isleap(year): print "yes" else: print "no"
Python
from sys import stdin f, = map(float, stdin.readline().strip().split()) print "%.3lf" % (5*(f-32)/9)
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a: print "yes" elif a + b <= c or a + c <= b or b + c <= a: print "not a triangle" else: print "no"
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) a.sort() print a[0], a[1], a[2]
Python
s = i = 0 while True: term = 1.0 / (i*2+1) s += term * ((-1)**i) if term < 1e-6: break i += 1 print "%.6lf" % s
Python
from sys import stdin from decimal import * a, b, c = map(int, stdin.readline().strip().split()) getcontext().prec = c print Decimal(a) / Decimal(b)
Python
from sys import stdin n = int(stdin.readline().strip()) print "%.3lf" % sum([1.0/x for x in range(1,n+1)])
Python
from sys import stdin print len(stdin.readline().strip())
Python
from itertools import product from math import * def issqrt(n): s = int(floor(sqrt(n))) return s*s == n aabb = [a*1100+b*11 for a,b in product(range(1,10),range(10))] print ' '.join(map(str, filter(issqrt, aabb)))
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) print "%d %d %.3lf" % (min(a), max(a), float(sum(a)) / len(a))
Python
from sys import stdin def cycle(n): if n == 1: return 0 elif n % 2 == 1: return cycle(n*3+1) + 1 else: return cycle(n/2) + 1 n = int(stdin.readline().strip()) print cycle(n)
Python
from sys import stdin n = int(stdin.readline().strip()) count = n*2-1 for i in range(n): print ' '*i + '#'*count count -= 2
Python
for abc in range(123, 329): big = str(abc) + str(abc*2) + str(abc*3) if(''.join(sorted(big)) == '123456789'): print abc, abc*2, abc*3
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) print "%.5lf" % sum([1.0/i/i for i in range(n,m+1)])
Python
from sys import stdin data = map(int, stdin.readline().strip().split()) n, m = data[0], data[-1] data = data[1:-1] print len(filter(lambda x: x < m, data))
Python
from sys import stdin def solve(a, b, c): for i in range(10, 101): if i % 3 == a and i % 5 == b and i % 7 == c: print i return print 'No answer' a, b, c = map(int, stdin.readline().strip().split()) solve(a, b, c)
Python
from itertools import product sol = [a*100+b*10+c for a,b,c in product(range(1,10), range(10), range(10)) if a**3+b**3+c**3 == a*100+b*10+c] print '\n'.join(map(str, sol))
Python
from sys import stdin from math import * n = int(stdin.readline().strip()) print sum(map(factorial, range(1,n+1))) % (10**6)
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) # @author Sam Pullara, samp@yahoo-inc.com import logging import wsgiref.handlers import os from google.appengine.ext.webapp import templat...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ A simple text library for normalizing, cleaning, and overlapping strings """ __author__ = "Vik Singh (viksi@yahoo-inc.com)" STOPWORD...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __all__ = ["console", "text", "typechecks"]
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __author__ = "Vik Singh (viksi@yahoo-inc.com)" from yos.crawl import object_dict from types import DictType, ListType, TupleType OBJ_DIC...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __author__ = "Vik Singh (viksi@yahoo-inc.com)" def strfix(msg): """ Copies this recipe: http://aspn.activestate.com/ASPN/Cookbook/Pyt...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ This is the Boss search API search is the main function Examples: web_results = search("britney spears") news_20_results = search...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __all__ = ["ysearch"]
Python
#! /usr/bin/env python # -*- coding: iso-8859-15 -*- """ Dictionary to XML - Library to convert a python dictionary to XML output Copyleft (C) 2007 Pianfetti Maurizio <boymix81@gmail.com> Package site : http://boymix81.altervista.org/files/dict2xml.tar.gz Revision 1.0 2007/12/15 11:57:20 Maurizio - ...
Python
#!/usr/local/bin/python25 # Thunder Chen<nkchenz@gmail.com> 2007.9.1 # # import xml.etree.ElementTree as ET from object_dict import object_dict def __parse_node(node): tmp = object_dict() # save attrs and text, hope there will not be a child with same name if node.text: tmp['value'] = node.text ...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ Functions for downloading REST API's and converting their responses into dictionaries """ __author__ = "Vik Singh (viksi@yahoo-inc.co...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __all__ = ["dict2xml", "object_dict", "rest", "xml2dict"]
Python
# object_dict # Thunder Chen<nkchenz@gmail.com> 2007 # Provided as-is; use at your own risk; no warranty; no promises; enjoy! class object_dict(dict): """object view of dict, you can >>> a = object_dict() >>> a.fish = 'fish' >>> a['fish'] 'fish' >>> a['water'] = 'water' >>> a.water 'wa...
Python
#! /usr/bin/env python # -*- coding: iso-8859-15 -*- """ Dictionary to XML - Library to convert a python dictionary to XML output Copyleft (C) 2007 Pianfetti Maurizio <boymix81@gmail.com> Package site : http://boymix81.altervista.org/files/dict2xml.tar.gz Revision 1.0 2007/12/15 11:57:20 Maurizio - ...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __all__ = ["boss", "crawl", "yql"]
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ Make python more SQL like over REST responses main entry functions are create and select The goal here is to let the developer specif...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ Some handy user defined functions to plug in db.select """ __author__ = "Vik Singh (viksi@yahoo-inc.com)" from util.typechecks impor...
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) __all__ = ["asizeof", "db", "udfs"]
Python
# Copyright (c) 2008 Yahoo! Inc. All rights reserved. # Licensed under the Yahoo! Search BOSS Terms of Use # (http://info.yahoo.com/legal/us/yahoo/search/bosstos/bosstos-2317.html) """ Calculate the size of an object in python This code used to be very complicated, and then realized in certain cases it failed Given th...
Python
#!/usr/bin/python2.6 # # Simple http server to emulate api.playfoursquare.com import logging import shutil import sys import urlparse import SimpleHTTPServer import BaseHTTPServer class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Handle playfoursquare.com requests, for testing.""" def do_GET(self...
Python
#!/usr/bin/python import os import subprocess import sys BASEDIR = '../main/src/com/joelapenna/foursquare' TYPESDIR = '../captures/types/v1' captures = sys.argv[1:] if not captures: captures = os.listdir(TYPESDIR) for f in captures: basename = f.split('.')[0] javaname = ''.join([c.capitalize() for c in basena...
Python
#!/usr/bin/python """ Pull a oAuth protected page from foursquare. Expects ~/.oget to contain (one on each line): CONSUMER_KEY CONSUMER_KEY_SECRET USERNAME PASSWORD Don't forget to chmod 600 the file! """ import httplib import os import re import sys import urllib import urllib2 import urlparse import user from xml....
Python
#!/usr/bin/python import datetime import sys import textwrap import common from xml.dom import pulldom PARSER = """\ /** * Copyright 2009 Joe LaPenna */ package com.joelapenna.foursquare.parsers; import com.joelapenna.foursquare.Foursquare; import com.joelapenna.foursquare.error.FoursquareError; import com.joel...
Python
#!/usr/bin/python import logging from xml.dom import minidom from xml.dom import pulldom BOOLEAN = "boolean" STRING = "String" GROUP = "Group" # Interfaces that all FoursquareTypes implement. DEFAULT_INTERFACES = ['FoursquareType'] # Interfaces that specific FoursqureTypes implement. INTERFACES = { } DEFAULT_CLA...
Python
#!/usr/bin/python2.6 # # Simple http server to emulate api.playfoursquare.com import logging import shutil import sys import urlparse import SimpleHTTPServer import BaseHTTPServer class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Handle playfoursquare.com requests, for testing.""" def do_GET(self...
Python
#!/usr/bin/python import datetime import sys import textwrap import common from xml.dom import pulldom PARSER = """\ /** * Copyright 2009 Joe LaPenna */ package com.joelapenna.foursquare.parsers; import com.joelapenna.foursquare.Foursquare; import com.joelapenna.foursquare.error.FoursquareError; import com.joel...
Python
#!/usr/bin/python """ Pull a oAuth protected page from foursquare. Expects ~/.oget to contain (one on each line): CONSUMER_KEY CONSUMER_KEY_SECRET USERNAME PASSWORD Don't forget to chmod 600 the file! """ import httplib import os import re import sys import urllib import urllib2 import urlparse import user from xml....
Python
#!/usr/bin/python import os import subprocess import sys BASEDIR = '../main/src/com/joelapenna/foursquare' TYPESDIR = '../captures/types/v1' captures = sys.argv[1:] if not captures: captures = os.listdir(TYPESDIR) for f in captures: basename = f.split('.')[0] javaname = ''.join([c.capitalize() for c in basena...
Python
#!/usr/bin/python import logging from xml.dom import minidom from xml.dom import pulldom BOOLEAN = "boolean" STRING = "String" GROUP = "Group" # Interfaces that all FoursquareTypes implement. DEFAULT_INTERFACES = ['FoursquareType'] # Interfaces that specific FoursqureTypes implement. INTERFACES = { } DEFAULT_CLA...
Python
#!/usr/bin/python import sys, hashlib def write_file(fn, buf): fp = open(fn, "wb") fp.write(buf) fp.close() def usage(): print ("Usage: " + sys.argv[0] + " infile outfile label") def main(): if( len(sys.argv) != 4): usage() sys.exit() fp = open( sys.argv[1] , "rb") hash_str = has...
Python
#!/usr/bin/python import sys, re, os def write_file(fn, buf): fp = open(fn, "wb") fp.write(buf) fp.close() def usage(): print ("Usage: " + os.path.split(__file__)[1] + " version outfile") def crete_version_str(ver): base = list("0.00") version = str(ver) ret = [] base[0] = version[0] base...
Python
#!/usr/bin/python """ PRO build script""" import os, shutil, sys NIGHTLY=0 VERSION="B9" PRO_BUILD = [ { "fn": "620PRO-%s.rar", "config": "CONFIG_620=1" }, { "fn": "635PRO-%s.rar", "config": "CONFIG_635=1" }, { "fn": "639PRO-%s.rar", "config": "CONFIG_639=1" }, { "fn": "660PRO-%s.rar", "config": "CONFIG_...
Python
#!/usr/bin/python import sys, os, gzip, StringIO def dump_binary(fn, data): f = open(fn, "wb") f.write(data) f.close() def dec_prx(fn): f = open(fn, "rb") f.seek(0x150) dat = f.read() f.close() temp=StringIO.StringIO(dat) f=gzip.GzipFile(fileobj=temp, mode='rb') dec = f.read(f) f.close() fn = "%s.dec.p...
Python
#!/usr/bin/python class FakeTime: def time(self): return 1225856967.109 import sys, os, struct, gzip, hashlib, StringIO gzip.time = FakeTime() def binary_replace(data, newdata, offset): return data[0:offset] + newdata + data[offset+len(newdata):] def prx_compress(output, hdr, input, mod_name="", mod_a...
Python
#!/usr/bin/python import sys, hashlib def toNID(name): hashstr = hashlib.sha1(name.encode()).hexdigest().upper() return "0x" + hashstr[6:8] + hashstr[4:6] + hashstr[2:4] + hashstr[0:2] if __name__ == "__main__": assert(toNID("sceKernelCpuSuspendIntr") == "0x092968F4") for name in sys.argv[1:]: print ("%s: %s"...
Python
#!/usr/bin/python from hashlib import * import sys, struct def sha512(psid): if len(psid) != 16: return "".encode() for i in range(512): psid = sha1(psid).digest() return psid def get_psid(str): if len(str) != 32: return "".encode() b = "".encode() for i in range(0, len(str), 2): b += struct.pack('B...
Python
#!/usr/bin/python """ pspbtcnf_editor: An script that add modules from pspbtcnf """ import sys, os, re from getopt import * from struct import * BTCNF_MAGIC=0x0F803001 verbose = False def print_usage(): print ("%s: pspbtcnf.bin [-o output.bin] [-a add_module_name:before_module_name:flag]" %(os.path...
Python
#!/usr/bin/python import os def main(): lists = [ "ISODrivers/Galaxy/galaxy.prx", "ISODrivers/March33/march33.prx", "ISODrivers/March33/march33_620.prx", "ISODrivers/March33/march33_660.prx", "ISODrivers/Inferno/inferno.prx", "Popcorn/popcorn.prx", "Satelite/satelite.prx", "Stargate/stargate....
Python
#!/usr/bin/python class FakeTime: def time(self): return 1225856967.109 import os, gzip, StringIO gzip.time = FakeTime() def create_gzip(input, output): f_in=open(input, 'rb') temp=StringIO.StringIO() f=gzip.GzipFile(fileobj=temp, mode='wb') f.writelines(f_in) f.close() f_in.close() fout=open(out...
Python
#!/usr/bin/python import os, sys, getopt def usage(): print ("Usage: %s [-l size ] basefile input output" % (sys.argv[0])) def write_file(fn, buf): fp = open(fn, "wb") fp.write(buf) fp.close() def main(): inputsize = 0 try: optlist, args = getopt.getopt(sys.argv[1:], 'l:h') except getopt.GetoptError: us...
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) print "%.3lf" % ((a+b+c)/3.0)
Python
from sys import stdin from math import * r, h = map(float, stdin.readline().strip().split()) print "Area = %.3lf" % (pi*r*r*2 + 2*pi*r*h)
Python
from sys import stdin from math import * n, = map(int, stdin.readline().strip().split()) rad = radians(n) print "%.3lf %.3lf" % (sin(rad), cos(rad))
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print n*(n+1)/2
Python
from sys import stdin a, b = map(int, stdin.readline().strip().split()) print b, a
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) a = (4*n-m)/2 b = n-a if m % 2 == 1 or a < 0 or b < 0: print "No answer" else: print a, b
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) money = n * 95 if money >= 300: money *= 0.85 print "%.2lf" % money
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print ["yes", "no"][n % 2]
Python
from sys import stdin from math import * x1, y1, x2, y2 = map(float, stdin.readline().strip().split()) print "%.3lf" % hypot((x1-x2), (y1-y2))
Python
from sys import stdin n = stdin.readline().strip().split()[0] print '%c%c%c' % (n[2], n[1], n[0])
Python
from sys import stdin x, = map(float, stdin.readline().strip().split()) print abs(x)
Python
from sys import stdin from calendar import isleap year, = map(int, stdin.readline().strip().split()) if isleap(year): print "yes" else: print "no"
Python
from sys import stdin f, = map(float, stdin.readline().strip().split()) print "%.3lf" % (5*(f-32)/9)
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a: print "yes" elif a + b <= c or a + c <= b or b + c <= a: print "not a triangle" else: print "no"
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) a.sort() print a[0], a[1], a[2]
Python
s = i = 0 while True: term = 1.0 / (i*2+1) s += term * ((-1)**i) if term < 1e-6: break i += 1 print "%.6lf" % s
Python
from sys import stdin from decimal import * a, b, c = map(int, stdin.readline().strip().split()) getcontext().prec = c print Decimal(a) / Decimal(b)
Python
from sys import stdin n = int(stdin.readline().strip()) print "%.3lf" % sum([1.0/x for x in range(1,n+1)])
Python