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

  • SEARCH
  • Home
  • 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 9053925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:32:56+00:00 2026-06-16T13:32:56+00:00

I have a pre-defined 6 digit number, and an Entry model with a ‘number’

  • 0

I have a pre-defined 6 digit number, and an Entry model with a ‘number’ field (integer) that will have several thousand randomly generated entries per month. I need to find the best way to find the entry that is closest to the pre-defined 6 digit number.

It’s basically a competition. At the start of a the month a random 6 digit number is chosen and people get to enter and are given a random number – at the end of the month the person with the closest number wins.

Anyone know what is the most efficient way to find the closest entry?

I am using Postgres 9.2 and Rails 3.2.9

  • 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-06-16T13:32:57+00:00Added an answer on June 16, 2026 at 1:32 pm

    The winner will have absolute of the difference between the predefined_number and chosen_number closest to zero.

    Just have to query the picked numbers ordered by abs(predefined_number – chosen_number). The first on the list is the winner.

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

Sidebar

Related Questions

I could understood that Desktop applications in Java doesn't have a pre-defined relative path
I have an activity with a button that sends a pre-defined email. The button
I have a webpage that is a Search page. There are a few pre-defined
I need to launch a program that will at a users pre defined interval,
I have a pre-defined database that I want to map using Entity Framework 4
I have a UITextField that I want to display a pre-defined list of email
I have two models: User (pre-defined by Django) and UserProfile that are connected through
I have a User Model (pre-defined by Django) and a UserProfile model connected via
I have a PHP class that needs some pre-defined globals before the file is
I have an input field with some pre defined text explaining what it is

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.