From: "Роман Ткаленко" Date: 2012-03-25T01:45:03+09:00 Subject: Ruby speed compared to C in a simple calculations. --e89a8f234bedcf331304bbffdc9f Content-Type: text/plain; charset=UTF-8 #works for 3.55 mins P = 295075153 o1 = 210205973 o2 = 22795300 (0 .. P).each do | i | if i ^ (i ^ o1) == o1 and ((i * 2 + 5) % P) ^ (((i ^ o1) * 3 + 7) % P) == o2 puts i break end end Code written in C gives me the solution in only 2 seconds. I suppose that it's called not by ruby slowlyness, but my shitty coding abilities. Cuold tou please tell me the weaknesse of the code? --e89a8f234bedcf331304bbffdc9f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
#works for 3.55 mins
P =3D 295075153
o1 =3D 210205= 973
o2 =3D 22795300
(0 .. P).each do | i |
= =C2=A0 =C2=A0 if i ^ (i ^ o1) =3D=3D o1 and ((i * 2 + 5) % P) ^ (((i ^ o1) = * 3 + 7) % P) =3D=3D o2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 puts i
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 break
=C2=A0 =C2=A0 end
end
Code written = in C gives me the solution in only 2 seconds. I suppose that it's calle= d not by ruby slowlyness, but my shitty coding abilities. Cuold tou please = tell me the weaknesse of the code?
--e89a8f234bedcf331304bbffdc9f--