Dynamic programming - decreasing number

2

The challenge

You are given an integer n, and you have to use these operations to make it 1.

  1. Divide it by 3.

  2. Divide by 2.

  3. Subtract 1.

Examples:

Input    Output
  1        0 (Its already 1, guys)
  5        3 (3->2->2 or 3->3->1)
 10        3 (3->1->1)
255        10(3->3->3->1->1->2->2->3->1->2)

user65134

Posted 2017-02-09T15:03:38.373

Reputation: 121

Question was closed 2017-02-09T15:07:28.570

4

Please expand on allowed input, expected output, and what the winning criterion is. Is the division floored to an integer? Consider using the Sandbox for Proposed Challenges to receive feedback for a challenge idea.

– mbomb007 – 2017-02-09T15:06:47.567

What if my language of choice only supports integer arithmetics ? Can I still apply ? – zeppelin – 2017-02-09T15:07:34.107

@zeppelin sure you can – user65134 – 2017-02-09T15:08:22.390

@mbomb007 is 3 enough? Yes it is floored – user65134 – 2017-02-09T15:08:32.750

What is the winning criterion? As I said before, try reading the guide in the Sandbox and visit our FAQ, where there is a template for challenges and things to consider when creating a challenge and What makes winning criteria “objective”?.

– mbomb007 – 2017-02-09T15:12:57.493

1Personally, I'd recommend answering challenges before asking. That way, you'll see plenty of examples of great questions. Feel free to look at other questions to see how specific and detailed they are. – mbomb007 – 2017-02-09T15:14:46.233

Also, you say it's floor division, but then 5 -> 1 because 5/3 = 1, so your example is wrong. Also, subtraction is never needed, the minimal number of moves can be reached with only division by 2 or 3. – mbomb007 – 2017-02-09T15:58:47.940

Going by the three examples it looks like one may only divide when it gives an integer result (thus from ten one could start with a divide by two, but then it takes 3 steps from five, whereas if one starts by subtracting one, one may then divide by three twice from nine to get to one in a total of three operations). – Jonathan Allan – 2017-02-09T16:09:37.607

@JonathanAllan "Yes it is floored" http://codegolf.stackexchange.com/questions/109602/dynamic-programming-decreasing-number#comment266880_109602

– mbomb007 – 2017-02-09T16:12:33.657

1@mbomb007 I know, I saw that, but it does not fit with the examples! 5 divided by three floored is one. – Jonathan Allan – 2017-02-09T16:14:16.613

Does the result need to reach 1 in fewest operations possible, or is any solution finding 1 acceptable? – steenbergh – 2017-02-09T16:14:48.533

@JonathanAllan And hence why it is closed. Anyway, I found a 54-byte solution for the one with floored division. Related OEIS

– mbomb007 – 2017-02-09T16:19:38.553

I think I might be able to fix it. – Matthew Roh – 2017-02-10T07:06:32.630

No answers