|
What is the rule according which they have been ordered?
|
|
|
|
|
The first row in the table dictates what label should be in the first group box in the first tab page. Then, all other labels that belong in same the tab page and group box are added in the order they appear in the original table. When no more labels belong to the first group box in the first tab page, then second group box in the first tab page are added in the order they appear in the original table. Then the third group box is processed, then the fourth, etc until there are no more group boxes in the first tab. Then same algorithm applies same way to the second tab page, then the third tab page, then the fourth, etc.
|
|
|
|
|
That looks to be just a simple sort using the T field as the first key, and the H field as the second. Er, except the last two entries.
|
|
|
|
|
I'm not sure it's particularly efficient, but using LINQ, you can at least get the right answer.
struct Record
{
public int T { get; set; }
public int H { get; set; }
public int L { get; set; }
}
Record[] UnsortedRecords =
{
new Record { T = 0, H = 0, L = 2 },
new Record { T = 1, H = 2, L = 1 },
new Record { T = 0, H = 1, L = 4 },
new Record { T = 0, H = 0, L = 0 },
new Record { T = 2, H = 4, L = 2 },
new Record { T = 2, H = 3, L = 6 },
};
public static IEnumerable<Record> SortRecords(IEnumerable<Record> source)
{
return source
.GroupBy(r => r.T, (key, items) => items
.GroupBy(r => r.H)
.SelectMany(g => g)
)
.SelectMany(g => g);
}
IEnumerable<Record> SortedRecords = SortRecords(UnsortedRecords);
NB: The documentation for GroupBy states that the order of the input sequence is preserved by both the returned groups, and the items within each group:
The IGrouping<TKey,TElement> objects are yielded in an order based on the order of the elements in source that produced the first key of each IGrouping<TKey,TElement> . Elements in a grouping are yielded in the order they appear in source .
You might be tempted to use a composite key in the grouping, to reduce the nesting. But that won't work - T0H1 and T1H2 will be returned in the wrong order:
source.GroupBy(r => new { r.T, r.H }).SelectMany(g => g);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This seems to be exactly what I need. Does anybody know how I can implement this in Visual Studio 2005? Or, does anybody know how I can convert my traditional ArrayList into an IEnumerable<record>? The contents of my ArrayList are objects of a class containing about 20 different variables (out of which 3 are strings representing tab page, group box, and label).
|
|
|
|
|
You can use LINQBridge[^] to bring the LINQ methods into C# 2.0, although the syntax is nowhere near as clean:
public static IEnumerable<Record> SortRecords(IEnumerable<Record> source)
{
IEnumerable<IEnumerable<Record>> groupT = Enumerable.GroupBy(source,
delegate(Record r) { return r.T; },
delegate(int key, IEnumerable<Record> items)
{
IEnumerable<IGrouping<int, Record>> groupH = Enumerable.GroupBy(items, delegate(Record r) { return r.H; });
return Enumerable.SelectMany(groupH, delegate(IGrouping<int, Record> g) { return g; });
});
return Enumerable.SelectMany(groupT, delegate(IEnumerable<Record> g) { return g; });
}
You can either replace the ArrayList with a List<T>[^], or use the Cast[^] or OfType[^] methods to convert it to an IEnumerable<T> .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I get the following compiler error on all lines that contain the word Enumerable:
The type arguments for method 'System.Linq.Enumerable.GroupBy<tsource,tkey>(System.Collections.Generic.IEnumerable<tsource>, System.Func<tsource,tkey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Does anybody know how I can correct this?
|
|
|
|
|
That's annoying. It sounds like C# 2.0 can't infer the generic type parameters properly. You might need to specify them explicitly:
public static IEnumerable<Record> SortRecords(IEnumerable<Record> source)
{
IEnumerable<IEnumerable<Record>> groupT = Enumerable.GroupBy<Record, int, IEnumerable<Record>>(source,
delegate(Record r) { return r.T; },
delegate(int key, IEnumerable<Record> items)
{
IEnumerable<IGrouping<int, Record>> groupH = Enumerable.GroupBy<Record, int>(items, delegate(Record r) { return r.H; });
return Enumerable.SelectMany<IEnumerable<Record>, Record>(groupH, delegate(IEnumerable<Record> g) { return g; });
});
return Enumerable.SelectMany<IEnumerable<Record>, Record>(groupT, delegate(IEnumerable<Record> g) { return g; });
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Let's do this the old way!
Sorting on multiple keys with a comparer method is straightforward (and easy to understand?). It is just a nested set of comparisons, compare the first key, if equal compare the second key, etc.
For example let's say we have a list of strings and we want a custom sort.
1) by string length
2) alphabetically within each group of equal length
The comparer method is
private static Int32 SortByLengthThenAlpha(String x, String y) {
Int32 result = x.Length.CompareTo(y.Length);
if (result == 0) {
result = x.CompareTo(y);
}
return result;
}
With an array of strings we can perform the sort with
Array.Sort(strings, SortByLengthThenAlpha);
Original Order
==============
Reddish
Yellowish
Redder
Greenish
Red
Orange
Yellow
Orangy
Green
Sorted
======
Red
Green
Orange
Orangy
Redder
Yellow
Reddish
Greenish
Yellowish
Hope that helps explain the general idea. In your case the keys are the numeric values of T, H and L.
Alan.
|
|
|
|
|
I think my example data was not so good, the following is probably better:
Unsorted:
"City" "Florida" "Miami"
"Animal" "Land" "Dog"
"Animal" "Land" "Rabbit"
"Food" "Dessert" "Chocolate Mousse"
"Food" "Dinner" "Hamburger"
"Animal" "Water" "Fish"
"Animal" "Land" "Cat"
"Food" "Dessert" "Cake"
"Animal" "Air" "Bird"
"Food" "Dessert" "Ice Cream"
"Food" "Dinner" "Steak"
"Animal" "Water" "Sea Lion"
"City" "Texas" "Austin"
"Food" "Breakfast" "Cereal"
"Food" "Breakfast" "Pancakes"
"City" "Florida" "Tampa"
"Animal" "Air" "Fly"
"City" "California" "San Francisco"
"Food" "Breakfast" "Bacon and Eggs"
"City" "Texas" "Dallas"
"City" "Texas" "Houston"
"City" "California" "Los Angeles"
"Animal" "Water" "Dolphin"
"Animal" "Air" "Bee"
"City" "Florida" "Orlando"
"City" "California" "San Diego"
"Food" "Dinner" "Lasagna"
Sorted:
"City" "Florida" "Miami"
"City" "Florida" "Tampa"
"City" "Florida" "Orlando"
"City" "Texas" "Austin"
"City" "Texas" "Dallas"
"City" "Texas" "Houston"
"City" "California" "San Francisco"
"City" "California" "Los Angeles"
"City" "California" "San Diego"
"Animal" "Land" "Dog"
"Animal" "Land" "Rabbit"
"Animal" "Land" "Cat"
"Animal" "Water" "Fish"
"Animal" "Water" "Sea Lion"
"Animal" "Water" "Dolphin"
"Animal" "Air" "Bird"
"Animal" "Air" "Fly"
"Animal" "Air" "Bee"
"Food" "Dessert" "Chocolate Mousse"
"Food" "Dessert" "Cake"
"Food" "Dessert" "Ice Cream"
"Food" "Dinner" "Hamburger"
"Food" "Dinner" "Steak"
"Food" "Dinner" "Lasagna"
"Food" "Breakfast" "Cereal"
"Food" "Breakfast" "Bacon and Eggs"
"Food" "Breakfast" "Pancakes"
How would I then use your code to sort it?
|
|
|
|
|
The problem you have is that the desired arrangement within the 3 columns has no discernable order. You are grouping terms, City, California, Water, Breakfast etc, but the order of the groups seems completely random. For example why is the order of the states Florida, Texas, California? There is nothing about the strings which would suggest that order so there must be some other factor which is not in the data that you have shown.
Alan.
|
|
|
|
|
First, pretend only column 1 (tab page string) and column 2 (groupbox string) are present and then simply remove all duplicate rows. This is the sorted order for columns 1 and 2. Now, insert column 3 items in the groupbox where they belong and preserve the unsorted order within each groupbox.
|
|
|
|
|
Hi,
I am trying to build email spam filtering .I have already done when email has text only but the problem when deal with images
Any help how to install tensorflow and deal with images.
Thanks
|
|
|
|
|
|
anyone would like to try a program on this. i have some practice material. Also would love to see what you are all upto. share your work too.
The running time of the program should be less than 4 seconds.
Mina wants to go on a trip during the a summer vacation.
She has to pay in advance several things such as airfare, lodging, car rent, show tickets,
etc. To pay them, she wants to use her mileage points from her credit card, airline, cell
phone, etc.
She can divide mileage points from one source (ex. airline mileage) to pay multiple things
(ex. airfare and tickets). Also she can merge mileage points from multiple sources (ex.
airline and cell phone) to pay one thing (ex. car rent).
However, there can be a limitation in applying certain mileages to certain type of payments.
For example, suppose she has 100,000 (in Korean Won) airline mileage and 50,000 cell phone
mileage, and she wants to pay 90,000 for airfare and 70,000 for car rent 1 , there can be a
limitation that she can use airline mileage for both airfare and car rent, but she only can
use cell phone mileage for car rent.
With that limitation, it is not a good idea to use only airline mileage to pay for car rent,
because, after that, she needs to pay 60,000 for car rent (after she use 90,000 for airfare
and 10,000 for car rent from 100,000 airline mileage). Instead, it is a reasonable choice to
use 50,000 cell phone mileage for car rent first, and then use 100,000 airline mileage for
airfare and car rent, which results her to pay 10,000 for either car rent or airfare.
Now given a set of mileages, a set of payments, and lists of feasible payments for each
mileage, calculate the minimum amount of money that Mina has to pay.
Input
2 <-- # of mileages
10 5 <-- mileage #0 and #1
2 <-- # of payments
9 7 <-- payment #0 and #1
0 1 <-- mileage #0 can be used for payment #0 and #1
1 <-- mileage #1 can be used for #1
Output
1 <-- minimum of payment 1 is needed
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello,
I need to print statement of account of my clients. I have a table that contains my invoices and another table that contains my payments. Each month I will have to print the history of invoices and payments with last month balance the calculate the new balance.
Date of transaction Reference Invoice Payment Balance
2016-02-25 09:23 FLO1602001 2281.2700 0 2281.2700
2016-02-25 09:51 FLO1602002 18860.1000 0 21141.3700
2016-04-14 09:39 RV16040100 0 -20205.3700 936
Could you advise me? What is the best practice? 1. I create a new transaction table and each month I fill this new table with my invoice and payment tables. Or 2. I re-calculate each month my last month balance ?
|
|
|
|
|
Accounts payable (AP) or receivable (AR)?
"Best practices" utilizes "journals"; to which daily transactions are "journalized"; which are then "posted" to "sub-ledgers" that maintain current balances; and monthly closing / opening balances.
The AP and AR (sub)ledgers typically contain one account per vendor / customer; with "sub-accounts" representing invoice debits and credits.
The AP and AR ledgers roll-up their totals to the "general ledger"; as (total) payables and receivables (per period; and current balances).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you for your reply. Do you have a link to a tutorial or more documentation?
|
|
|
|
|
|
The other response is good.
However if in fact this is only for you, then it is just going to be easier if you do exactly what you suggested, recalculate each month for the previous month.
Creating a new table each month would not be a good solution.
|
|
|
|
|
Hello.
There's an algorithm I've been asked to implement, from a paper called:
A chaotic image encryption algorithm based on perceptron model .
It was introduced in this paper.
I've spent quite some trying to implement it, but so far without success.
First of all I'd like to point to example results the authors are presenting - they say that for the Lorenz System their starting point was
X = 0, Y = 0, Z = 10^(-10) , but in the system if initial points of X and Y are equal to 0 then they will remain so, no matter the step we take. And actually mainly X and Y points from the system are used in the algorithm while Z's role is to increase randomization/variety of whole process.
The second thing which is unclear to me is in 2nd step, it says there to choose 8 bits in Z8 to create m, whereas Z8 is the Z coordinate from a point obtained through Lorenz System, but those are actually floating point values, would that mean I should be using bit representation of double/float type and choose the 8 bits from that?
In my implementation, as the m value will be later used for XOR operations with wj, wi, and those will have values within [0-255], I've been using bit representation of the Z8 (double type in my implementation) and in a 8-times loop I've been doing XOR operation on n-th bit of wi/wj with randomly chosen bit from Z8. Would that be correct?
And the last thing is the threshold value - θ - which is obtained through XOR operation on w'1 and w'2, but those are made from w1 and w2, which are obtained through same keyX value... so in the end w'1 and w'2 have same values, doing XOR on them I will always have 0, so what's even the point of having to add/subtract that threshold value if it's always gonna be 0 anyway?
For a reference I've set up a GitHub repo with my implementation and example results - encoded images and histograms. There you can find that I also tried using normal distribution instead of Lorenz System - then results are actually a bit similar to those presented in the article, but that's only if I use pure random distribution omitting the 2nd step and simply generating random numbers for the X, Y and Z without taking any step/choosing new starting points.
I've spent bunch of time trying to figure out this algorithm but I didn't manage to obtain results as those in the article.
I'd highly appreciate any help, maybe I'm confusing something or making wrong assumptions?
I'd like to also add, that I'd already tried to contact two of the paper authors but unfortunately I have not received any response.
|
|
|
|
|
Hi guys.
My google foo seems to have left me this morning as well as my cognitive abilities.
Lets say I have a list of 3 numbers, say (31549, 20468, 17625), that together add up to 69642. Say I have another list of numbers, (10211,8821,6894,6497,6482,5623,5594,5132,4471,4326,3245,2346), that also add up to 69642. I need to select the numbers from the second list that add up to the individual numbers in the first list.
In my example the result I would expect would be
10211 + 5623 + 6894 + 8821 = 31549
3245 + 6497 + 5132 + 5594 = 20468
21346 + 6482 + 4326 + 4471 = 17625
Hope someone has some ideas to help.
Thanks in advance
Everyone dies - but not everyone lives
|
|
|
|
|
Create an array of the second numbers. Take each of the first set in turn and loop through the second arraylooking for the combination that sums to the selected number. You will need to loop through the array taking each number in turn and adding one or more of the others looking for a combination that makes the sum.
|
|
|
|
|
Ah! the brute force approach. Sometimes the obvious escapes you. Many thanks for kickstarting my brain this morning.
Much appreciated
Everyone dies - but not everyone lives
|
|
|
|
|