This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Vector.Unboxed as V | |
| main :: IO () | |
| main = print $ sumVector ones | |
| sumVector :: (Num a, Unbox a) => Vector a -> a | |
| sumVector = V.foldl' (+) 0 | |
| {-# NOINLINE ones #-} | |
| ones :: Vector Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Extremely inefficient priority queue. | |
| * | |
| * In a real program this would probably be implemented as a heap, | |
| * but this is good enough for this demonstration. | |
| */ | |
| function PQueue(comparator) { | |
| this.comparator = comparator || function(x, y) { return x - y } | |
| this.array = [] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Prim's algorithm | |
| * | |
| * __(')< written by lambda fairy | |
| * \___) | |
| */ | |
| function reset_graph(g) { | |
| function reset(thing) { | |
| thing.set_type(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Traceback (most recent call last): | |
| File "/usr/bin/sugar-activity", line 146, in <module> | |
| main() | |
| File "/usr/bin/sugar-activity", line 104, in main | |
| module = __import__(module_name) | |
| File "/home/liveuser/Activities/Maze(GTK3).activity/activity.py", line 6, in <module> | |
| from gi.repository import Gtk | |
| File "/usr/lib64/python2.7/site-packages/gi/__init__.py", line 23, in <module> | |
| from ._gi import _API, Repository | |
| ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".',)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Parse the file at <http://hogsofdestiny.com/kol/pricegun/dailyprice.log>""" | |
| from urllib2 import urlopen | |
| def read_prices(lines): | |
| """Given an iterator yielding the lines of the input file, return a dictionary mapping item IDs to prices.""" | |
| result = {} | |
| for line in lines: | |
| # Ignore comments | |
| if line.startswith('#'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| You open the blind-pack capsules and dump out the toys inside: | |
| You acquire an item: tiny plastic Charity the Zombie Hunter | |
| You acquire 2 tiny plastic fire servants | |
| You acquire an item: tiny plastic Scott the Miner | |
| You acquire an item: tiny plastic beebee queue | |
| You acquire an item: tiny plastic cavebugbear | |
| You acquire 2 tiny plastic the Free Men | |
| You acquire 2 tiny plastic Queen Bees | |
| You acquire 2 tiny plastic angry space marines | |
| You acquire an item: tiny plastic Norville Rogers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Simple implementation of Kruskal's algorithm using a disjoint set""" | |
| from collections import namedtuple | |
| Edge = namedtuple('Edge', 'weight start end') | |
| class DisjointSet: | |
| def __init__(self, key): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from random import randint | |
| def simulate(): | |
| """Simulate one round of the game Gus described.""" | |
| pushes = 1 | |
| # Until a kitten pops out | |
| while randint(0, 99) != 0: | |
| # Push the button |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def max_index(items, start, end): | |
| best_item = None | |
| best_index = None | |
| for index, item in zip(range(start, end), items[start:end]): | |
| if best_item is None or item > best_item: | |
| best_item = item | |
| best_index = index | |
| if best_index is None: | |
| raise ValueError('maximum of empty sequence') | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Wormholes <http://nztrain.com/problems/98> | |
| #include <algorithm> | |
| #include <cstdio> | |
| #include <vector> | |
| using namespace std; | |
| // This can't be INT_MAX -- adding anything to INT_MAX would cause it to | |
| // overflow and become negative. | |
| // Kudos to Alan Ansell for pointing that out |