Skip to content

Instantly share code, notes, and snippets.

Ceasar Bautista Ceasar

Block or report user

Report or block Ceasar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View game.py
import random
def main():
while True:
a, b = random.randint(1, 10), random.randint(1, 10)
expr = "{} + {}".format(a, b)
print "What is {}?".format(expr)
try:
given_answer = int(raw_input('> '))
@Ceasar
Ceasar / floydwarshall.py
Created Apr 23, 2012
Simple implementation of floyd-warhsall algorithm in Python.
View floydwarshall.py
def adj(g):
"""
Convert a directed graph to an adjacency matrix.
Note: The distance from a node to itself is 0 and distance from a node to
an unconnected node is defined to be infinite.
>>> g = {1: {2: 3, 3: 8, 5: -4},
@Ceasar
Ceasar / xml2json.py
Created Jul 26, 2013
Convert xml to json.
View xml2json.py
'''A module for converting xml into json.'''
import json
from lxml import etree
def xml_to_json(xml_input, json_output):
'''Converts an xml file to json.'''
dict_to_json(etree_to_dict(xml_to_etree(xml_input), True), json_output)
@Ceasar
Ceasar / eredan_arean.py
Last active Feb 12, 2018
Computes how an attack will go for some heroes in Eredan Arena.
View eredan_arean.py
"""
http://www.kongregate.com/games/feerik/eredan-arena
"""
import itertools
die = ['R', 'R', 'B', 'Y', 'S', 'S']
sides = set(die)
View app.py
import json
from flask import Flask, request, url_for, jsonify
app = Flask(__name__)
with open('photos.json') as fp:
PHOTOS = json.loads(fp.read())
with open('albums.json') as fp:
@Ceasar
Ceasar / parse.hs
Created Dec 1, 2012
A basic parser written in Haskell. Written as a learning exercise.
View parse.hs
import Data.List
-- Evaluate a postfix expression
evalPostfix :: (Num a, Read a) => String -> a
evalPostfix = head . foldl comb [] . words
where
comb (x:y:ys) "*" = (x * y) : ys
comb (x:y:ys) "+" = (x + y) : ys
comb (x:y:ys) "-" = (y - x) : ys
View basins.py
"""
Palantir interview question.
The goal is to, given an elevation map of some land, print out a
list of basin sizes in descending order, where a basin is a set of
cells of land that all drain to a common point. One cell drains to
another if among the first cell and its neighbors (i.e. cells adjacent,
horizonatlly, vertically or diagonally) the second cell has the lowest
elevation.
@Ceasar
Ceasar / Lisp.hs
Created Jul 27, 2013
Lisp in Haskell. WIP.
View Lisp.hs
import Text.ParserCombinators.Parsec
import System.Environment
data LispVal = Atom String
-- | List [LispVal]
-- | DottedList [LispVal] LispVal
| Number Integer
| String String
@Ceasar
Ceasar / Logic.lhs
Created Jul 26, 2013
Propositional logic.
View Logic.lhs
> import Data.Set as S
> import Data.Map as M
> import Data.Maybe
> import Control.Monad (liftM, liftM2)
> import Test.QuickCheck
A statement is a sentence that is determinately true of determinately false independently of the circumstances in which it is used.
> data Proposition = Implies Proposition Proposition
View speed_primes.py
import timeit
setup = """
def primes(n):
'''Get all primes up to n.'''
if n < 2:
return []
nums = range(n)
sieve = set(xrange(2, n))
You can’t perform that action at this time.