Re: Concours de rentrée 2019 - défi langage historique
Posté: 14 Nov 2019, 17:53
Je ne l'ai plus et je ne sais pas si ce serai une bonne idée de le refaire.
News, programmes, tutoriaux, forum sur les calculatrices TI !
https://tiplanet.org/forum/
edgar13 a écrit:Je ne l'ai plus et je ne sais pas si ce serai une bonne idée de le refaire.
Azerpogba a écrit:edgar13 a écrit:Je ne l'ai plus et je ne sais pas si ce serai une bonne idée de le refaire.
Ca veux dire quoi ça??
qu'il etait pas bien??
edgar13 a écrit:Azerpogba a écrit:edgar13 a écrit:Je ne l'ai plus et je ne sais pas si ce serai une bonne idée de le refaire.
Ca veux dire quoi ça??
qu'il etait pas bien??
Non qu'il était long et moche.
Azerpogba a écrit:....QQn d'autre en a un?
ggauny@live.fr a écrit:peut-on avoir les programmes des défis en HPPPL et non uniquement en Hpapp ?
atmu=run(100,False)
variercompo()
from math import log10,sqrt
from random import randint
import csv
from math import log10,sqrt
from tkinter import *
def color(r, g, b):
return '#%02x%02x%02x' % (r, g, b)
def fill_rect(x, y, w, h, color):
y += 18
canvas.create_rectangle(x, y, x + w, y + h, fill=color, outline='')
def draw_string(text, x, y, fg=color(0,0,0), bg=None):
y += 18
t = canvas.create_text(x, y, anchor=NW, text=text, fill=fg)
if bg is not None:
r = canvas.create_rectangle(canvas.bbox(t), fill=bg, outline='')
canvas.tag_lower(r, t)
def clear():
canvas.delete('all')
canvas.create_rectangle(0, 18, 320, 240, fill=color(255, 255, 255), outline='')
canvas.create_rectangle(0, 0, 320, 18, fill=color(255, 183, 52), outline='')
def init():
global atmu,n,j,s,ma,mb,mc,w,fp,fm
atmu,n,j,s,w,fp,fm=[],9,0,0,5,0,0
ma,mb,mc=[[0]*n for k in range(n)],[[0]*n for k in range(n)],[[0]*n for k in range(n)]
def dr():
global s,j,w
sw=320
d,h=min(sw//n,221//n),(color(0,0,0),color(255,255,255))
b=sw-1-n*d
clear()
for i in range(0,n*d+1,d):
fill_rect(b,i,n*d,1,h[0])
fill_rect(b+i,0,1,n*d,h[0])
for y in range(0,n):
for x in range(0,n):
t=255-(255*abs(ma[y][x])//w)
fill_rect(b+x*d+1,y*d+1,d-1,d-1,ma[y][x]<0 and color(t,t,255) or ma[y][x]>0 and color(255,t,t) or h[1])
draw_string(" ATLEMU ",1,1,color(255,255,0),color(127,127,127))
draw_string("Muen\ndo(-1,c,l)",0,19,color(0,0,255),h[1])
draw_string("Atlante\ndo(1,c,l)",0,53,color(255,0,0),h[1])
draw_string("Passer\ndo(0)",0,87,color(255,0,255),h[1])
draw_string("Recommencer\ninit()",0,121,color(0,0,0),h[1])
draw_string("An: "+str(j)+"\nScore:\n"+str(s)[:10],0,n*d-49)
def do(*ar):
global j,gp,gm,fp,fm,s
j,k,v,(sc,sl)=j+1,ar[0],(len(ar)%2) or ar[len(ar)-1],(len(ar)>=3) and (ar[1],ar[2]) or (0,0)
k,gp,gm=k and k//abs(k),fp,fm
for y in range(n):mb[y]=mc[y].copy()
for y in range(n):
for x in range(n):
o,ma[y][x]=ma[y][x],ma[y][x]+w*(ma[y][x]==0 and x==sc and y==sl)*((k>0)-(k<0))+(ma[y][x]<=0 and (x-sc or y-sl or k==0) and mb[y][x]//10==3)*((ma[y][x]==0)*w-ma[y][x]*(not(not(ma[y][x]))))-(ma[y][x]>=0 and (x-sc or y-sl or k==0) and mb[y][x]-10*(mb[y][x]//10)==3)*((ma[y][x]==0)*w+ma[y][x]*(not(not(ma[y][x]))))
if o and ma[y][x]==o:
ls=(-1,w>abs(ma[y][x]))
ma[y][x]=ma[y][x]+(ma[y][x]>0)*ls[mb[y][x]//10==3 or mb[y][x]//10==4]-(ma[y][x]<0)*ls[mb[y][x]-10*(mb[y][x]//10)==3 or mb[y][x]-10*(mb[y][x]//10)==2]
if ma[y][x]-o:
fp,fm=fp+(ma[y][x]>0 and not(o))-(o>0 and not(ma[y][x])),fm+(ma[y][x]<0 and not(o))-(o<0 and not(ma[y][x]))
if not(o) and ma[y][x] or o and not(ma[y][x]):
for dl in range(-1,2):
for dc in range(-1,2):
if dl or dc:mc[y+dl+(dl<0 and y==0)*n-(dl>0 and y==n-1)*n][x+dc+(dc<0 and x==0)*n-(dc>0 and x==n-1)*n]+=(ma[y][x]<0)-(o<0 and 0==ma[y][x])+10*((ma[y][x]>0)-(o>0 and 0==ma[y][x]))
if max(fp,gp)*max(fm,gm):s=s/(1+abs(k)*log10(sqrt(j)))+fp*fm*min(fp,gp)*min(fm,gm)/max(fp,gp)/max(fm,gm)
atmu.append((sc*k+k,sl*k+k))
if v:
dr()
# print("Bon score ? Envoie la liste\n'atmu' a info@tiplanet.org")
return s
def st(l,v=True):
init()
for p in l:s=do((p[0]>0)-(p[0]<0),abs(p[0])-1,abs(p[1])-1,v)
dr()
return s
# ************************************************************************************
# **
# ** SUB PERSO
# **
# ************************************************************************************
rep="D:/_Datas/_Datas PERSO/Python-atlemu"
def sauvecsv(v,nom=rep + "/sansnom.csv",m="w"):
#sauvegarde une matrice p en csv
#with open("L:/_Datas/11 - Arnaud/Python - DEFI/table.csv", "w") as f_write:
with open(nom, m) as f_write:
writer = csv.writer(f_write,delimiter=";")
writer.writerow(v) # writer.writerows(v) si plusieurs lignes
return
def sauvetxt(v,nom=rep + "/sansnom.txt"):
fichier = open(nom,"w")
fichier.write(str(v))
fichier.close()
return
def run(nbboucles,sauvechaquetirage=False):
global atmumax
smax=0
boucle=0
moyscore=0
while boucle<nbboucles or nbboucles==0:
boucle+=1
init()
if boucle%100==0:print("run "+str(boucle)+" Max="+str(smax))
carrex= randint(2,4)
carrey= randint(2,4)
zonex=9-carrex
zoney=9-carrey
x1=randint(1,zonex)
y1=randint(1,zoney)
x2=randint(1,zonex)
y2=randint(1,zoney)
nbhabitants=12 #randint(3,5)
for k in range(nbhabitants-1): #nombre d'habitants par couleur
# l=randint(0,carre)
# m=randint(0,carre)
do(1,x1+randint(0,carrex),y1+randint(0,carrey) )
do(-1,x2+randint(0,carrex),y2+randint(0,carrey) )
# nx1=x1+randint(0,carrex)
# ny1=y1+randint(0,carrey)
# if ma[nx1-1][ny1-1]!=0:
# s=do(0)
# else:
# do(1,nx1,ny1)
#
# nx2=x2+randint(0,carrex)
# ny2=y2+randint(0,carrey)
# if ma[nx2-1][ny2-1]!=0:
# s=do(0)
# else:
# do(-1,nx2,ny2)
s=do(0)
s=do(0)
do(1,x1+randint(0,carrex),y1+randint(0,carrey) )
do(-1,x2+randint(0,carrex),y2+randint(0,carrey) )
while j<42:
s=do(0)
moyscore+=s
if s>smax:
smax=s
atmumax=list(atmu)
print("---")
print("#"+str(smax))
print("#"+str(atmumax))
print("---")
print("Carre X="+str(carrex))
print("Carre Y="+str(carrey))
print("Nb habitants="+str(nbhabitants))
print("---")
if not(sauvechaquetirage):
sauvertirage(smax,nbhabitants,0,carrex,carrey,atmumax)
if sauvechaquetirage:
sauvertirage(s,nbhabitants,0,carrex,carrey,atmu)
print("#"+str(smax))
print("#st("+str(atmumax)+",False)")
print("#"+str(smax))
moyscore=moyscore/nbboucles
print("#"+str(moyscore))
st(atmumax,False)
return atmumax
def sauvertirage(score,nbhabitants,surface,carrex,carrey,compo):
if surface==0:
surface=carrex*carrey
e=[]
e.append(score)
e.append(nbhabitants)
e.append(surface)
e.append(carrex)
e.append(carrey)
e.append(compo)
sauvecsv(e,rep+"/stat-tirages.csv","a")
return
def variercompo():
compo=[(7, 2), (-4, -7), (8, 2), (-2, -7), (7, 4), (-3, -7), (0, 0), (-4, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
smax=0
atmumax=[]
s=st(compo,False)
smax=s
atmumax=list(atmu)
for k in range(len(compo)):
print("k="+str(k))
hab=compo[k]
x=hab[0]
y=hab[1]
if x!=0:
#on fait varier les positions
plage=[-1,0,1]
for deltax in plage:
nx=x+deltax
for deltay in plage:
ny=y+deltay
#on a la nouvelle position nx,ny
ncompo=list(compo)
print(ncompo[k])
ncompo[k][0]=nx
ncompo[k][1]=ny
#on teste la compo
s=st(ncompo,False)
#
if s>smax:
smax=s
atmumax=list(atmu)
print("---")
print("#"+str(smax))
print("#"+str(atmumax))
print("---")
print("Carre X="+str(carrex))
print("Carre Y="+str(carrey))
print("Nb habitants="+str(nbhabitants))
print("---")
return
master = Tk()
master.resizable(0, 0)
canvas = Canvas(master, width=320, height=240)
canvas.pack()
sauvertirage("Score","nb habitants","surface","carre X","carre Y","Sequence")
init()
dr()
variercompo()
#atmu=run(100,False)
#sauvetxt(atmu,rep+"/CompoAtmu.txt")
#affichage
if __name__== "__main__":master.mainloop()
#st([(7, 2), (-4, -7), (8, 2), (-2, -7), (7, 4), (-3, -7), (0, 0), (-4, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],False)
#18425.217793183947
#st([(7, 2), (-4, -7), (8, 2), (-2, -7), (7, 4), (-3, -7), (0, 0), (-4, -9), (0, 0), (-3, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],False)
#18390.75048739328
#18381.309236990124
#[(7, 2), (-4, -7), (8, 2), (-2, -7), (7, 4), (-3, -7), (8, 2), (-4, -9), (7, 4), (-3, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#18381.309236990124
#18168.450679791244
#[(9, 7), (-4, -8), (9, 8), (-4, -7), (7, 8), (-2, -8), (9, 8), (-4, -8), (8, 6), (-4, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#18168.450679791244
#18049.830151963542
#[(9, 3), (-5, -3), (7, 3), (-5, -2), (9, 2), (-5, -4), (7, 2), (-3, -4), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#18049.830151963542
#18035.99025478949
#[(3, 3), (-8, -7), (2, 3), (-7, -6), (3, 4), (-9, -6), (4, 3), (-7, -7), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#18035.99025478949
#18003.837819596458
#[(3, 3), (-4, -8), (3, 4), (-4, -7), (5, 3), (-2, -8), (2, 2), (-5, -9), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#18003.837819596458
#17841.546235752416
#[(4, 4), (-8, -2), (4, 5), (-8, -3), (2, 5), (-6, -3), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#17781.124608967286
#[(4, 7), (-8, -6), (3, 6), (-9, -7), (5, 6), (-7, -7), (4, 7), (-8, -6), (3, 5), (-9, -8), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#17605.76772889996
#[(2, 9), (-7, -6), (3, 9), (-7, -7), (2, 8), (-5, -7), (4, 7), (-5, -7), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
#17425
#[(4, 5), (-8, -3), (4, 4), (-8, -4), (4, 3), (-6, -4), (3, 3), (-6, -3), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
Shift
Programpermet de consulter et éditer le code de l'appli ATLEMU.
main(liste)
pour lancer l'interface graphique de la simulation, avec une liste vide en paramètre pour une nouvelle simulation.