|
By specifying that you need the "best" algorithm, you have severely limited any response.
Oh, and that's "Octal" you're fiddling with.
|
|
|
|
|
Thank you,
better perhaps put examples
81 LINES
11111111111111
11121111111111
11141111111111
11211111111111
11221111111111
11241111111111
11411111111111
11421111111111
11441111111111
12111111111111
12121111111111
12141111111111
12211111111111
12221111111111
12241111111111
12411111111111
12421111111111
12441111111111
14111111111111
14121111111111
14141111111111
14211111111111
14221111111111
14241111111111
14411111111111
14421111111111
14441111111111
21111111111111
21121111111111
21141111111111
21211111111111
21221111111111
21241111111111
21411111111111
21421111111111
21441111111111
22111111111111
22121111111111
22141111111111
22211111111111
22221111111111
22241111111111
22411111111111
22421111111111
22441111111111
24111111111111
24121111111111
24141111111111
24211111111111
24221111111111
24241111111111
24411111111111
24421111111111
24441111111111
41111111111111
41121111111111
41141111111111
41211111111111
41221111111111
41241111111111
41411111111111
41421111111111
41441111111111
42111111111111
42121111111111
42141111111111
42211111111111
42221111111111
42241111111111
42411111111111
42421111111111
42441111111111
44111111111111
44121111111111
44141111111111
44211111111111
44221111111111
44241111111111
44411111111111
44421111111111
44441111111111
after joining
77771111111111
Example 3 first lines
11111111111111
11121111111111
11141111111111
Therea only difference in 3th character
001 xor 010 ==> 011
and there only a different in 3th charcter in 3th line then
011 xor 100 ==> 111 => 7
|
|
|
|
|
There's no recursion required; just a "for" loop.
XOR the first and second "lines"; then XOR that result with the 3rd; and so forth.
Maybe not the "best", but "easy" to understand and implement; and you're only dealing with 81 "lines".
|
|
|
|
|
Thank You
My Post was a trivial example , but can have somee restrictions
Example:
3,5 and 6 can show only 2 times
or
7 with 3
or
7 with 5
or
7 with 6
show only one time in file
example
75444444444444 is possible
75344444444444 no is possible because 7 is together 5 and 3
35644444444444 no possible 3,5 and 6
35444444444444 is possible
etc
My problem is way to let
smaller number of possible lines
|
|
|
|
|
If you need to "filter" your "list of lines" use LINQ.
You can remove items; count items; etc.
e.g.
... = MyList.Where( line => line.contains() || line.StartsWith() || etc. )
|
|
|
|
|
Hello to All!
I am performing a small academic research regarding distributed storage systems and some practical problems that are connected with this. One problem is fail-over and primary-backup replication algorithms. Some DSS use consensus algorithms to elect leader for replication like Raft and Paxos (Multi-Paxos). So my question is:
How do these algorithms address replication issues in storage systems? What are advantages and disadvantages to use Paxos or Raft? E.g.:
1. Raft has following advantages:
2. Raft has following limits:
3. Paxos has following advantages:
4. Paxos has following limits:
Can anyone point me on what basic pros and cons are for these two algorithms in using for storage systems?
What is the practical usage of both of them in DSS?
Thanks in advance,
Nick.
|
|
|
|
|
|
Thank you Richard, I know these resources. But mostly information there is about internals of algorithms and how they work. By now I need to see a brief comparison of limits of each for the purpose of building a fault tolerant system using consensus.
So maybe more simple question for people who already familiar with both
protocols: what do like and dislike in each other? I need information not like "it's more complex" or "it's more popular" but better their limits in particular purpose (storage fault tolerance). Why one prefer Paxos or other likes Raft?
Regards,
Nick.
|
|
|
|
|
Hi.. im new here...
Im a BSCS freshman and im studying in a couple of weeks.. i just have a little problem... i am having trouble translating this flowchart into an algorithm pseudocode... i dont know how to end the program in the middle of DO-WHILE and REPEAT-UNTIL, it just makes me write endless DO-WHILEs... can someone help me?
here is the link of my flowchart..
untitled — Postimage.org[^]
thanks for helping me..
modified 27-Aug-16 9:00am.
|
|
|
|
|
Please use "code" tags to modify your question so the flowchart is readable. That will give you a fixed width font, and you can see the preview to get it right. You won't get any answers to the current mess.
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
ive edited my post.. hope you can now understand it..
|
|
|
|
|
Crikey! If that's the 'fixed' version, the other one probably killed dolphins, fairies and little babies.
As suggested, rather than trying to hack it together using . characters for spacing, why dont you wrap it in <pre> </pre> blocks? (select it then hit the 'code' button)
You could end up with something as legible as this (even with it's incorrect decision boxes):
+-------+
| START |
+-------+
|<--------+
+---v---+ |
|X = X+1| |
+---+---+ | YES
| |
+---v---+ |
| X < 3?|-----+
+-------+
|
| NO
|
v
Failing that, upload an image to an image-hosting site and then post a link. That's the less preferred option, text is perfectly adequate.
|
|
|
|
|
omg thank you... now its better..
modified 27-Aug-16 8:21am.
|
|
|
|
|
You're welcome. That image is much more legible.
|
|
|
|
|
|
OMG now i get it.. thank you so much for the info ;D ;D
modified 27-Aug-16 21:01pm.
|
|
|
|
|
Please Need Urgent Code suggestions for this:
There is a 2D matrix which has 0s and 1s . Your main aim is to tell maximum number of rows that are max amplified . A row is max amplified if all the columns in a row are 1. You have been given K which tells the number of column inversions you HAVE to do . Column inversion means that the whole column of that 2D matrix is inverted . 0 is replaced by 1 and 1 is replaced by 0 . You have to tell that after K inversions how many rows of max amplification will be present . K inversions gave to take place . Not less than that not more . One column can be inverted more than once .
|
|
|
|
|
Your homework is set to test what you know, not how good you are at convincing strangers on the Internet to do your work for you.
Try doing it yourself, and you'll probably find it's not as difficult as you think. After all, it should be based on concepts that you've recently covered in your course.
If you really don't know where to start, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This a test about your math knowledge and convert to code. Computer graphic you has do it or you will never get it
|
|
|
|
|
I'm facing problem intersecting ray with triangle edges. Actually, I'm trying to pick/intersect with triangle, vertex, edge of a mesh using Mouse. So I made ray from the Mouse current position and then I intersect it with the mesh elements like triangle/polygon, vertex, edge etc to work with it. Basically, 3d modeling stuffs. Intersecting with triangle was easy and fun. And the vertex part was tricky.
But now, I don't know how to intersect/pick with triangle edges. I mean how I treat them when intersecting with the Mouse Ray? First I thought they can be treated like a 3d line. But eventually failed to do the Ray and the Line intersect. Searched on the Internet but not found any helpful info. Although I found some open source projects are using OpenGL built-in picking features to pick/intersect with Edge. But in my case, I can't use that.
So I really need some help. Any idea, algorithm or a small help is greatly appreciated.
|
|
|
|
|
Am I reading this right if I say that you want to select the edge if the distance between your vector (the ray) is shorter than the distance epsilon (or some other defined minimal distance) from the line?
If we move to 2d a Voronoi diagram would suffice? Or some version of this:
Add a point to a polyline[^]
|
|
|
|
|
I'm not sure I understand the ray part, but since you're talking 3D, I'd look for the intersection of the mesh parts with a sphere centered on the mouse click location -- point (vertex) contained in sphere, line segment (edge) fully or partially contained in sphere, etc. This means you'll need to keep track of the cursor location in three dimensions and map the actual mouse gestures on the screen to somehow moving that 3D cursor.
This is pretty standard math for any 3D rendering or 3D game, so you might see if you can find a library that already implements the heavy lifting for you. If you roll your own, there's tons of resources for this sort of math, but I often found myself at the Wolfram reference site.
If your mesh is big, performance will be pretty slow. I think a lot of the 3D editors do the voxel thing so they can check only a subset for each event.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
Ah.. I see you are suggesting me to go for Sphere-Line intersect instead of Ray-Line. Am I right? Although currently, I'm not concern about the vertex part since I already did it somehow..
But I think I should really check out if I can implement the Sphere-Line intersect idea to pick triangle's edge.
And yes, many thanks for the suggestion about performance
|
|
|
|
|
Actually, now that I've thought about it, sphere math is overkill, and probably not what you're wanting anyway. It'll work, but it's be simpler to just calculate nearest point on a line to a 3D point, and then decide if A) that falls within the endpoints of the line segment, and B) the distance between the two are close enough.
However, if you're using your "ray" to describe corner points of a 3D prism that's the selection bounding volume, then its just point inside a volume, and 3D plane/line-segment intersection math.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
|
|
|
|
|
I'm in the process of writing my 4th generation package calculator. Over the years, UPS and FedEx require that you enter package dimensions and weight to get a quote.
Before I was able to create a clump, which I call a unit of mass, based off the cart database which contains each products dimensions, then cube that clump into a cube shape. But times have changed.
My 3rd generation package calculator was a complete failure overall, in which I tried using SQL Linq to calculate from the database
So here is my 4th generation attempt.
I get all the items from the database, and throw the items into 1 of 4 categories - List(Of
These will always be separate packages
Isolated Items - Case Quantities, you just slap a label on them and ship
Long Items, like sticks, long levels over 6ft
These can be combined into a single package, if under the max parameters
Thin Items like pancakes, AAA batteries less than 1/2" height
Common Items - you can throw them in a box, slap a label and ship
Then I wrote 4 functions that calculate the length, width, height, dimensional weight, gravity weight.
Within each function, a loop runs.
Each function is slightly different, ...
1. lines up the items by length, then loops down the lengths going wider, then taller
2. stacks them up like a tower, largest on the bottom
3. Isolate - its just a package, get the length, width, height, weight and go
4. Common - I'm in doubt on this one, needs improvement
If the limit is reached, the Create_Package fires and makes a Package.
So now I have these packages, and run Package_Combine, in which I see if I can throw a THIN package into the common box, to reduce the number of packages, because each package has a base cost of $7.00, and shoppers freak out.
The packages are a class of package_types, that are sent off to UPS or Fedex for a Quote, in which those programs I wrote loop and submit each package as a single shipment.
My code is too large to post. So I will post a snippet of 2 functions to start with.
So my question is, do you think I'm on the right track. Does a better more efficient way pop into your head. Did I make it way too complicated?
Think I get can further refine the 4 functions into 1 function by using more Linq?
I have to get this right this time, I'm tired of being poor and need to raise my income. I don't have the funds to just pay someone to write this, and how would I validate that person before hire.
Oh and I expect to hear crickets on this post, sit here forever with no reply.
Here are some known values
Private Const MAX_DIMENSIONAL_LENGTH As Decimal = 108.0
Private Const MAX_DIMENSIONAL_WEIGHT As Decimal = 165.0
Private Const MAX_GRAVITY_WEIGHT As Decimal = 150.0
Private Const MAX_TYPICAL_BOXLENGTH As Decimal = 37.0
Private Const MIN_TYPICAL_LONG_ITEM As Decimal = 72.0
Common Items - I'm in doubt about this one.
Private Shared Function Package_C1( _
ByVal pItems As List(Of model_rateItems),
ByRef packages() As package_type) As Integer
Dim pValue As Integer = 0
Dim pdx As Integer = 0
Dim item As New model_rateItems()
Dim gWeight As Decimal = 0
Dim dWeight As Decimal = 0
Dim dPackage As Decimal = 0
Dim oFlag As Boolean = True
For Each p As model_rateItems In pItems _
.OrderByDescending(Function(m) m.Length) _
.OrderByDescending(Function(m) m.Width) _
.OrderByDescending(Function(m) m.Height)
pdx += 1
If (p.Qty = 1) Then
gWeight += p.Weight
item.Cost += p.Cost
item.Price += p.Price
item.Weight += p.Weight
item.Description = If(item.Description Is String.Empty, p.Description, item.Description & ", " & p.Description)
item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
item.DryIce = If(p.DryIce = True, True, item.DryIce)
item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)
item.Length = If(p.Length > item.Length, p.Length, item.Length)
item.Width = If(p.Width > item.Width, p.Width, item.Width)
item.Height = If(item.Height = 0, p.Height, (item.Height + p.Height))
dWeight = Calc_DWeight(item)
If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then
pValue += Package_Create("COMMON", dWeight, item, packages)
End If
Else
item.Cost += p.Cost * p.Qty
item.Price += p.Price * p.Qty
item.Weight += p.Weight * p.Qty
item.Description = If(item.Description Is String.Empty, p.Description, item.Description & ", " & p.Description)
item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
item.DryIce = If(p.DryIce = True, True, item.DryIce)
item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)
item.Length = If(p.Length > item.Length, p.Length, item.Length)
item.Width = If(p.Width > item.Width, p.Width, item.Width)
item.Height = If(item.Height = 0, p.Height, (item.Height + (p.Height * p.Qty)))
dWeight = Calc_DWeight(item)
If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then
pValue += Package_Create("COMMON", dWeight, item, packages)
End If
End If
Next
dWeight = Calc_DWeight(item)
pValue += Package_Create("COMMON", dWeight, item, packages)
Return pValue
End Function
Long Items - It's seems to work well. but I think maybe there's a more efficient way to do it.
Private Shared Function Package_L1( _
ByVal pItems As List(Of model_rateItems),
ByRef packages() As package_type) As Integer
Dim pValue As Integer = 0
Dim pdx As Integer = 0
Dim item As New model_rateItems()
Dim dWeight As Decimal = 0
Dim oFlag As Boolean = True
For Each p As model_rateItems In pItems.OrderByDescending(Function(m) m.Length)
pdx += 1
If (p.Qty = 1) Then
item.Cost += p.Cost
item.Price += p.Price
item.Weight += p.Weight
item.Description = If(pdx = 1, p.Description, ", " & p.Description)
item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
item.DryIce = If(p.DryIce = True, True, item.DryIce)
item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)
If (p.Length > item.Length) Then
item.Length = p.Length
item.Width = If(item.Width = 0, p.Width, item.Width)
item.Height = If(item.Height = 0, p.Height, item.Height)
Else
If (p.Width > item.Width) Then
item.Length = item.Length
item.Width = p.Width
item.Height = item.Height + p.Height
Else
item.Length = item.Length
item.Width = item.Width
item.Height = item.Height + p.Height
End If
End If
dWeight = Calc_DWeight(item)
If (dWeight > MAX_DIMENSIONAL_LENGTH Or item.Weight > MAX_GRAVITY_WEIGHT) Then
pValue += Package_Create("LONG", dWeight, item, packages)
dWeight = 0
item = New model_rateItems()
ElseIf (pdx = pItems.Count()) Then
pValue += Package_Create("LONG", dWeight, item, packages)
Exit For
End If
Else
item.Description = If(pdx = 1, p.Description, item.Description & "," & p.Description)
item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
item.DryIce = If(p.DryIce = True, True, item.DryIce)
item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)
item.Width = If(item.Width = 0, p.Width, item.Width)
item.Height = If(item.Height = 0, p.Height, item.Height)
For idx As Integer = 0 To p.Qty - 1
item.Length = item.Length + p.Length
item.Weight += p.Weight
item.Cost += p.Cost
item.Price += p.Price
If (item.Length > MAX_DIMENSIONAL_LENGTH And item.Weight < MAX_GRAVITY_WEIGHT) Then
If (p.Length > item.Length) Then
item.Length = p.Length
item.Width += p.Width
item.Height = If(p.Height > item.Height, p.Height, item.Height)
Else
item.Length = item.Length - p.Length
item.Width += p.Width
item.Height = If(p.Height > item.Height, p.Height, item.Height)
End If
ElseIf (item.Length < MAX_DIMENSIONAL_LENGTH And item.Weight < MAX_GRAVITY_WEIGHT) Then
If (p.Length > item.Length) Then
item.Length = p.Length
item.Width += p.Width
item.Height = If(p.Height > item.Height, p.Height, item.Height)
Else
item.Length = item.Length
item.Width += p.Width
item.Height = If(p.Height > item.Height, p.Height, item.Height)
End If
End If
dWeight = Calc_DWeight(item)
If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then
pValue += Package_Create("LONG", dWeight, item, packages)
dWeight = 0
idx = idx - 1
item = New model_rateItems()
End If
Next
End If
Next
If (pValue = 0) Then
dWeight = Calc_DWeight(item)
pValue += Package_Create("LONG", dWeight, item, packages)
End If
Return pValue
End Function
|
|
|
|
|