I have a little assignment of stack smashing.So what is the simplest way to smash the stack?
I just want a simple illustrative method.
Try reading "Smashing the Stack for Fun and Profit" by Aleph One.
Related
The question Stack overflow despite tail call position but only in 64-bit lead to uncovering a bug in the F# compiler.
After reading the answer I am curious as to the reasoning that lead to finding the bug as I would like to better improve my skills at resolving problems and understanding TCO.
My reasoning was something like this:
Talking about "tail calls" when looking at a computation expression can be misleading - in general there really isn't such a thing (see e.g. this other answer for one related discussion, though not related to sequence expressions).
So calling gauss will not itself ever overflow the stack, only the code iterating through it could make it overflow. But once I saw that the calling code was just something like Seq.nth, that meant that there was almost certainly a compiler bug, because the pattern of "tail yield!ing" in a sequence expression is supposed to get optimized (not sure if this is part of the spec, but I think it's fairly well known). So then it was just a case of seeing what parts of the initial repro were necessary.
Replacing loop in the original code with a non-recursive definition made the repro stop failing, as did removing the pattern match. I didn't find looking at the IL helpful (there's so much compiler-generated machinery involved in the compilation of sequence expressions), I just tried minimizing the repro at the source level and empirically testing the behavior.
lets get right into this topic.
So I have a output from an cydia app called "AutoTouch".
touchDown(2, 634.4, 471.3);
usleep(66685.62);
touchUp(2, 635.4, 470.3);
usleep(365600.04);
Now, as i already made some functions for me, i want to parse that into something like that:
tapp(634, 471);
usleep(365600);
What simple language would u reccomend i should use to do that? It should be easy, but also powerful (like compare numbers and such hardcore stuff ^^) and work on osx/linux.
Thanks for your help and i hope i used the word "parsing" correctly :)
On linux/unix/osx, sed is your friend. You'll find a nice sed tutorial on grymoire. Depending on your specific needs, you could use awk as an alternative. There is also nice awk tutorial on grymoire.
The answer to this stack overflow question should help you choose between these two tools.
What is the complexity for Seq.append? Is it O(1) time and space?
I might add that (a) I should certainly hope so, and (b) I failed to google my way to complexity bounds for Seq module members. If someone know of such, I'd love to have a link to it.
EDIT. I did check the source code before asking. The implementation is here, which will make you look, eventually, at this function, the implementation of which is not immediately accessible to me, and the comments before which puzzles me.
Yes, it is O(1) because it basically just create a new object that encapsulates the two original sequences.
See source code here
is there any condition in which merge sort can be done without extra memory
my prof said it has and he will give bonus point on that.
You want to google in place merge sort.
Here is one of the result :
http://thomas.baudel.name/Visualisation/VisuTri/inplacestablesort.html
Use linked list. This will avoid the O(n) extra space needed during Mergeing of 2 lists. However, you cannot do anything about the space taken by recursion calls i.e O(lg(n)).
Yes, the answer to this is to use in-place merge sort
Given that this is a homework question, I can only point you to The Art of Computer Programming. A good programmer should be able to use the standard references in our field to research a question such as this.
i am kinda confused reading the definition between the two. Can they actually intersect in terms of definition? or am i completely lost? Thanks.
Closures, as the word tends to be used, are just functions (or blocks of code, if you like) that you can treat like a piece of data and pass to other functions, etc. (the "closed" bit is that wherever you eventually call it, it behaves just as it would if you called it where it was originally defined). A monad is (roughly) more like a context in which functions can be chained together sequentially, and controls how data is passed from one function to the next.
They're quite different, although monads will often use closures to capture logic.
Personally I would try to get solid on the definition of closures (essentially a piece of logic which also captures its environment, i.e. local variables etc) before worrying about monads. They can come later :)
There are various questions about closures on Stack Overflow - the best one to help you will depend on what platform you're working on. For instance, there's:
What are closures in .NET?
Function pointers, closures and lambda
Personally I'm only just beginning to "grok" monads (thanks to the book I'm helping out on). One day I'll get round to writing an article about them, when I feel I understand them well enough :)
A "closure" is an object comprising 1) a function, and 2) the values of its free variables where it's constructed.
A "monad" is a class of functions that can be composed in a certain way, i.e. by using associated bind and return higher-order function operators, to produce other functions.
I think monads are a little more complicated than closures because closures are just blocks of code that remember something from the point of their definitions and monads are a construct for "twisting" the usual function composition operation.