Skip to content

Instantly share code, notes, and snippets.

View pheuter's full-sized avatar

Mark Fayngersh pheuter

View GitHub Profile
def uncipher(str)
1.upto(26) do |shift|
key = Hash[('a'..'z').zip((97..122).collect{ |i| if (i+shift > 122) then ((i + shift) % 122) + 96 else i+shift end })].merge({' '=>' '.ord,','=>','.ord,'.'=>'.'.ord,'?'=>'?'.ord,'!'=>'!'.ord})
freqs = Hash.new(0)
tmp = str.split('').collect { |letter| switched = (key[letter]).chr; freqs[switched] += 1; switched }
total = 0
freqs.each { |e| total += e[1] }
puts tmp.join if freqs['e']/total.to_f * 100 > 7 and freqs['t']/total.to_f * 100 > 5 # Might want to eventually make more accomodating
end
end
require "prime"
fib = Fiber.new do
x, y = 0, 1
loop do
Fiber.yield y
x,y = y, x+y
end
end
str = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesed
import Data.List
main = print $ length . filter (\x -> sum x `elem` a) . filter (\x -> length x > 1) $ subsequences a
where a = [3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99]
5 4 1 + = [ "5 = 5, YAY!" ] [ ":(" ] if
server = ServerSocket new() : ServerSocket
---------------------------------------------------------------
ERROR No such function accept(Int, SockAddr*, UInt*)
conn := accept(descriptor, addr&, addrSize&)
^^^^^^
Nearest match is:
accept: func (s : Int, addr : SockAddr*, addrlen : UInt) -> Int
..but the type of this arg should be UInt (lang/types [23951, 23955]), not UInt* (lang/types [23951, 23955])