Mathématiques

Question

Bonjour les amis , j'aurais besoin de votre aide silvouplait , c'est une énigme que je dois terminer , 2 nombres composés des mêmes chiffres ( ex : 459 + 495 ) qu'on additionne pour avoir une somme , la somme étant un nombre composé des 3 mêmes chiffres précédents ( 954 dans l'exemple ) , seuls 2 solutions existent , merci d'avance

1 Réponse

  • Réponse :

    Bonjour,

    Explications étape par étape

    Si on accepte 045 comme un nombre de 3 chiffres, alors il y a 3 solutions

    '-------------------------------------------------------------------------------------------

    la première que j'avais déjà cité: 459+495=954

    la 2è: 045+405=450

    la 3è: 054+450=504

    '-------------------------------------------------------------------------------------------

    const Faux=0=1

    const Vrai=not(Faux)

    dim shared chiffre(9) as integer

    dim i as integer,j as integer,k as integer

    SCREEN 0: WIDTH 150, 45: _FONT 16

    CLS

    for i=0 to 9

       for j=0 to 9

           if j<>i then

               for k=0 to 9

                   if k<>j and k<>j then

                       call Try(i,j,k)

                   end if

               next k

           end if

       next j

    next i

    end

    sub Try(p1 as integer,p2 as integer,p3 as integer)

    ' abc,acb,bac,bca,cab,cba

       call Try_1(p1,p2,p3,p1,p3,p2) ' abc , acb

       call Try_1(p1,p2,p3,p2,p1,p3) ' abc , bac

       call Try_1(p1,p2,p3,p2,p3,p1) ' abc , bca

       call Try_1(p1,p2,p3,p3,p1,p2) ' abc , cab

       call Try_1(p1,p2,p3,p3,p2,p1) ' abc , cba

       call Try_1(p1,p3,p2,p2,p1,p3) ' acb , bac

       call Try_1(p1,p3,p2,p2,p3,p1) ' acb , bca

       call Try_1(p1,p3,p2,p3,p1,p2) ' acb , cab

       call Try_1(p1,p3,p2,p3,p2,p1) ' acb , cba

       call Try_1(p2,p1,p3,p2,p3,p1) ' bac , bca

       call Try_1(p2,p1,p3,p3,p1,p2) ' bac , cab

       call Try_1(p2,p1,p3,p3,p2,p1) ' bac , cba

       call Try_1(p2,p3,p1,p3,p1,p2) ' bca , cab

       call Try_1(p2,p3,p1,p3,p2,p1) ' bca , cba

       call Try_1(p3,p1,p2,p3,p2,p1) ' cab , cba

    end sub

    sub Try_1(p1 as integer,p2 as integer,p3 as integer, p4 as integer, p5 as integer, p6 as integer)

       dim n1 as integer,n2 as integer,n3 as integer

           n1=p1*100+p2*10+p3

           n2=p4*100+p5*10+p6

           n3=n1+n2

           if n3<1000 then

               call InitChiffre

               call addChiffre(n1)

               call addChiffre(n2)

               call addChiffre(n3)

               if Test% then

                   print n1,n2,n3

               end if

           end if

    end sub

    sub InitChiffre

       dim i as integer

       for i=0 to 9

           chiffre(i)=0

       next i

    end sub

    sub AddChiffre( p as integer)

       dim i as integer, a as string ,n as integer

           a=ltrim$(str$(p))

           for i=1 to 3

               n=val(mid$(a,i,1))

               chiffre(n)=chiffre(n)+1

           next i

    end sub

    function Test%

       dim rep as integer,i as integer,nb as integer

           rep=Faux

           nb=0

           for i=0 to 9

               if chiffre(i)=3 then nb=nb+1

           next i

           if nb=3 then rep=Vrai

       Test%=rep

    end function

    '-------------------------------------------------------------------------------------------

Autres questions