Programming , Tech, and stuff
Project Euler :: Problem 2 :: Haskell
Jan 2nd
This is the second tutorial on solving Project Euler problems using Haskell. Hope you will enjoy!
Problem Description:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Again, create a new text file and call it euler2.hs
First, we are required to make a function that computes the numbers of the Fibonnacci sequence. From the definition fib(x) = fib(x-1) + fib(x-2), we can easily code this in Haskell.
Here is how it would look:
fib :: Int -> Int fib 1 = 1 fib 2 = 1 fib x = fib(x-1) + fib(x-2)
Now on to test this function. Open up ghci, load the file, and type in “fib 30″, which asks for the 30th Fibonacci numbers. Actually, this will be quite slow, here are my results:
*Euler1> fib 30 832040 (2.46 secs, 172153128 bytes)
2.46 seconds to get the 30th number ? Way too slow. What is happening here, is that the computer has to do a lot of counting.
fib(30) = fib(29) + fib(28)
= [fib(28) + fib(27)] + [fib(27) + fib(26) ]
and so on and on, expanding the fib, until the problem is reduced to adding up a whole bunch of 1’s together, as the first two terms are 1’s.
So we need a solution, where we don’t need to recompute fib as many times, so you could call it a form of “caching”.
Here is my proposed solution:
fib :: Int -> Int fib n = table !! n where table = 0 : 1 : zipWith (+) table (tail table)
Whoa, what’s happening here ? We are creating a “table” of the Fibonacci numbers, and then simply calling the “!!” (value at index) function to get our desired number.
We define a table as a list, with first element 0, and second element 1, and with the rest of the list being computed recursively using “zipWith (+)”.
“zipWith” is a function that takes another function, such as the plus function (+), and two lists, and it “zips” them together using that operator.
For example, zipWith (+) [1,2,3] [1,1,1] will return the list [2,3,4].
Understanding the above revised fib function is best done by simply expanding the recursive bit. Here it is from my prompt.
*Euler1> zipWith (+) [0,1] [1] [1] *Euler1> zipWith (+) [0,1,1] [1,1] [1,2] *Euler1> zipWith (+) [0,1,1,2] [1,1,2] [1,2,3] *Euler1> zipWith (+) [0,1,1,2,3] [1,1,2,3] [1,2,3,5] *Euler1> zipWith (+) [0,1,1,2,3,5] [1,1,2,3,5] [1,2,3,5,8]
So we are seeing how the second parameter of zipWith is our desired sequence. Since Haskell implement lazy evaluation, it will stop computing the list as soon as it reaches “n”.
This approach is also much faster than the previous one. See for yourself!
*Euler1> fib 30 832040 (0.00 secs, 528596 bytes)
0.00 seconds is quite damn fast, and the solution uses up a lot less memory than the previous one!
Now using our knowledge of list comprehensions from the previous tutorial, and the function described above, we can solve problem 2 on Project Euler.
fib n = table !! n
where
table = 0 : 1 : zipWith (+) table (tail table)
euler2 = sum[x | x<- takeWhile (<4000000) (map fib [1..]), even(x)]
Line 5 has a couple new function we aren’t familiar with, such as takeWhile, map, and even.
“even” returns true when its parameter is even, and else it returns false. Hence, “even(x)” is one of our conditions for the list comprehension
Now the main part of this is
x <- takeWhile (<4000000) (map fib [1..])
Let’s look at “map” first. “Map” is a function which takes another function, and a list, and it applies that function to every element of the list.
For example, “map (+1) [1,2,3]” will return the list [2,3,4]. Think of this as a kind of a “foreach” loop you might know from imperative programming languages such as C,C++, Java, etc.
Now the “takeWhile” function. This function takes a predicate p, and a list, and returns a list such that all elements in the list meet the predicate p up to a certain point in the list, when we encounter a member that does not follow the predicate, and hence the list is trimmed.
For example, “takeWhile <5 [1,4,2,6,3]” will return [1,4,2] since the number 6 does not follow the predicate, it is NOT less than 5.
So finally, what we are saying, is : “x comes from infinite list of Fibonacci numbers, but trim this list so that we only have elements less than 4 million”
At the very end, use the predefined “sum” function we know from the previous tutorial, to get the sum of the list.
Here is script executing on my machine, very rapidly thanks to that method of computing fibonacci numbers!
*Euler> euler2 4613732 (0.00 secs, 524700 bytes)
Thanks for reading! This is only my second tutorial, so could you please post some comments about improving my style, explanations, etc.
Please come back for more tutorials!
Project Euler :: Problem 1 :: Haskell
Jan 2nd
This is the first tutorial about solving the problems on Project Euler.
I will be solving problem number 1, using the language Haskell, which is a functional programming language. If you come from a imperative programming language background (C++, C, Java, PHP), you might find Haskell a little ‘weird’ at first, but it is actually quite good for quickly solving some of the Project Euler problems!
Problem Description:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Solving this using Haskell is really simple. Open up ghci (Glasgow Haskell Compiler Interpreter), and then create somewhere a new file called euler1.hs, or whatever else you please.
Here is the code:
euler1 :: Int euler1 = sum [x | x <- [1..999], x `mod` 5 == 0 || x `mod` 3 == 0]
Line 1 says that the function euler1 is of type Int (think of it as just an integer), meaning it will return an integer after calling it. Line 2 is the meat of the function. Firstly, we are using the “list comprehension” syntax. Ignore “sum” for now, and just look at what’s inbetween the square brackets. Read it as “Return me a list of numbers x, where x comes from the finite list 1 to 999, and such that x is evenly divisible by 5 OR x is evenly divisible by 3.
Finally, use the predefined “sum” function. This function takes a list of numeric values, and returns the sum of them, which is precisely what we want.
As this is my very first tutorial like this, I would appreciate any comments, such as should I write more in-depth, less in-depth, explain some concepts more, explain how to set up Haskell on your system ?
Thanks, and please come back for the second tutorial for Project Euler!
Blog Update!
Jan 2nd
Hello to everyone in the New Year!
I have not updated this blog much recently, but I’m hoping for this to change this year!
The most popular post on my blog happened to be about cheating the Facebook game Tetris, hence I’m planning on putting up more videos and tutorials on various aspects of game hacking and programming.
Hence, some of the things I’m hoping to post include
- More tutorial about various aspects of game hacking
- Programming Tutorials
- Solving problems from Project Euler and posting my solutions
Hope you will enjoy the blog, and that you will check back often!
TUTORIAL – How to hack the administrator password in Windows XP!
May 20th
Have you ever wondered how to retrieve the Windows admin password for a computer? I’ll try to be brief and explain how to do just that without using too many advanced techniques. Of course they are many ways of doing this, so I’ll outline what I find easy. Remember that this is only for educational purposes, don’t try to hack someone’s computer (unless you really need to…). Also remember that you need physical access to the computer and some time. This tutorial is for Windows XP, not sure what else it will work for.
Tools you will need:
- 1GB or bigger USB key (or a CD and CD burner)
- Another any size USB key
- Any distribution of Linux. I used Pendrive Linux and a USB key but any combination will work.
- A computer on which to do all the installing and other work
- The computer for which you want to retrieve the password
- Rainbow table program Ophcrack
- A 700MB rainbow table (if the password is more complex you can use a bigger one. More on that a bit later)
I will write this tutorial as if you are using Pendrive Linux and USB, but you can easily port this method to CD/DVD or other variants. Below is the step by step tutorial on what exactly you need to do.
- Format your USB stick and set the filesystem to FAT32 while formattting. If the Linux won’t work with FAT32 try FAT.
- Download Pendrive Linux from HERE
- Using Winrar or another extraction program, extract the contents of Pendrive Linux into the root of your newly formatted USB drive
- When it finishes extracting, open the USB directory, and open the file makeboot.dat. This will make your USB drive bootable
- Your USB is ready for booting. Plug it into the computer you want to find the password for. Reboot/Start the computer
- When booting, make sure you select USB as the boot device. This is different for every BIOS, so you will just have to figure it out yourself. It’s sometimes F9, F8, or Del key, but it could by something else
- Wait for Pendrive linux to finish booting. You will arrive at the main screen.
- Open the window that allows you to see all storage devices on the computer. One of the them will be the hard drive, open it and navigate to C:\Windows\system32\config/
- Stick your other USB key into the computer, and copy all the files from this directory onto another directoy on your USB key. You can ignore the systemprofile directory, you don’t need it.
- Just to be safe and make sure you have the files you need, you can also copy the contents of C:\Windows\repair to another folder on your USB Key. This is just in case the other files don’t work, but most likely they will.
OK, you are now finished with copying the system files. What’s stored in the /config/ directory is all the passwords that are saved on the current computer, but they are encrypted, so we need a way of decrypting them. It would take forever to bruteforce, so what we will use is Rainbow Tables. These are pregenerated hashes, so what the computer will do is check the hashed version of the password from the file and compare it with the table. Of course, the bigger the table the more possibilities it has, and also it’s faster. Now it’s password-cracking time
- Download Ophcrack. It will allow us to crack the passwords.
- Download this 700MB rainbow table
- If the password is not alpha-numeric and contains special characters, you will need a bigger table. What I recommend is to download a 35 GB rainbow table from a torrent. The torrent is available from HERE. Make sure you download the right now, or otherwise that’s a lot of bandwidth wasted!
- Open up Opcrack and click the Tables icon. Point to your tables directory and click Install
- Click the Load icon, and select “Encrypted SAM”. Now point the tree view to the directory to which you dumped all the files from the system32\config directory
- Click crack and wait a little. If the passwords are complicated it might take longer. After it finishes, it presents you with all the passwords stored for this computer!
If it didn’t work, it might be because you are using the alphanumeric table and the password has non alphanumeric characters. If you Download the 35 GB table there is a much higher chance you will be able to crack the password! Also, it might be possible that the passwords are salted, in which I think you are out of luck, since a salt makes it really hard to decrypt the hash. Still, try the method and see what you come up with! You now have administrator access to the machine! I hope you enjoyed reading, and that you learned something. Also, remember that this is for educational purposes only, don’t use it for criminal activities! Also, sorry for no pics, maybe I”ll come up with some a bit later!
TI Basic Insulter Program
May 4th
Hmm, this is a weird program, but try it out
You input the name of the person, select the statement, and then this loops on the main screen. Press the “Enter” key to end.
DOWNLOAD:HERE
New Calculator Program
May 1st
Hey all. After I had to do about 50 different examples of these in my chemistry class, I decided to make small program in TI-Basic that solves for the pH of strong/weak acids and bases. To do the weak acids calculations, you need to provide the pKa or pKb, and the concentration of the acid/base. It uses the assumption that the concentration of H+, OH- in weak acids/bases tends to zero, and solves it without using the quadratic equation, therefore it’s not fully accurate, but its enough for the requirements of the IB. You need a calculator that supports TI-Basic, and means to transfer the program from the computer to the calculator.
Download: HERE
TUTORIAL – How to hack and cheat the Facebook game Tetris / Blockstar
Apr 5th
This is the second, and the better tutorial on how to hack and cheat in the game Facebook Tetris / Blockstar. Use this method instead of the other one posted some time ago.
EDIT: Facebook tetris has updated and this, as far as I know, does not work anymore. If you have any ideas, post in the comment section
Here is the video tutorial, and the shortened text version after the vid.
How to HACK / CHEAT the Facebook Game Tetris / Blockstar (v.2)
Step 1. Download Cheat Engine HERE.
Step 2. Go to Facebook Tetris.
Step 3. Install and run Cheat Engine. Click Attach Process in the top left, and select your browser (firefox.exe, iexplore.exe etc)
Step 4. Start playing tetris so that you get any score. Just get something like a 100 and click pause. Go to Cheat Engine. In the Value box, type in your score. For search type select Exact Value, and for Data Type select “Double”. Click First Scan. The program will now scan the memory, and it will find from 1-1000 addresses.
Step 5. What you want to do now is go back to Tetris, and unpause the game. Get another couple of points, and pause the game again. Go back to Cheat Engine, and change the value in the Value box to your current score. IMPORTANT: Click Next Scan, and not first scan. Cheat Engine should now 1 address in the address box. If you have more, perform this step again until you find only 1 address.
Step 6. When you do find the 1 address, double click on it. This will add it to the window in the bottom of Cheat Engine. Now Right Click on the address, and select “Set Hotkey” or something along the lines of hotkey. You will a window pop up. For the key combination, click anything, I chose the Del key but you can chose anything you want. For the dropdown menu, select “Increment”, and for the increment value, put 10000 (IMPORTANT, no more than 10000). Click OK
Step 7. Go back to Tetris and unpause the game. Start playing, and hit the Del key or whatever you set for your hotkey. Your score will now increase by 10000. Keep on clicking delete and playing at the same time. If you just mash the hotkey the game will find out you are cheating. So don’t overdo it, drop one block, hit the hotkey, and you should easily get >2 million points
If the above is not working for you then you did something wrong. Reread the tutorial and watch the video again.
I hope this was useful, and I’m still working on finding a method to allow you to input any score you want without consequences, so check back the site often.
No go on and get yourself a high Blockstar score!!!
TUTORIAL – How to cheat in Facebook Tetris – BlockStar Cheating
Mar 28th
WARNING: THIS IS THE OLD TUTORIAL. FOR THE NEWER, BETTER VERSION, PLEASE CLICK HERE
A friend of mine once asked me how he could cheat in the facebook game Tetris, or Blockstar, so I made a tutorial how to do it in a pretty interesting way. As I’m no programmer, (well, I hope to improve….), this method doesn’t involve modifying the memory, and is very limited. But hey, if you want to beat someone it can get u that extra 300k points. I also have a video tutorial if you rather watching than reading, here it goes.
How to Cheat in Facebook Tetris – For more amazing video clips, click here
Step 1: Install the plugin called ReloadEvery for Firefox.
Step 2: Go to www.youtube.com and while holding CTRL, click on like 40 videos you can see on the main page. This will open all of them in a new tab.
Step 3: Right Click anywhere on any page and go to ReloadEvery. Select 5s intervals, and click enable for all tabs. This will make firefox run very slowly, and since there will be so many instances of flash running already, facebook Tetris will be really slow
Step 4: Head over to Facebook Tetris and play it. It will be really slow now. It all matters on your computer. If it’s not slow enough, open more tabs, if it’s too slow, close some
I hope I’ll find a better method, like one where you can just set your score. For now, thanks for reading and stay tuned for more:)
Concentration Camps – Creative Video
Dec 5th
Hey. This is a short creative video portraying the horrors of the Holocaust and of the Nazi concentration camps during the Second World War. The video takes some quotes from Chapter 6 of a popular Holocaust novel, “If This is a Man”, by Primo Levi. The book is an autobiography and it shows what the main character went through from the time he was taken by the Germans to the time where the Russians come and save them. The video was done in After Effects with sound added in Premiere.
[Youtube:http://youtube.com/watch?v=c8CGsxL4UZE]
High Quality Version (130MB) (Right Click>Save As)> - HERE
Lower Quality Version (30MB) (Right Click>Save As)> - HERE
Should Schools Fingerprint Your Kids?
Nov 26th
Original Link – http://www.time.com/time/business/article/0,8599,1665119,00.html
Schools in certain states in America want to introduce fingerprint scanners in cafeterias to increase the lunch period. Using a 6 digit number was troublesome for a lot, and it shortened the lunch break which in some schools is only 20 minutes long. The schools’ idea is that by using a fingerprint scanner lines would move more quickly and the students could enjoy a longer lunch break.

The information system here is biometric devices and their use. At the beginning of the year, all the children would have their fingerprints scanned and put into the school system. Then, when in a lunch line, what a child would have to do is just put their index finger on a small biometric reader. The picture of the person and other personal data would be pulled from the school server and would pop up on the cashier’s screen.
This development raises the ethical issue of privacy. Even though schools have a legal binding with the government that they can’t release any personal data, a lot of parents are infuriated by this new idea. One of them commented it as being Orwellian, and that he believes that this data might be compromised by 3rd parties. While the schools believe that this would be a great improvement, parents are scared about their children and no one should blame them. No one would want the personal data of their children seen by people who were never meant to see it.
A possible area of impact of this is the education system along with the children in it. If the system is not implemented, the children will have to stand more time in a line, have less free time during lunch which could possibly demoralize them for the next class. The impact on the school would be such that everything would be much more simplified, and no one would have to go through the trouble if they forgot their student ID. They would have their fingerprint with them for payment. Other stakeholders apart from the children and schools include the parents who are terribly nervous about their children’s privacy, and the biometrics companies, for which schools are slowly becoming good customer of.