Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Efficient method to slice an int64 to parts ?

Posted on 2011-09-23
2
383 Views
Last Modified: 2016-09-29
i have a big number that i want to slice into 10 parts for example, each part will be almost equel...

now don't reply with "just devide it by 10", no that's not the point..

so lets say for example i want to devide the number 3,480,352 into 10 parts, it will look like this:

0. 339.9 (kb)
1. 361.1 (kb)
2. 357.2 (kb)
3. 353.9 (kb)
4. 353.9 (kb)
5. 350.4 (kb)
6. 350.4 (kb)
7. 310.4 (kb)
8. 260.2 (kb)
9. 361.1 (kb)

the example i showed was taken from a rea-world scenario.
0
Comment
Question by:rotem156
2 Comments
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 250 total points
ID: 36586463
Since you don't specify a programming language I'll use pseudo-code. I'll use rand(0,10) to mean a random integer between 0 and 10.

integer num = 3480352;
integer random;
integer array[10];
integer max_rand;

for i from 1 to 9 //do this for the first 9 parts
  max_rand = floor(num/30); //floor means round down, the 30 should be set to whatever you want
  random = rand(0,max_rand*2) - max_rand; //This generates a number from -max_rand to max_rand
  array[i] = num/(10-i+1) + random; //divide by 10 the first time, then by 9, then 8 etc
  num = num - array[i]; Take it out of the old number
end for
array[10] = num; //put the rest in the last one

Open in new window

0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 250 total points
ID: 36586472
>>i f i devide by 2, it will look like this:

>>0. 346.6 (kb)
>>1. 2.96 (mb)

why?

for one, those aren't close to being equal
and even if they were closer,  why isn't dividing evenly by 2 or 10 acceptable?

are you just looking for semi-random divisions?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned. This example is designed t…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question