5 thoughts on “O noua provocare pentru programatori”

  1. Emil [carco] Sirbu

    Da’ voi mai si munciti? 🙂

    Cum a zis Alexandra, cu variatiuni, se poate face si cu inmultire / impartire sau cu xor/^.

    Mai exista varianta directa in anumite limbaje (am uitat care au implementata atribuirea “paralela”), adica (a,b) = (b,a), in pehaspe, ceva similar (cu acelasi rezultat) ar fi: list($a,$b) = array($b,$a)

  2. andreea.paraschiv

    Good one, NoName!

    Si solutiile colegilor mei:
    1.
    $a = $a + $b
    $b = $a – $b
    $a = $a – $b

    2.
    $a = $a * $b;
    $b = $a / $b;
    $a = $a / $b;

    3.
    $a = $a ^ $b;
    $b = $a ^ $b;
    $a = $a ^ $b;

    4.
    list($a, $b) = array($b, $a);
    SAU
    list($a,$b) = array_reverse(array($a,$b));

    5.
    extract(array(‘a’=>$b, ‘b’=>$a));

    6.
    file_put_contents(‘a.txt’,$a);
    file_put_contents(‘b.txt’,$b);

    $a = file_get_contents(‘b.txt’);
    $b = file_get_contents(‘a.txt’);

    7.
    $a = $a <> strlen(decbin($b));
    $a = $b << (strlen(decbin($a)) – strlen(decbin($b))) ^ $a;

Leave a Comment

Your email address will not be published.

Scroll to Top