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
$ python examples/quickstart.py | |
[2017-07-25 01:30:48,333] Making new env: CartPole-v0 | |
{max_kl_divergence=0.005, states={shape=(4,), type=float}, cg_damping=0.01, network=<function network_builder at 0x7f7e7a055f50>, normalize_advantage=False, actions={continuous=False, num_actions=2}, gae_lambda=0.97, line_search_steps=20, loglevel=info, override_line_search=False, batch_size=100, generalized_advantage_estimation=True, cg_iterations=20, baseline={type=mlp, repeat_update=100, size=32}} | |
Finished episode 1 after 18 timesteps (reward: 18.0) | |
Finished episode 2 after 19 timesteps (reward: 19.0) | |
Finished episode 3 after 44 timesteps (reward: 44.0) | |
Finished episode 4 after 13 timesteps (reward: 13.0) | |
Finished episode 5 after 17 timesteps (reward: 17.0) | |
Finished episode 6 after 22 timesteps (reward: 22.0) | |
Finished episode 7 after 25 timesteps (reward: 25.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
$ python examples/quickstart.py | |
[2017-07-24 23:13:32,771] Making new env: CartPole-v0 | |
Finished episode 1 after 40 timesteps (reward: 40.0) | |
Finished episode 2 after 25 timesteps (reward: 25.0) | |
Finished episode 3 after 20 timesteps (reward: 20.0) | |
Finished episode 4 after 36 timesteps (reward: 36.0) | |
Finished episode 5 after 21 timesteps (reward: 21.0) | |
Finished episode 6 after 44 timesteps (reward: 44.0) | |
Finished episode 7 after 12 timesteps (reward: 12.0) | |
Finished episode 8 after 16 timesteps (reward: 16.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
// $ g++ sparse.cpp --std=c++11 | |
// $ time ./a.out | |
// sum(2000000000) = 95673602693282040 | |
// | |
// real 0m0.150s | |
// user 0m0.147s | |
// sys 0m0.003s | |
#include <iostream> |
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 qualified Control.Monad as ControlMonad | |
import qualified Data.Array as Array | |
import qualified Data.Array.ST as ArrayST | |
import qualified Data.Array.Base as ArrayBase | |
import Control.DeepSeq | |
import qualified Data.Map as Map | |
-- From "The Genuine Sieve of Eratosthenes" by Melissa O'Neill. | |
-- O(n * log n * log log n) | |
sieve xs = sieve' xs Map.empty |
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 P10(n): | |
r = int(n**0.5) | |
assert r*r <= n and (r+1)**2 > n | |
V = [n//i for i in range(1,r+1)] | |
V += list(range(V[-1]-1,0,-1)) | |
S = {i:i*(i+1)//2-1 for i in V} | |
for p in range(2,r+1): | |
if S[p] > S[p-1]: # p is prime | |
sp = S[p-1] # sum of primes smaller than p | |
p2 = p*p |
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 Control.Monad (when, forM_) | |
import qualified Data.Judy as J | |
import Data.Maybe (fromJust) | |
import qualified Data.Vector.Unboxed as V | |
import Control.Applicative | |
p10 n = do | |
let r = floor (sqrt (fromIntegral n)) | |
let n' = n `div` r - 1 | |
let v1 = V.generate r $ \i -> n `div` (i + 1) -- [n `div` i | i <- [1..r]] |
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
/* | |
Compile: | |
g++ -O2 --std=c++11 10.cpp | |
Run: | |
time ./a.out | |
Results with g++ version 4.8.4: | |
sum(20000000) = 12272577818052 in 0.019s | |
sum(200000000) = 1075207199997334 in 0.063s |
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.List | |
import qualified Data.HashTable.IO as H | |
import Data.Maybe (fromJust) | |
type HashTable k v = H.BasicHashTable k v | |
(!) :: IO (HashTable Int Int) -> Int -> IO Int | |
(!) m k = do | |
h <- m | |
x <- H.lookup h k |
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.List | |
import Data.IntMap.Strict(IntMap, (!)) | |
import qualified Data.IntMap.Strict as IntMap | |
problem10 :: Int -> Int | |
problem10 n = (sieve (IntMap.fromList [(i, i * (i + 1) `div` 2 - 1) | i <- vs]) 2 r vs) ! n | |
where vs = [n `div` i | i <- [1..r]] ++ [n', n' - 1 .. 1] | |
r = floor (sqrt (fromIntegral n)) | |
n' = n `div` r - 1 |
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.List | |
import Data.IntMap (IntMap, (!)) | |
import qualified Data.IntMap as IntMap | |
p :: Int -> Int | |
p n = (sieve (IntMap.fromList [(i, i * (i + 1) `div` 2 - 1) | i <- vs]) 2 r vs) ! n | |
where vs = [n `div` i | i <- [1..r]] ++ reverse [1..n `div` r - 1] | |
r = floor (sqrt (fromIntegral n)) |