Skip to content

Instantly share code, notes, and snippets.

View lorenzotinfena's full-sized avatar
🏠
OutOfMemoryException thrown in --> malloc(sizeof(RLpower))

Lorenzo Tinfena lorenzotinfena

🏠
OutOfMemoryException thrown in --> malloc(sizeof(RLpower))
View GitHub Profile
@lorenzotinfena
lorenzotinfena / sort.go
Created August 24, 2023 19:44
Efficient (but ugly) radix sort implementation for uint32
func Sort(v []uint32) {
rec0 := func(L, R int) {
l := L
r := R
for l <= r {
if v[l]&(1<<0) == 0 {
l++
} else {
v[l], v[r] = v[r], v[l]
r--
@lorenzotinfena
lorenzotinfena / main.py
Last active April 13, 2022 17:27
3.code inside "A formal introduction to Deep Reinforcement Learning"
state = get_first_state()
while not done:
# policy
if random ∈[0,1] < epsilon: action = random_action
else: action = argmax(nn.predict(state))
next_state, reward, done = step(action) # perform the action
replay_memory.put(state, action, reward, done, next_state) # save in replay memory
if len(replay_memory) >= batch_size: # if there is enough memory
# get a mini-batch from the replay memory
for state_exp, action_exp, reward_exp, done_exp, next_state_exp in replay_memory.get_random(batch_size):
@lorenzotinfena
lorenzotinfena / main.py
Last active April 13, 2022 17:20
1.code inside "A formal introduction to Deep Reinforcement Learning"
import gym
env = gym.make('CartPole-v1')
# initialize metrics
total_reward = 0
steps = 0
current_state = env.reset() # obtain first state
done = False
while not done: # when done is True the episode ends
action = env.action_space.sample() # get a random action from A of the environment
next_state, reward, done, _ = env.step(action) # perform the action
@lorenzotinfena
lorenzotinfena / 1. Slowest Key Press.go
Last active September 13, 2021 19:46
my code of "Lord of Code | Italian Edition 2021" challenge
func slowestKey(keyTimes [][]int32) string {
a := [][]int32{{-1, 0}}
keyTimes = append(a, keyTimes...)
var max int32
var c int32
for i := 1; i < len(keyTimes); i++ {
if tmp := keyTimes[i][1] - keyTimes[i-1][1]; tmp > max{
max = tmp
c = keyTimes[i][0]
}
@lorenzotinfena
lorenzotinfena / Useful links.txt
Last active November 23, 2020 08:23
Useful links