Category Archives: Problem Solution

Sorting strings and Overriding std::sort comparison

At that post, I try to illustrate one of the use case of comparison overriding for std::sort on top of a simple problem. Our problem is as follows:

Write a method to sort an array of strings so that all the anagrams are next to each other.

Continue reading Sorting strings and Overriding std::sort comparison

Share

Project Euler - Problem 14

Here is one again a very intricate problem from Project Euler. It has no solution sheet as oppose to the other problems at the site. Therefore there is no consensus on the best solution.

Below is the problem: (I really suggest you to observe some of the example sequences. It has really interesting behaviours. 🙂 )

The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)
n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence: Continue reading Project Euler - Problem 14

Share

Project Euler - Problem 13

Here we have another qualified problem from Project Euler. You might want to work out the problem before see my solution.

The basic idea of my solution is to not use all the digits of the given numbers, instead extract the part of the each number that is necessary to sum up to conclude the first 10 digits of the result. I try to explain my approach at the top of the source code with my lacking MATH english. If you have any problem for that part please leave me a comment. Continue reading Project Euler - Problem 13

Share

Project Euler - Problem 12

As a 2 years researcher, I feel a bit rusty to code.  I search a good set of execises to hone my abilities again and I stumbled upon Project Euler. This site hosts increasing number of very well formed algorithmic problems and discussions. It ranges very basic problems to very high level ones, requiring profound knowledge and practice.

After that intro. I want to introduce one of the example question from Project Euler. NOTE THAT, IF YOU ALREADY KNOW THE SITE AND YOU TRY TO SOLVE THAT PROBLEM, DO NOT CHEAT YOURSELF.

Here is the problem statement we try to solve. Continue reading Project Euler - Problem 12

Share

de-importing a Python module with a simple function

Sometimes it is eluding to de-importing some of the python modules especially dwelling on IPython since you have changes something on the module and IPython does not see those  changes even you import the module again. The solution of such a problem is to de-import the module and import again. Here is the function that de-import the staff.

 

 

Share

Solution to Steam lunch problem in linux

If you installed Steam to your linux machine and see some lunch alerts complaining about such error;

You are missing the following 32-bit libraries, and Steam may not run: libGL.so.1

this is your solution time. Here is the solution.

This seem to happen on every 64bits OS. Full bug report here:

https://github.com/ValveSoftware/steam-for-linux/issues/321

Solution: Continue reading Solution to Steam lunch problem in linux

Share

Sql injection - hack this site "Realistic Mission 2"

Today it is the turn for the realistic mission 2 on hackthissite.org.

This mission is all about looking the home page source code. Finding the hidden link on page to directs you to admin page then use basic SQL injection to accomplish the mission.

SQL injection is about typing some malformed values to html forms to make some changes on the application database or get some data that the application owner does not expect us to see them or change. You can learn more about SQL injection from this link.

You need to be able to pass the mission after all the explanation and the reading from the above reference site. If you cannot, it means you need to work some more on hacking the sites. However for the lazy brains here I give the instructions as follows:

  1. Open the source file of the page.
  2. See the update.php link on the source. It is hidden on the visuals on the page.
  3. Find the hidden link and click on it to go to admin login page.
  4. Now use one of the tricks that you know about sql injection. I used this for both input  x' OR 1 = 1;

That's all 🙂

Share

PHP parameter trick on hackthissite.org "Realistic Mission 1"

After I pass the basic missions on hackthissite here is the first realistic mission solution of the hackhissite.org. You can see the mission from here.

It is really easy mission if you know about the value passing from the URL of the page to Continue reading PHP parameter trick on hackthissite.org "Realistic Mission 1"

Share

Topcoder SRM 246 Div1 250points question

My silly solution for that question:

Problem Statement

The problem statement contains the unicode symbols.
You are developing a new software calculator. A very important feature is the auto-placing of the ? value by one click. The only problem is that you don't know the required precision. That's why you decided to write a program that can return ? with any reasonable precision.
You are given an int precision. You should return the ? value with exactly precision digits after the decimal point. The last digit(s) should be rounded according to the standard rounding rules (less than five round down, more than or equal to five round up).
Definition Continue reading Topcoder SRM 246 Div1 250points question

Share