Sur une machine à sous d’un casino, on gagne 50€ dès que l’on a 3 valeurs identiques (3 Rois, 3 Dames ou 3 Valets) et chaque partie coute 2€. Voici les résultats que d’un joueur :
var casino= ['DVR','VVR','RDV','VVV','RRV','DVD','VRV','RVD','DVD','VRV','VRV','DDD','DDV','VRR','DVV','DDR','RRR','DRR','DRR','DVR','DDD','VVD','DRR','RRD','RRV','RDD','VDV','VDV','VDR','DRV','RVV','VRV','RRD','DRR','DDD','DDV','RVV','VDD','DVR','DRD','VRD','VVV','VRR','DRV','RRV','VVR','DRR','DRV','DDR','VDD','VRD','VVV','RRR','RVR','VVD','RVD','DVD','RVD','VVD','DDR','VVD','RDR','VRD','RDD','VDV','DVR','RVV','RVV','RDV','RRV','RVD','DVD','DDD','RVV','DDR','VDV','VVD','VVD','RVR','VDD','DDD','RDV','RVD','DDR','VDD','RVV','VRV','DRR','RRD','RVV','RVD','VRR','VRV','DRR','DVV','DRV','VRD','VDV','VDV','DRV']
Écrire une fonction gain qui admet en paramètre la liste des résultats obtenus et donne en retour le montant gagné (ou perdu !).
casino= ['DVR','VVR','RDV','VVV','RRV','DVD','VRV','RVD','DVD','VRV','VRV','DDD','DDV','VRR','DVV','DDR','RRR','DRR','DRR','DVR','DDD','VVD','DRR','RRD','RRV','RDD','VDV','VDV','VDR','DRV','RVV','VRV','RRD','DRR','DDD','DDV','RVV','VDD','DVR','DRD','VRD','VVV','VRR','DRV','RRV','VVR','DRR','DRV','DDR','VDD','VRD','VVV','RRR','RVR','VVD','RVD','DVD','RVD','VVD','DDR','VVD','RDR','VRD','RDD','VDV','DVR','RVV','RVV','RDV','RRV','RVD','DVD','DDD','RVV','DDR','VDV','VVD','VVD','RVR','VDD','DDD','RDV','RVD','DDR','VDD','RVV','VRV','DRR','RRD','RVV','RVD','VRR','VRV','DRR','DVV','DRV','VRD','VDV','VDV','DRV'] def gain(parties): sortie=0 for p in parties: if p==p[0]*3: sortie+=50 sortie-=2 return sortie # gain(casino) donnera ici 300 def gain(parties): sortie=0 for p in parties: if p=="VVV" or p=="DDD" or p="RRR": sortie+=50 sortie-=2 return sortie # Version 2 def trois(partie): return partie==partie[0]*3 def gainv2(parties): return 50*len(list(filter(trois,parties)))-2*len(parties) # Version 3 def gainv3(parties): return 50*len([p for p in parties if p==p[0]*3])-2*len(parties)