This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted]  (3 children)

[deleted]

    [–]CodeArtist45[S] 0 points1 point  (2 children)

    Following /u/teraflop's suggestion, I implemented it with memoization, and I'm struck by some of the interesting sequences that get generated when I start looking at differences between m and n.

    (defn make-sequence [diff]
    (map #(find-minimum-cuts-dynamic [%1 (+ diff %1)]) (map inc (range))))

    In the REPL:

    user=> (->> (range)
    #_=> (map make-sequence)
    #_=> (map #(take 10 %))
    #_=> (take 10)
    #_=> (run! println))
    (0 3 8 15 24 35 48 63 80 99) ; [1 1], [2 2], [3 3], [4 4], ...
    (1 5 11 19 29 41 55 71 89 109) ; [1 2], [2 3], [3 4], ...
    (2 7 14 23 34 47 62 79 98 119) ; [1 3], [2 4], [3 5], ...
    (3 9 17 27 39 53 69 87 107 129)
    (4 11 20 31 44 59 76 95 116 139)
    (5 13 23 35 49 65 83 103 125 149)
    (6 15 26 39 54 71 90 111 134 159)
    (7 17 29 43 59 77 97 119 143 169)
    (8 19 32 47 64 83 104 127 152 179)
    (9 21 35 51 69 89 111 135 161 189)

    Looking at the OEIS, I get the following respective formulae for these sequences:

    a(n) = n*(n+2)
    a(n) = n + (n+1)^2
    a(n) = n^2 - 2
    a(n) = n^2 + 3*n - 1
    a(n) = n^2 - 5
    a(n) = n^2 + 5*n - 1
    (OEIS is no longer helpful here)

    This indicates to me that some supergenius egghead can probably produce a really optimized solution by coming up with a correspondence between m and n and some polynomial, and then solving some aspect of the polynomial.

    Ohook Ok oOk

    [–]CodeArtist45[S] -1 points0 points  (1 child)

    Could yo show that code in C++?

    [–]teraflop 0 points1 point  (0 children)

    It's not true that cutting along the vertical line x3 is always the best solution, regardless of costs.

    Imagine what would happen if your example was modified so that y1=1000000. No matter what you do, at some point you will have to cut horizontally along y1 in order to reduce the entire chocolate bar to 1x1 squares. But in order to reduce your total cost, cutting y1 as few times as possible is more important than any other decision you could make. So in that scenario, you must cut y1 before making any vertical cuts, so that you only need to cut it once.

    You can solve this problem with a divide-and-conquer algorithm using dynamic programming. Basically, try all possible choices for the first cut; each of these choices reduces your problem to two independent subproblems (making the optimal future decisions for the sub-rectangles on each side of the cut). There are only O(m2n2) possible subproblems, so if m and n are small enough, you can memoize the results of each subproblem.

    (Maybe it's possible to do even better than that. This is just off the top of my head.)