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 convert_to_code(id, alphabet=ALPHABET): | |
"""Converts a decimal id number into a shortened URL code. Use the id of the | |
row in the database with the entered long URL.""" | |
if id <= 0: #invalid codes (autoincrement is always 1 or higher) | |
return alphabet[0] | |
base = len(alphabet) #base to convert to (56 for our standard alphabet) | |
chars = [] | |
while id: | |
chars.append(alphabet[id % base]) |
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/local/bin/ruby -rubygems | |
require 'open-uri' | |
require 'json' | |
require 'pony' | |
class Headline | |
def initialize(title, title_url, points, | |
comments, comments_url, time, time_units) | |
@title = title |
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
$ ./halt.py principia.py | |
False | |
$ oh gosh | |
i know |
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
____ | |
/(( )) / | |
( )6 -( ) / | |
(_) l (_) / | |
\ <> ) | |
) ( | |
.----\""/----. | |
| \/ | | |
| | . | | | |
| | . | |____/__ |
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
find . -name '*.java' | xargs wc -l |
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
//Maps all a^b terms for lower <= b <= upper to all a for lower <= a <= upper | |
def getDistinctCount(lower:Int, upper:Int) = { | |
(lower to upper).flatMap(a => (lower to upper).map(b => BigInt(a).pow(b))) | |
.distinct.size //Return number of distinct elements | |
} | |
println(getDistinctCount(2, 100)) |