Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
ary = []
itrts = 50_000_000
code_range = 1e+13.to_i...4e+13.to_i
itrts.times do |i|
ary << rand(code_range)
end
puts Benchmark::CAPTION
# Const
CODE_NUMS = 100
CODE_LENGTH = 8
AVAILABLE_CHARS = ('A'..'Z').to_a.delete_if{|c| c == 'O'}
AVAILABLE_CHARS_NUM = AVAILABLE_CHARS.length
# Throw random nums to suck
code_suck = []
(CODE_NUMS*2).times do
buff = []
module Main where
import System.Random
import Data.Maybe
import Data.Bits
import Data.List
import Data.Char
main = do
gen <- getStdGen
@oropon
oropon / Primes
Last active January 3, 2016 05:58
module Main where
main = putStrLn $ unlines $ map (show) $ primes 1000000
primes :: Int -> [Int]
primes max
| max < 2 = error "No primes"
| otherwise = erat [] [2..max]
where
erat :: [Int] -> [Int] -> [Int]
module Main where
main = print $ calc cs
cs = "3 4 + 5 2 - * 4 2 / +"
calc :: String -> Float
calc = head . foldl calc' [] . words where
calc' :: [Float] -> String -> [Float]
calc' [x] [] = [x]
module Main where
main = print $ calc cs
cs = "3 4 + 5 2 - * 4 2 / +"
calc :: String -> Float
calc = calc' [] . words
calc' :: [Float] -> [String] -> Float
@oropon
oropon / gist:5160008
Created March 14, 2013 09:20
compact recursiveDescription-block
NSString*(^__block __weak r)(id,int)=^(id v,int d){NSMutableString*m,*l;m=[NSMutableString string];l=[NSMutableString string];for(id _ in [v subviews])[m appendString:r(_,d+1)];for(int i=0;i<d;i++)[l appendString:@" | "];return[NSString stringWithFormat:@"%@%@\n%@",l,[v description], m];};
NSLog(@"\n%@", r(<#target_view#>, 0));
@oropon
oropon / gist:5159805
Created March 14, 2013 08:39
My recursive description (iOS/OSX)(ARC/ManualMemoryManagement)
#if TARGET_OS_IPHONE
@interface UIView (RecursiveDescription)
#else
@interface NSView (RecursiveDescription)
#endif
#ifdef DEBUG
- (NSString*)_recursiveDescription;
#endif
@end