Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:03:07+00:00 2026-05-23T02:03:07+00:00

this has been bugging me for a while. Lets say you have a function

  • 0

this has been bugging me for a while.

Lets say you have a function f x y where x and y are integers and you know that f is strictly non-decreasing in its arguments,

i.e. f (x+1) y >= f x y and f x (y+1) >= f x y.

What would be the fastest way to find the largest f x y satisfying a property given that x and y are bounded.

I was thinking that this might be a variation of saddleback search and I was wondering if there was a name for this type of problem.

Also, more specifically I was wondering if there was a faster way to solve this problem if you knew that f was the multiplication operator.

Thanks!

Edit: Seeing the comments below, the property can be anything

Given a property g (where g takes a value and returns a boolean) I am simply looking for the largest f such that g(f) == True

For example, a naive implementation (in haskell) would be:

maximise :: (Int -> Int -> Int) -> (Int -> Bool) -> Int -> Int -> Int
maximise f g xLim yLim = head . filter g . reverse . sort $ results
    where results = [f x y | x <- [1..xLim], y <- [1..yLim]]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:03:08+00:00Added an answer on May 23, 2026 at 2:03 am

    Let’s draw an example grid for your problem to help think about it. Here’s an example plot of f for each x and y. It is monotone in each argument, which is an interesting constraint we might be able to do something clever with.

    +------- x --------->
    | 0  0  1  1  1  2 
    | 0  1  1  2  2  4
    y 1  1  3  4  6  6
    | 1  2  3  6  6  7
    | 7  7  7  7  7  7
    v
    

    Since we don’t know anything about the property, we can’t really do better than to list the values in the range of f in decreasing order. The question is how to do that efficiently.

    The first thing that comes to mind is to traverse it like a graph starting at the lower-right corner. Here is my attempt:

    import Data.Maybe (listToMaybe)
    
    maximise :: (Ord b, Num b) => (Int -> Int -> b) -> (b -> Bool) -> Int -> Int -> Maybe b
    maximise f p xLim yLim = 
        listToMaybe . filter p . map (negate . snd) $ 
           enumIncreasing measure successors (xLim,yLim)
      where
        measure (x,y) = negate $ f x y
        successors (x,y) = [ (x-1,y) | x > 0 ] ++ [ (x,y-1) | y > 0 ] ]
    

    The signature is not as general as it could be (Num should not be necessary, but I needed it to negate the measure function because enumIncreasing returns an increasing rather than a decreasing list — I could have also done it with a newtype wrapper).

    Using this function, we can find the largest odd number which can be written as a product of two numbers <= 100:

    ghci> maximise (*) odd 100 100
    Just 9801
    

    I wrote enumIncreasing using meldable-heap on hackage to solve this problem, but it is pretty general. You could tweak the above to add additional constraints on the domain, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been bugging me for a while. I have this ircbot that I
This is a question that has been bugging me for a while. I started
This problem has been bugging me for a while. I have to load a
This is a question that has been bugging me for a while and I
This has been bugging me for a while and have yet to find an
This has been bugging me for a while and I'm hoping that one of
This question has been bugging me for a while Is it usual to have
This is one thing that has been bugging me for a while about DDD.
This is something that has been bugging me for a while as it is
This one has been bugging me for a while now. Is there a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.