tag:blogger.com,1999:blog-2933862468756896835.post6967903917763947761..comments2022-04-05T14:40:05.803-07:00Comments on J Engine Team: Hacker Cup - 3 Questions solved.Unknownnoreply@blogger.comBlogger15125tag:blogger.com,1999:blog-2933862468756896835.post-74190591015381631892011-01-10T15:10:36.597-08:002011-01-10T15:10:36.597-08:00What the hell have you been doing with first task?...What the hell have you been doing with first task? Here is whole solution:<br /><br />$nums=file('input.txt');<br />for ($i=1; $i<count($nums); ++$i) {<br /> $num=(int)$nums[$i];<br /> $total=0;<br /> <br /> for ($a=0; $a<=sqrt($num/2); ++$a) {<br /> $b=(int)sqrt($num-$a*$a);<br /> if ($a*$a+$b*$b==$num) ++$total;<br /> }<br /> <br /> echo $total."\n";<br />}Rok Kraljhttps://www.blogger.com/profile/09734685097778408336noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-4841569752042041492011-01-10T14:15:36.506-08:002011-01-10T14:15:36.506-08:00The double square one was easy. Mine took like a s...The double square one was easy. Mine took like a second to run. All i have is 2 nested loops. Outer one goes sqrt(n) and the inner one goes sqrt(n - sqrt(i)) where i is the location of the outer loop. if the squared addition of the inner and outer loop was less than n or equal to n i just break out of the loop so it doesn't check so many useless values.what?https://www.blogger.com/profile/02430404963295436277noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-83410275137258154682011-01-10T13:31:18.298-08:002011-01-10T13:31:18.298-08:00A C implementation of Double Squares takes approx ...A C implementation of Double Squares takes approx 0.01 seconds on the full input file. My approach was a little better than brute force.fresh new pagehttps://www.blogger.com/profile/05647430196923704024noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-14698608858101230222011-01-10T12:43:46.576-08:002011-01-10T12:43:46.576-08:00My time has expired :( but i can do works it. in P...My time has expired :( but i can do works it. in PHP.<br /><br />"Double Square solution"<br /><br />function is_perfect_square($value) {<br /> $sqrt = sqrt($value);<br /> return $sqrt==intval($sqrt);<br />}<br /><br />function t($v) {<br /> $sqrt = intval(sqrt($v));<br /> $cases = 0;<br /> for ($j = $sqrt; $j>=0; $j--){<br /> $num_a = pow($j, 2);<br /> $num_b = $v-$num_a;<br /> <br /> if (is_perfect_square($num_b)) {<br /> $cases++;<br /> }<br /> }<br /> <br /> return round($cases/2);<br />}<br /><br />print t(10);<br />print "\r\n";<br />print t(25);<br />print "\r\n";<br />print t(64);<br /><br /><br />Emmmanuel.Emmanuelhttps://www.blogger.com/profile/01356242364213867153noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-45768432666979038942011-01-10T10:36:06.953-08:002011-01-10T10:36:06.953-08:00and it displayed the result at once for Q1 and Q3....and it displayed the result at once for Q1 and Q3.<br />It takes about 20 sec for Q2.Kevin Wonghttps://www.blogger.com/profile/02431608772949981933noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-9960493038060479662011-01-10T10:34:54.023-08:002011-01-10T10:34:54.023-08:00I used java for all 3 questions.I used java for all 3 questions.Kevin Wonghttps://www.blogger.com/profile/02431608772949981933noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-51931957303645662482011-01-10T10:07:02.776-08:002011-01-10T10:07:02.776-08:0024hrs? its 6mins! ll24hrs? its 6mins! llAnonymoushttps://www.blogger.com/profile/14928014668463541825noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-87350329036919323602011-01-10T10:00:43.080-08:002011-01-10T10:00:43.080-08:00The exercise 1, with BruteForce is very slow in Ja...The exercise 1, with BruteForce is very slow in Java.. a dont know if is the same in ohter languages... but with BruteForce in my experience es very very slow.. 24 hrs is not sufficient.Lautaro Alfarohttps://www.blogger.com/profile/01206287010033899274noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-73188507010063597012011-01-10T09:03:46.171-08:002011-01-10T09:03:46.171-08:00You're right. And I even still can't solve...You're right. And I even still can't solve the other problems. Because I don't think my major will teach me much about this because I take Information systems as my major. Btw I just added you on Facebook Kevin. I'm sorry I'm mistakenly deleted the first comment(Using Excel) because of my cousin, he doesn't know how to use the laptop and he just tried to click what he wants and it's gone.Edyhttps://www.blogger.com/profile/03323521698736925672noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-37703506711057057612011-01-10T08:43:36.279-08:002011-01-10T08:43:36.279-08:00I agreed the approaches I used are not the most ef...I agreed the approaches I used are not the most efficient one. But they are more flexible to be modified to handle another similar questions.Kevin Wonghttps://www.blogger.com/profile/02431608772949981933noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-63576395100055441572011-01-10T08:25:39.741-08:002011-01-10T08:25:39.741-08:00This comment has been removed by the author.Edyhttps://www.blogger.com/profile/03323521698736925672noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-66576990078035814832011-01-09T19:59:56.299-08:002011-01-09T19:59:56.299-08:00Yea, Double Square can be easily bruteforced, and ...Yea, Double Square can be easily bruteforced, and still be fast.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-9428547520087562492011-01-09T19:56:00.158-08:002011-01-09T19:56:00.158-08:00actually, the exp() approach is much more efficien...actually, the exp() approach is much more efficient if you can derive a proper equation.<br /><br />and for the studious student question, simply use the tool that give you the correct result.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-45824640376829647502011-01-09T16:24:11.522-08:002011-01-09T16:24:11.522-08:00@Sam: Totally right. "Too hard to brute force...@Sam: Totally right. "Too hard to brute force." I don't think so. :PAnonymoushttps://www.blogger.com/profile/13746562022978027885noreply@blogger.comtag:blogger.com,1999:blog-2933862468756896835.post-40295176374519407442011-01-09T00:55:19.043-08:002011-01-09T00:55:19.043-08:00Seems like you took these problems too complicated...Seems like you took these problems too complicatedly. Problems 1 and 3 are bruteforcable.Anonymoushttps://www.blogger.com/profile/08216077455435639578noreply@blogger.com