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 8185813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:58:43+00:00 2026-06-07T01:58:43+00:00

so i got a ranking system that is basically a pyramid: 01 02 03

  • 0

so i got a ranking system that is basically a pyramid:

     01
    02 03
   04 05 06
  07 08 09 10
 11 12 13 14 15
16 17 18 19 20 21

Now every person can challenge every person to the left in the same row and to the right in the row above.

So for example 18 can challange 13-17
Basically you can challenge further up the ladder the lower you are.

Any Idea on how to solve this as a function? When thinking about the problem i just come up with some pretty complex calculations for the range by calculating the layer of the pyramid through counting down but i’m sure there has to be an easy solution.

Some more exmaples for the ranges:
02 – 01
03 – 02
04 – 02-03
05 – 03-04
06 – 04-05
07 – 04-06
08 – 05-07
11 – 07-10
17 – 12-16

Btw, even though it might look like homework, i can assure you i’m already out of school for some years now. This is actually going into an archery ladder system i’m trying to digitize for the local archery club 🙂

  • 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-07T01:58:46+00:00Added an answer on June 7, 2026 at 1:58 am

    For player x it is easy to see that the upper value in the range is always x - 1. The tricky part is to find the lower value.

    First notice that the number of people you can challenge is equal to the number of people in the row above you. You may find it easier to understand why this is true by looking at the following diagram where each oval contains exactly one of the people player 13 can challenge (9, 10, 11, 12):

    showing relationship to triangular numbers

    There are four people that number 13 can challenge, and four people in the row above player 13.


    So we need to find the number of people in the row above x. Notice that the total number of people above x is a triangular number T(n) for some n. And the value of n is the number of people in the row above x.

    To find triangular numbers you may find this formula useful:

    T(n) = n * (n+1) / 2
    

    The problem is to find the largest n such that T(n) < x.

    You could use a loop to run through all possible values of n, calculating T(n) until it exceeds x. This would work, it’s simple, and it would almost certainly be fast enough for your purposes.

    But you can also get there more directly by using the inverse of the above quadratic equation:

    inverse of triangulare number formula

    The only adjustment that is needed is to first subtract 1 from x because we want the triangular number strictly smaller than x. Without that adjustment it would give the current row for exact triangular numbers, instead of the row above.

    Using this formula and translating it to PHP we can get the result directly for any x:

    $n = floor((sqrt(1 + 8 * ($x - 1)) - 1) / 2);
    $lower = $x - $n;
    $upper = $x - 1;
    

    Results:

    2: 1 - 1
    3: 2 - 2
    4: 2 - 3
    5: 3 - 4
    6: 4 - 5
    7: 4 - 6
    8: 5 - 7
    9: 6 - 8
    10: 7 - 9
    11: 7 - 10
    12: 8 - 11
    13: 9 - 12
    14: 10 - 13
    15: 11 - 14
    16: 11 - 15
    17: 12 - 16
    18: 13 - 17
    19: 14 - 18
    20: 15 - 19
    21: 16 - 20
    

    See it working online: ideone

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

Sidebar

Related Questions

Got a seg fault from my memcpy that gdb can't give me anything else
I've got a MySQL statement that selects a name and also makes a ranking.
Now that I got my head wrapped around the 'C' language to a point
got a problem, can't get my head around this jquery and would appreciate your
got some problems. Built an applet that has to be used step-by-step. After each
I've got a mySQL statement that selects some data and also ranks. I want
Got my TextView in the xml: <TextView android:id=@+id/myTextView android:layout_width=wrap_content android:layout_height=wrap_content android:layout_gravity=center android:layout_weight=1 android:gravity=left android:text=TextView/>
Current, I've got a stored procedure that has a main goal of doing a
Got a mobile site with a jquery mobile menu (nested-list). Every item in the
Got this really stupid problem: Can find the proper name for the android folder

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.