Solved

Efficient method to slice an int64 to parts ?

Posted on 2011-09-23
2
380 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
Comment Utility
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 73

Assisted Solution

by:sdstuber
sdstuber earned 250 total points
Comment Utility
>>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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
directed graph traversal 7 69
NLP in .Net for Categorization 34 295
weak ssl ciphers 2 79
scoresClump  challenge 31 107
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…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now