## Permanent Programming #6

Put your programming skills to the test in these challenges.

### Re: Permanent Programming #6

Hmm, the cropping, analyzing and getting the answer part is quite fast.
I am using imagemagick to do the rotations and I just can't think of anything to speed it up,
I suppose i could scale down the images before rotating, but this way i would loose image quality.
Chaosmaster
New User

Posts: 4
Joined: Wed Feb 25, 2009 3:58 am
Blog: View Blog (0)

### Re: Permanent Programming #6

Chaosmaster wrote:I wan't asking it it was possible in another language, I was asking if there's a way to speed it up in php.
Why would you need 36 rotations anyway? I only need 8, but it still takes too long.

It's actually 1 complete rotation but at 10 degrees for each row. If you set a crop for the row at the 12 O'clock position and then rotate the image 10 degrees it should line up the very next row into the crop that's been set. Doing this for each row will achieve 360 degrees. You could also disable javascript which would give you a few more seconds so you don't have to go through the 25% done, 50% done, etc....

Defience

Posts: 1281
Joined: Thu Jun 12, 2008 3:16 pm
Blog: View Blog (0)

### Re: Permanent Programming #6

Defience wrote:
Chaosmaster wrote:I wan't asking it it was possible in another language, I was asking if there's a way to speed it up in php.
Why would you need 36 rotations anyway? I only need 8, but it still takes too long.

It's actually 1 complete rotation but at 10 degrees for each row. If you set a crop for the row at the 12 O'clock position and then rotate the image 10 degrees it should line up the very next row into the crop that's been set. Doing this for each row will achieve 360 degrees. You could also disable javascript which would give you a few more seconds so you don't have to go through the 25% done, 50% done, etc....

I actually am using GD to draw the initial image. And then i need 8 rotations by 10 degrees and i can crop out the 12,3,6,9 o'clock positions, then i only need to rotate 3/4 of the chars by 90,180,270 degrees respectively (no interpolations are needed and the single chars are much smaller).
My problem only are the 8 major rotations which consume too much time.
Chaosmaster
New User

Posts: 4
Joined: Wed Feb 25, 2009 3:58 am
Blog: View Blog (0)

### Re: Permanent Programming #6

Edit:
Nevermind.. I found my issue and solved the problem
DrakierD
Experienced User

Posts: 51
Joined: Tue Apr 07, 2009 2:14 pm
Blog: View Blog (0)

### Re: Permanent Programming #6

Chaosmaster wrote:I actually am using GD to draw the initial image. And then i need 8 rotations by 10 degrees and i can crop out the 12,3,6,9 o'clock positions, then i only need to rotate 3/4 of the chars by 90,180,270 degrees respectively (no interpolations are needed and the single chars are much smaller).
My problem only are the 8 major rotations which consume too much time.

Using GD the same 8 rotations only take me about 6 seconds.
Baggins
New User

Posts: 1
Joined: Mon Jun 29, 2009 11:38 am
Blog: View Blog (0)

### Re: Permanent Programming #6

Just for the record.. For those saying it takes too much time to rotate the image, are you acually displaying the rotated image each time?

Nines
Poster

Posts: 191
Joined: Sun Apr 13, 2008 5:57 pm
Blog: View Blog (0)

### Re: Permanent Programming #6

I used the OCR approach with Java, n it worked pretty fast! however, it takes time to fine-tune the program! i did the pixel-counting first, but it didn't work well! the hardest part was finding the center, after realizing how hard it is to program it, i chose to find it manually. i would view the image, select the center, then the program would do the rest! it did 35 rotations n found the letters in less than 2 sec, what took time was selecting the correct center.
The philosopher and mathematician Bertrand Russell was asked, "If a false premise can imply any conclusion, use 1 = 2 to prove you're the Pope!" Russell replied, "The Pope and I are two, so we are one."

jpmut
New User

Posts: 22
Joined: Fri Jul 03, 2009 1:13 pm
Blog: View Blog (0)

### Re: Permanent Programming #6

Yes, its important to note that the center of the page is not the center of the spiral.

Defience

Posts: 1281
Joined: Thu Jun 12, 2008 3:16 pm
Blog: View Blog (0)

### Re: Permanent Programming #6

I solved it with Python without using the image, but the data embedded in the Javascript code.
The drawing method is the same as in programming 4, so I extracted the lines and arcs from the source, organized them in letters (this is the hardest part), and then identified the letter by line counting ("B" is 4 lines and 2 arcs, "8" is 2 arcs,...) and some other simple heuristics.
This method is a lot faster than using the picture (no rotations, mine runs in 0.1s) and has better accuracy (it can't mistake a B for an 8, but the OCR do). But it may be somewhat harder to find out which line belongs to which letter.
Drawing the lines between letters before starting to code may help you think some strategy.
Good luck everyone!
mancontr
New User

Posts: 1
Joined: Sat May 23, 2009 1:35 pm
Blog: View Blog (0)

Previous

### Who is online

Users browsing this forum: No registered users and 0 guests