Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Density of selected values within file

Posted on 2011-02-14
7
Medium Priority
?
365 Views
Last Modified: 2012-06-27
Hello experts!

Please have a look at the numbers attached to the code.


First number is amount of indexes.
The second number is index itself.
Indexes are valued from 0..7.

So for example:

19, 4

means that we have nineteen indexes with value of 4.


My task is to analyze the density of these indexes.
These density types should be calculated and taken into consideration:
(I want to find index values and position borders they appear)

- single indexes
- couples of indexes
- triples of indexes


So if we look for single indexes we should find out that we have high density of
indexes = 4 (look at line no.2) and indexes = 0 (look at line no. 6).

If we look for triples of indexes we should find out that we have high density
of indexes 0, 1, 7 (from line no. 5 to 66).

Search for couples will be similar as for triples.


How can I make such analysis in a smart way?
Is there any mathematical tool to do such things?


Thank you

panJames


1, 5
19, 4
2, 6
1, 2
1, 1
18, 0
1, 1
1, 0
1, 7
3, 0
1, 1
1, 7
1, 0
1, 1
1, 7
1, 0
1, 1
1, 7
5, 0
1, 1
1, 0
1, 7
2, 0
1, 1
1, 7
1, 1
2, 0
1, 7
5, 0
1, 1
1, 7
1, 0
1, 1
2, 0
1, 7
2, 0
1, 1
1, 7
2, 0
1, 1
2, 0
1, 7
1, 0
1, 1
1, 0
1, 7
1, 1
1, 7
3, 0
1, 1
1, 7
1, 1
4, 0
1, 7
1, 1
1, 7
1, 1
1, 7
2, 0
1, 1
1, 7
4, 0
1, 1
1, 7
2, 0
1, 7
1, 5
2, 6
1, 5
2, 6

Open in new window

0
Comment
Question by:panJames
[X]
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
7 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 34888668
If you have Microsoft Access, you can create a query that will group and count the number of indexes. Using the data provide, I came up with the following results:

22,0
20,1
1,2
1,4
3,5
3,6
20,7

This took all of 5 minutes. If this is what you're looking for, I can provide you with some guidance on how to create the table and query.

Flyster
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34889679
If you don't have Access, you most likely have Excel (or OpenOffice or something that does the same thing). These programs will open the file perfectly (they are built to understand the commas as separating cells). They can do quite a bit of analysis with built-in functions and you can write scripts to do anything that computers are capable of doing.

In a string like 0,1,7,0,1,7,0,1,7, 0. Should the 0,1,7 and 1,7,0 triples both be counted (3 each)?
Does 19,4 indicate a bunch of triples of 4?
The required analysis is not yet clear.
0
 

Author Comment

by:panJames
ID: 34895179
Flyster: Thank you for your answer.

What I need here is algorithm to solve problem.


panJames
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34897614
Is 4,0 essentially the same as 0,0,0,0? So do you need to look at triples like 0,0,0? We need more specifications before we can help with algorithms.

Also, what platform are you working with? C++, Excel, VBScript, pen and paper, etc
0
 

Author Comment

by:panJames
ID: 34917414
@TommySzalapski:

"Is 4,0 essentially the same as 0,0,0,0?" <- not really.

I should explain it better.

Values attached describe another file with values inside [values: 0..7]

First file:

0
0
0
0
1
1
2
2
2

it means that in the second file we get:

4, 0
2, 1
3, 2

so the second file is like a summary of the first file.

Algorithm will be using C++

panJames
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34936901
panJames,

Copy the list into Excel and use Data/Text to columns to split the data into 2 columns - Number of Indexes and Index. Having done that set up a small table listing the indexes and use this formula to summarise the results:

=SUMIF($B$1:$B$70,D2,$A$1:$A$70)

It's in the atteched Excel file.

Patrick
panJames-01.xls
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 34937402
Single indexes is easy. You just sum them all.
In C++ I would use an array like
int indexes[8];
for(int i = 0; i < 8; ++i)
  indexes[8] = 0;

Then just loop through the input and if you see 4, 3 do
indexes[3] += 4
etc.
But this is the easy part

For triples you need to look at each index individually. I would use an array of arrays of arrays (actually I would call it a tree). So if you see 4, 3 you'll need to send all 4 of the 3s one at a time into your function.
You would need to track what the last two were. If I was implementing it for real, I would use a circular queue, but if you only need to deal with up to triples I would just do it the easy way.
Something like this:
(note: set up constants where they should be etc)
const int INDEXES = 8;//You really should use a constant for the 8

int history[3];
int triples[INDEXES][INDEXES][INDEXES];
memset(triples, 0, INDEXES*INDEXES*INDEXES*sizeof(int)); //set all to 0

//Write your code to read the values in.
//Get the first three before you start this part

triples[history[0]][history[1]][history[2]]++;

//This could be a loop (and really should be)
history[0] = history[1];
history[1] = history[2];

history[2] = newValue;

//Then you can do something like
for(int i = 0; i < INDEXES; ++i)
  for(int j = 0; j < INDEXES; ++j)
    for(int k = 0; k < INDEXES; ++k)
      if(triples[i][j][k] > 0)
        printf("%d, %d, %d: %d", i, j, k, triples[i][j][k];

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

705 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