|
Nevermind... I'm just an idiot. Note to self: (x/16) * (16/y) != (16*x)/y
The solution is actually:
±√[1/3 * (15/11 - ∛{-40/9317 * [9 + 11√(-54)]} - ∛{-40/9317 * [9 - 11√(-54)]})]
Thanks to anyone who was planning to help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
|
That is a really handy site! You wouldn't happen to know how to determine the roots of higher-order polynomials to n-significant figures, would you? For example, when I plug in the following Legendre polynomial, I only get the roots to 6-significant digits.
(46189x^10 - 109395x^8 + 90090x^6 - 30030x^4 + 3465x^2 - 63) / 256
I can't figure out how to run this query so I get the "more digits" option for the roots. This isn't really an algorithm question, but I figured you may have some insight since you recommended that site. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
|
Yes, there are a lot of really good math programs out there. if you know Python then go with Sage. If not I would go with Maximia.
~TheArch
|
|
|
|
|
Now ihave do this
select a from table_a where aa=123
select b from table_a where aa=32
select sum(aa) as c from table_a where aa=44
select sum(bb) as d from table_a where aa=88
i want to select them just use one SQL.not use union,because i want to show them like this :
a b c d
1 2 32 32
23 43 54 564
32 43 64 45
show four fields,not one,it's difficulty for me,i have done all day long,everyone who can teach me ?very apprciate!!
|
|
|
|
|
Cross posting is considered bad form here. Your question is SQL related and you've posted it the SQL forum.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi
Is there any algorithm to check if a binary tree
(not BST,just a binary tree with max two childs for each parent)
is AVL tree?
Regards
|
|
|
|
|
|
An AVL tree's height will be limited to 1.44*Log2(n), so why not calculate the height and then if it is over the max height then it's not AVL.
Here is a PFD to calculate the height:
AVL Trees[^]
Hope this helps....
~TheArch
|
|
|
|
|
Hi there, I have an algorithm which searches a graph for Hamiltonian cycles. A graph is a bunch of nodes, with edges (connected with probability p each). A Hamiltonian cycle is a path along the edges from one node back to itself- passing through each node precisely once.
My algorithm currently does the following procedure:
starts at node 1
tries to increase the path to 2 vertices, call it 1,final node.
Algorithm:
if final node in path has a neighbour not already in the path, extend it by going to the first neigbhour it has in a list
if final node has no neighbours then remove final node and search the list of (final node - 1) for other potential neighbours.
(output if Path has length n and final node is connected to node 1)
This algorithm has a worst case complexity of n!. I.e if there n nodes and it visits everypath but can't find a hamiltonian cycle.
But what would be the average case running time given n and p?
|
|
|
|
|
Try your code using my Big O Algorithm Analyzer.
Big O Algorithm Analyzer for .NET[^]
It will show you the running time verses the n, you might have to create a Big O function to calculate p, I can't understand why this would be n! though.
Let me know if you need some help using the tool.
|
|
|
|
|
This can't be a new problem, but I don't see any code out there for it. An application I'm working on accepts input in Unicode, so most things work with Japanese characters, but there are a couple of names that I need to generate in ASCII. I have a base name to work from in Japanese (Hiragana or Katakana) and would like to use Hepburn or ISO_3602 romanization to convert into ASCII. There are various tables out there that I could use for this purpose, but I thought I'd check here first.
Has anyone out there solved this problem who's willing to share?
Thanks
|
|
|
|
|
Well, I have no knowledge on the language, but couldn't you just create a look-up method?
|
|
|
|
|
So far i have made the snake move about, eat randomly generated food pieces and the peices attach to the end of the snake, i need help on figuring out how to move the "segments" attached to the head of the snake.
For example a snake moving right works fine,
----->
But when i press down this happens:
|
|
|
V
When it should be:
-----
.....|
.....V (dots represent a space as this WYSIWYG doesn't allow me to have spaces)
Any ideas? Thanks
|
|
|
|
|
Hi,
1.
when you use PRE tags, you get a non-proportional font, and spaces work as you would expect.
2.
you need to hold the playground in memory, maybe as a 2-dimensional array of integers.
you could initialize it at all zero (=empty cells); then set one or a few cells to consecutive numbers (1,2,3,..N) where the highest number is the head and the lowest non-zero is the tail of the snake.
Moving it means adding the next number to the right/left/top/down position of the head, depending on current direction; and probably also removing the lowest non-zero, unless you want the snake to grow.
[CLARIFICATION ADDED]: in one dimension the snake could move
from 0 0 1 2 3 4 0 0 0
to 0 0 0 2 3 4 5 0 0
, so the head was 4 and now moved to 5, while the tail was 1 and moved to 2. You keep a pointer to the head and adjust it in the right direction; and you keep a pointer to the tail, search the neighbour that is one higher, and that becomes the tail.[/ADDED]
3.
and then you should visualize all this in the Paint handler, as I explained here[^].
modified on Wednesday, January 13, 2010 8:41 PM
|
|
|
|
|
I would actually store the snake's head index, tail index, and current direction. Then, store a 2D grid such that each cell can have one of three values: empty, snake, or new_segment, based on the contents of that cell. At each time step, move the head in the current direction by updating the head index, and test the value of that cell. If the value is "snake", there is a collision. If the value is "new_segment", draw the head, change the value to "snake", and continue to the next time step. Finally, if the value at the head index is "empty", erase the tail, search the four adjacent cells to find the one with a "snake" value (that isn't the head index), and set the tail index appropriately.
This approach has the following complexities:
Memory usage: O(grid_size)
Moving the snake: O(1) (assuming you use arrays with constant access time)
Redrawing the snake: O(1) (you only have to update at most two cells)
Testing for collisions: O(1) Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I'm not sure that is good enough, if zero-gap meandering is allowed (it seems it is in such games), then the tail would not know where to go, as in:
0 0 0 0 0 0 0
0 1 4 5 6 7 0
0 2 3 0 0 0 0
where 7 is the head, 1 is the tail, and the problem is which square to vacate after 1 is vacated.
|
|
|
|
|
Ah... then perhaps there are still three states: empty=int.MaxValue, new_section=int.MaxValue - 1, and other=moveCount % (int.MaxValue - 1) (if it is not possible to have a game where int.MaxValue - 1 moves are made, then forget the modulus to save time. Also be sure that grid_height * grid_width < int.MaxValue - 1). Basically, I was trying to suggest the possibility that the number assigned to each cell was not necessarily the location of that cell in the snake. This allows a move to be performed in O(1) time instead of having to iterate through each snake segment and decrement it to reflect the snake segment on that tile. I think you were suggesting the same thing, but after reading your post I didn't know if that was clear to the OP or not, so I tried to expound upon it even though I probably just added to the confusion with my buggy approach. Thanks for the catch!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I think you misunderstood my proposal; I'm not reworking the whole snake on each step of its journey: I add a head (like you do), and I replace the current tail by the cell that is numbered one higher, so if a snake is 1-2-3-4 at one point in time, it is 2-3-4-5 the next, etc. So it is as O(1) as yours, and has a similar limitation as I must end the game, or do something very special, when the head would overflow (an easy trick would be to use odd values only for the snake cells, i.e. increment by 2; that would work fine except for very complex paths on huge boards).
BTW:
Skippums wrote: there are still three states: empty=int.MaxValue, new_section=int.MaxValue - 1, and other=moveCount % (int.MaxValue - 1)
if the state variable can range from 0 to int.MaxValue, few people would call that three states
|
|
|
|
|
Luc Pattyn wrote: I think you misunderstood my proposal
Exactly! When I first read your post, I thought, "Why would Luc suggest such an inneficient algorithm?" I knew you wouldn't suggest such a thing, so I reread your post. After a few reads, I finally comprehended what you meant, and thought that it could use some clarification. Unfortunately, I clarified it right into buggy software, but I think you get where I coming from .
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Sorry about that; I now added some clarification to the original message.
Thanks.
|
|
|
|
|
Hi 'thebuzzwright',
> So far i have made the snake move about, eat randomly generated food pieces and the peices attach to the end of the snake, i need help on figuring out how to move the "segments" attached to the head of the snake.
I just wanted to add that I have a freeware open source version of the Snake game, written in Borland Delphi 5 (no longer owned by Borland any more. See: embarcadero.com for the latest trial versions of Delphi or google for 'free Delphi compiler download' to find older free versions of Delphi).
https://downloads.embarcadero.com/free/delphi[^]
... for M$ Windows (almost all versions). You should also be able to port it to other versions of Delphi or even convert in to Lazarus programming language (available for M$ Windows, Macs & Linux). Delphi and Lazarus are essential Object Oriented Pascal with a GUI (Graphical User Interface) RAD (Rapid Application Development) interface.
I would recommend Delphi 3 or 5 or 7. Standard is fine (named 'Personal' in later versions) however, with the later forms of the compiler e.g. Professional or Enterprise version (and later Architect)... they can be very expensive and also have a very large foot-print (e.g. size of installed files and folders) but they will also have the source code for it's units included with the compiler. This is handy if you need to re-compile it's own units (not usually necessarily) and also if you want to look at the code for one of Delphi's own unit or form files to see how they have implemented some of the code to achieve a particular task.
Alternatively, Lazarus compiler is very good... however, note also that the compiler is constantly being developed and re-programmed and tweaked and developed ... so you will need to find a 'repository' for the 'snapshots' of the compiler and download it and compile it... There are different versions for different OS's and also different versions of the compiler -- some of which are considered stable code and some contain experimental beta version of the compiler (RAD GUI). Just google for it.
My Snake Game
=============
Here is a link to my freeware open source version of the Snake game in Delphi 5. It is based on an earlier version of it by someone else, which I debugged and made some changes to. It was also written in Delphi (possibly ver 4 or 3... I forget, as this goes back years). There is also a link to the older ver in the code, and possibly also the code of the ealier version *may* be included.
http://sites.google.com/site/pewtas/delphitable2#SNAKEGAME[^]
Note that there are some nifty new features which I added, like being able to have the borders ON or OFF. When the border are OFF, you can move thro' the borders (or walls) and the window for the snake simply wraps around e.g. left and right borders join and so do the top and bottom borders. I also added numerous tweaks and debugged it quite a bit and re-wrote some of the code and declarations (e.g. type-declaration -- to make it more structured and/or more readable).
Regards,
PEW ))
from Hobart, Tasmania, AustraliaPeter E Williams ))
|
|
|
|
|
Thanks for that very helpful !
|
|
|
|
|
I have a 2D scene defined as a series of segments (like a GL_LINES section from OpenGL or Line from Direct3D). Each segment have a starting and an ending point. These segments can be joined at one end or not.
I want to find inside this scene the rectangle which :
a) have the interior completely free (no segment can cross its boundaries - might touch them thou);
b) have his sides parallel to Ox and Oy axes;
c) have the biggest area;
d) have the center closest to a specific point (Xref,Yref);
e) have a certain aspect ratio H/W.
Conditions a) and b) are mandatory. Condition c) have priority over d) and d) over e) meaning it is more important to be bigger than to be closer to Xref/Yref which it is more important than having a specific aspect ratio (how to quantize "importance" - I'm open to suggestions).
I only need ideas/hints how to solve this problem (if it is solvable) - I'll manage the implementation regardless of complexity.
Thank you
|
|
|
|
|