help with an algorithm
you have a number and 5 operations
1) add one to a digit ... 3 points 2) decrese one from a digit ... 2 points 3) interchange 2 digits ... 7 points 4)add a digit... 10 points 5) delet a digit... 12 points and you have to make the given number a palindrom with a total of minimal points for example if the number is 234 , decrese 4 by 2 and you get 232 and 4 points |
...ehrm..is this a school assignment? If so, sorry, kid. We dont do someone else's homework... :)
If not, expand a little. What programm language would you use? What is it for? More info...of course, if it's NOT an assignment... :) Thor |
While agreeing with Thor, even if it were a homework I would feel happy to point you at a Breadth First Search, which is what you probably want to be implementing :)
|
yeah, actually it's an example of a problem i might be geting at my exams and i've been trying but can't pull it trough...
it doesn't matter what language, but mously he asks us to work in C# |
Right - next time say so in your question, 'cos it helps people know what level of support they're working on :)
Do you have any code that you've written to attempt the problem? Have you tried implementing the BFS I linked you to? (there's informal pseudocode on the wikipedia article I linked you to, but I'm almost certain there's better pseudocode on the web, or I can explain it if you get stuck.) |
i can't quite imagine how to use BFS here, but thank's for trying to help me, i'll magenage i think ;)
|
Ahaha, okay. I'll explain anyway, to see if that makes it clearer...
Quote:
Code:
queue = [ (134,2) , (224,2) , (233,2) , (334,3) , ... , (24,12) , (23,13) ] Having written that, it does become obvious that you're going to get a really big queue really quickly. In that case, it might be better to use a depth limited search if space becomes an issue. Of course, if you have an alternative approach which you also have problems with then do post back and we'll try to help you :) Hope this helps, |
All times are GMT -5. The time now is 09:22 AM. |