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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:14:39+00:00 2026-05-23T17:14:39+00:00

I have an algorithm question related to XP levels in games: I have a

  • 0

I have an algorithm question related to XP levels in games:

I have a table that lists level numbers, and number of XPs in that level:

GameLevel    ExperiencePointsInLevel
1            30
2            70
3            160
4            250

For each player, I only maintain their total XP, not any level info.
Given a player’s total XP, how do I determine the following via an algorithm (I’m using C# & LINQ)?

  1. Current level of person
  2. Number points the person has in this level

For example, if a player has 110 XPs, the answer would be:

  1. Level 3
  2. 10 XPs; (110-30-70 = 10)

Any ideas?

Cheers,

Dean

  • 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-23T17:14:40+00:00Added an answer on May 23, 2026 at 5:14 pm

    If experience points in level is changed to represent the total XP a player needs to reach that level.

    Game Level    Experience Points
     1             0
     2             100
     3             200
     4             400
    

    A more functional approach with LINQ would be something like the following:

    var playerlevel = ExperiencePointsTable
        .Where(xpt => xpt.ExperiencePointsInLevel <= player.ExperiencePoints)
        .Select(xpt => xpt.GameLevel)
        .Max();
    

    I think this simplifies the solution and avoids having to generate arrays for a look up.

    Edit: fixed to check less than or equal to level.

    To find out how many xp the player has to get to the next level you can use a similiar LINQ query.

    var xpToNextLevel = (ExperiencePointsTable
        .Where(xpt => xpt.ExperiencePointsInLevel > player.ExperiencePoints)
        .Select(xpt => xpt.ExperiencePoints)
        .Min()) - player.ExperiencePoints;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two part question Best-Practice I have an algorithm that performs some
I have a language-agnostic question about an algorithm. This comes from a (probably simple)
I have probem / strange question, i got algorithm with few for loops and
I have an algorithm that generates strings based on a list of input words.
I have an algorithm that recursively makes change in the following manner: public static
I have this algorithm that I want to implement on VB6. Sub Main() dim
If I have an algorithm that takes n log n steps (e.g. heapsort), where
This is a design/algorithm question. Here's the outline of my scenario: I have a
I have two questions related to function objects and function pointers, Question : 1
Not sure whether this is the right place, but I have a question related

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.