This file contains 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
"""We want to calculate the probabilty that in a set of 3 sets, each composed of 3 different integers in the range [1,9] | |
we have at least one set where all the integers are odd""" | |
import random | |
print("""We want to calculate the probabilty that in a set of 3 sets, each composed of 3 different integers in the range [1,9] | |
we have at least one set where all the integers are odd\n\n""") | |
print("For example in the list [[1,4,5],[7,3,9],[2,6,8]] we have 1 sublist where all numbers are odd\n\n") | |
print("Let's start...") | |
print("Loading...") |
This file contains 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
""" Given the first 10 numbers, we want to know how many snake permutations exist, where a snake permutations is: | |
x1 < x2 > x3 < x4 > x5 < x6 > x7 < x8 > x9 < x10 | |
The result is very counterintuitive....more than 50000 snake permutation exist. | |
It takes a lot of time to have the output, so take only the idea of the code...""" | |
import random | |
union = [] | |
for i in range (25000000): | |
A = [s for s in range (1,11)] | |
new = [] |
This file contains 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
# On average how many times do you need to roll a die before all six different numbers show up? | |
import random | |
dado = [i for i in range (1,7)] | |
throw_list = [] | |
N = 100000 # montecarlo method | |
for i in range(N): | |
lista = [] |
This file contains 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
''' A tennis club invites 32 players of equal ability to compete in an elimination tournament. | |
(Only the winner of the pair will stay for the next round) | |
What is the probability that a particular pair of players will meet during the tournament?''' | |
import random | |
count = 0 | |
def recursive_round(a): # we create a recursive function to simulate the tournament where the argument is a list | |
if len(a) == 1: | |
return a[0] |
This file contains 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 collatz(number): | |
if number % 2 == 0: | |
print(number // 2) | |
return (number // 2) | |
else: | |
print(3 * number + 1) | |
return (3 * number + 1) | |
This file contains 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
''' In what follows all number are uniformly distributed on [0,1]. Start with | |
a number So and the keep on generating the sequence S1,S2....until, for some | |
N, Sn > So for the first time. What is the expected value E(N) of that N ? ''' | |
import statistics | |
import random | |
# we proceed with Montecarlo method | |
Series_of_n = [] #we creat a list of 10 million elements (n = 10.000.000) |
This file contains 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 math | |
import random | |
count = 0 | |
n = 1000000 #montecarlo simulation | |
for i in range (1000000): | |
z = float(random.uniform(0,(math.pi)/2)) #uniform distribution, it gives a random real number between (0, π/2) | |
y = float(random.uniform(0,z)) | |
x = float(random.uniform(0,y)) |
This file contains 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
''' There are ten coins, each blank on one side and numbered on the other side with numbers 1 through 10. | |
All ten coins are tossed and the sum of numbers landing face up is calculated. What is the probability that this sum is at least 45? | |
''' | |
import random | |
def toss_coin (x): | |
coin = random.choice ([0,x]) #a discrete uniform distribution between values of a sequence, in this case 2 values possible. | |
return (coin) |
This file contains 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
''' Here the description of the problem: https://www.hackerrank.com/challenges/bomber-man/problem ''' | |
from random import choice | |
from time import sleep | |
R, C, N = map(int, input().split()) # we take the number of rows, columns and seconds of the loop | |
Lista = [] # we create the grid where each element is randomnly chosen between '.'(free cell) and 'M'(marked bomb) | |
for r in range(R): |
This file contains 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
'''' Here's the problem: https://www.hackerrank.com/challenges/python-sort-sort/problem''' | |
N,M = map(int,input('First number is the number of athletes,\n\ | |
second number is the number of attributes for each atlhete.\nWrite: ').split()) | |
print() | |
print("So we have {} athletes and {} in our database\n".format(N,M)) | |
L = [] | |
for i in range(1,N+1): | |
L.append(list(map(int,input('Write attributes for athlete number {} : '.format(i)).split()))) |
OlderNewer