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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:52:12+00:00 2026-06-06T12:52:12+00:00

Hi I have a List<decimal> containing values between ]0;1]. I want to check if

  • 0

Hi I have a List<decimal> containing values between ]0;1].
I want to check if a total (or subtotal) of these values can equal 1 (or almost).

I can also use Linq functions to filter or manipulate the list.

Desired results:

  • A list containing {0.7, 0.7, 0.7} should return false;
  • A list containing {0.7, 0.3, 0.7} should return true;
  • A list containing {0.777777, 0.2, 0.1} should return false;
  • A list containing {0.33333, 0.33333, 0.33333} should return true;
  • A list containing {0.4, 0.5, 0.6, 0.3} should return true.

Obviously, I’ll want something with the lowest performance cost possible.

  • 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-06T12:52:13+00:00Added an answer on June 6, 2026 at 12:52 pm

    UPDATED — now doesn’t repetively sum
    try this

    bool isClose(IEnumerable<decimal> list, decimal epislon) {
      return isClose(Enumerable.Empty<decimal>(),list,0,list.Sum(),epislon);
    }
    // Define other methods and classes here
    bool isClose(IEnumerable<decimal> left,IEnumerable<decimal> right, decimal leftSum,decimal rightSum, decimal epsilon) {
      if (leftSum>=1-epsilon && leftSum<=1+epsilon) return true;
      if (leftSum>1+epsilon) return false;
      if (leftSum+right.Sum()< 1-epsilon) return false;
      if (!right.Any()) return false;
    
      for (var i=0;i<right.Count();i++) {
        var skip=right.Skip(i);
        var newItem=skip.First();
        if (isClose(left.Concat(skip.Take(1)),skip.Skip(1),leftSum+newItem,rightSum-newItem,epsilon)) return true;
      }
      return false;
    }
    
    
    
    isClose(new[] {0.7m,0.7m,0.7m},0.001m); // returns false
    isClose(new[] {0.7m,0.3m,0.7m},0.001m); //returns true
    isClose(new[] {0.777777m,0.2m,0.1m},0.001m); //returns false
    isClose(new[] {0.33333m,0.33333m,0.33333m},0.001m); //returns true
    

    EDIT 5th Test

    isClose(new[] {0.4m, 0.5m, 0.6m, 0.3m},0.001m); //returns true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of upwards 3,000 decimal values and for each one I
I have a list of float values and I want to print them with
let's say I have a list of decimals : List<decimal> values; and 2 function
I have a drop down list with decimal values. (formatted as string) <select id=SizeBox>
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,
I have list of words. I type in a word misspelled. Can I query
I have list of IPs: 238.51.208.96/28 238.51.209.180-199 238.51.209.100-109 238.51.213.2-254 ... How can I easily
I have a list that contain two colums which are type currency. I want
I have an ordered list, but I want to number is manually in a

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.