Skip to content

Instantly share code, notes, and snippets.

View antonio-catalano's full-sized avatar

Antonio Catalano antonio-catalano

View GitHub Profile
@antonio-catalano
antonio-catalano / history
Created February 22, 2019 16:31
history file
==> 2018-05-07 05:54:59 <==
# cmd: C:\Users\Admin\Anaconda3\Scripts\conda install pandas-datareader
+defaults::_ipyw_jlab_nb_ext_conf-0.1.0-py36he6757f0_0
+defaults::alabaster-0.7.10-py36hcd07829_0
+defaults::anaconda-5.1.0-py36_2
+defaults::anaconda-client-1.6.9-py36_0
+defaults::anaconda-navigator-1.7.0-py36_0
+defaults::anaconda-project-0.8.2-py36hfad2e28_0
+defaults::asn1crypto-0.24.0-py36_0
+defaults::astroid-1.6.1-py36_0
import numpy as np
import matplotlib.pyplot as plt
def IQ(IQ_mean, IQ_std):
IQ_value_low = []
IQ_value_high = []
IQ_all = []
for i in range(10000):
IQ_value = np.random.normal(IQ_mean, IQ_std)
IQ_all.append(IQ_value)
@antonio-catalano
antonio-catalano / bubblesortquiz.py
Last active April 24, 2018 12:33
bubble sort quiz
''' In this link the description of problem: https://twitter.com/CutTheKnotMath/status/988401818915999744 '''
import random
def bubblesortOnePass(l):
if len(l) == 1:
return l
else:
for i in range(len(l)):
try:
@antonio-catalano
antonio-catalano / DynamicAlgo.py
Created April 19, 2018 13:11
dynamic programming code
"It's a reworked version of Problem 14 that you find here: http://interactivepython.org/runestone/static/pythonds/Recursion/pythondsProgrammingExercises.html"
dizio_1 = { (2,2): 1, (3,4): 2, (4,6): 3, (5,7): 4, (9,10): 5, (9,11): 6, (13,15): 7, (16,19): 8, \
(25,37): 9, (35,45):10 }
def createTab ( _Dict ): #create the graphic tab
dizio = _Dict
print('','Item', 'Weight', 'Value','\n', sep=" " )
for key in dizio:
spazio = " "
@antonio-catalano
antonio-catalano / AthleteSort.py
Created April 14, 2018 13:22
from hackerrank site
'''' 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())))
@antonio-catalano
antonio-catalano / BomberManGame.py
Created April 14, 2018 10:27
The BomberMan Game
''' 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):
''' 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)
@antonio-catalano
antonio-catalano / Inequality.py
Last active April 8, 2018 00:45
Show that for three real number that satisfy 0 < x < y < z < π/2 , the following inequality holds: (x+y) sin(z) + (x-z) sin(y) < (y+z) sin(x)
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))
''' 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)
@antonio-catalano
antonio-catalano / collatz_conjecture.py
Created April 8, 2018 00:40
It will print the collatz sequence given an initial positive integer number
def collatz(number):
if number % 2 == 0:
print(number // 2)
return (number // 2)
else:
print(3 * number + 1)
return (3 * number + 1)