Skip to content

Instantly share code, notes, and snippets.

View Louis-Saglio's full-sized avatar

Louis Saglio Louis-Saglio

View GitHub Profile
@Louis-Saglio
Louis-Saglio / results.txt
Created August 25, 2022 13:26
Results of simulated Risk fights
Documentation :
Defenders strategies :
- 0 : always roll 2 dice
- 1 : roll one die if the sum of the best two attacker dice is >= 8
- 1.n : roll one die if the sum of the best two attacker dice is >= n
- 2 : like 1 but if there are only 2 defender units remaining always roll 2 dice
- 3 : like 2 but if the attacker has only 3 or fewer units remaining always throw 2 dice
Winning rate is the probability of an attacker victory
use std::cmp::min;
use rand::Rng;
use crate::Player::{Attacker, Defender};
enum Player {
Attacker, Defender
}
struct Delta {
a_delta: u32,
@Louis-Saglio
Louis-Saglio / gist:33a4eb4207f33a76c9c6b1ed44bb1cc1
Created December 2, 2019 18:34
Django console starting script for Pycharm with docker interpreter
When a Django project is configured with an interpreter located in a docker container, the python console encounter errors.
To fix that, go to file > settings > Build, Execution, Deployment > Console > Django Console.
Then override the starting script with the following snippet :
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS, '/opt/.pycharm_helpers/pycharm', '/opt/.pycharm_helpers/pydev'])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
75.83
55.912
56.9861
98
92.6667
83
69.7037
55.2549
54.6
@Louis-Saglio
Louis-Saglio / Some things to remind you why we live in a cold, deterministic, deluded world :)
Created July 17, 2019 15:31
Some things to remind you why we live in a cold, deterministic, deluded world :)
There is nothing after death, you will disappear, like you were never existed, as if your story was never told.
There was nothing before your birth and there will be nothing after your death.
Your free will is an illusion, you are a living organism just like every other animal, you are built with similar systems as to all mammals, you are not so different than a rat roaming the street, searching for potential mate, shelter, or food.
Your life matters just like the animal that had to be murdered in order for you to eat it's meat few days ago.
You are made out of material, you are nothing special among the 7.6 billion humans living on earth.
#!/usr/bin/env python
def read_stdin() -> list:
"""
Returns a list of str read from stdin.
Use whitespaces as word separator.
"""
# 0 is the file descriptor of stdin.
# A more clever way would have been to use sys.stdin, but it is forbidden for pedagogic reasons
#!/usr/bin/env python3.7
def read_stdin() -> list:
"""
Returns a list of str read from stdin.
Use whitespaces as word separator.
"""
# 0 is the file descriptor of stdin.
# A more clever way would have been to use sys.stdin, but it is forbidden for pedagogic reasons
@Louis-Saglio
Louis-Saglio / in_set_vs_list_vs_tuple.py
Last active March 25, 2019 14:39
determine if instanciating and checking presence in a set is more efficient than instanciating and checking in a list or a tuple
from random import randint
from time import time
# Runtime values
i, j, k = randint(0, 9), randint(0, 9), randint(0, 9)
start = time()
for _ in range(10_000_000):
@Louis-Saglio
Louis-Saglio / to_dict.py
Last active September 19, 2019 07:06
Transform any object into dict by recursively exploring __dict__ attribute
import json
def is_iterable(obj):
try:
for _ in obj:
return True
except TypeError:
return False
rm(list=ls())
Eleve1 = c(17, 18.5, 14, 17.5, 13)
Eleve2 = c(8, 19.5, 20, 6.5, 18.5)
Eleve3 = c(14, 15.5, 12.5, 15.5, 13)
Matiere = c("Maths", "Anglais", "Chimie", "Sport", "Dessin")
Eleves = c("Eleve4", "Eleve5", "Eleve6", "Eleve7", "Eleve8", "Eleve9", "Eleve10", "Eleve1", "Eleve2", "Eleve3")