I am currently learning Ruby and I am wondering whether you guys can suggest some medium to difficult iterators to implemet?
Thanks
There are http://rubyquiz.com/ and more generic http://projecteuler.net/. You will find different exercises in them that you can solve using iterators, recursion, or something else.
Try mastering Enumerable.inject. It's a really helpful method that reduces LOC.
Related
This question already has answers here:
What is recursion and when should I use it?
(40 answers)
Closed 9 years ago.
I am wondering, why do people use recursion? In most of my learning experience, I've found it to be much more inefficient that iterative methods, so why do people use it? Is it because you can simply write a shorter method? Is it used in real-world programming outside the classroom setting (or learning purposes)? If it is, please provide a good example if you can, I'm very curious.
Thanks in advance for your help! I really appreciate it!
If you have a tree data structure and you want to walk over it in depth-first order, recursion is the only way to do it.
If you want to write a parser for a typical language having context-free rules, like every programming language in existence, a recursive-descent parser is a simple and natural way to do it.
There is no iterative way to do it with limited storage.
Well, for one thing, it's used in functional programming languages (like Haskell), which don't really have iteration, and they are optimized for recursion. Also, for some problems (like working with binary trees), recursions is a very natural and clean solution.
My overall experience with programming is DOM manipulation with jQuery, little Ajax with it too, also some raw javascript (codecademy course). Now I decided to learn Sinatra (read that RoR is too complex for non-savvy progammers) but I am aware that I need to understand some Ruby to start learning this framework, thus the question is how much Ruby do I need to cover?
I don't think there is a set amount. Like anything else, the more the better.
If you were to read Chris Pine's Learn to Program it would give you all the basic ruby functionality you would need to get by. It is probably the best intro to ruby book out there that will cover things like iteration, classes, methods, blocks and procs.
_why's poignant guide to ruby is a great start for learning ruby. If you want to get a handle on the language first, I'd recommend starting there. If you'd rather learn as you go, the sinatra book is free and should provide a great start.
I think you'll have a much easier time in the long run if you take a few weeks and get very comfortable in Ruby now. Work through the Ruby Monk course and don't move on from a concept until you have it. You only have to learn these concepts once and then learning additional languages is a breeze!
I'm pretty close to an exam where I have to answer some questions about Haskell and Prolog.
I would like to find a web like "learnyouahaskell" but about Prolog.
I don't know why logical languages are harder for me, they aren't logical for my knowledge =.=
Any recommends?
Thanks in advance.
I think that the equivalent of leanyouahaskell would be Learn Prolog Now.
also, check this question
It might also help to re-evaluate (or rather backtrack xD) your definition of logical;
for example, when you have
x=3
2x=x+1
you would normally conclude that there is no x that satisfies this system of equations, not that x is first 3 and then 1 :b
anyway, it's true that it's a bit hard to adjust; good luck with your exam!
also this is a very good website for understanding the basics with examples, diagrams and so on:
http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html
I've been told that the best way to learn a programming language is to implement some data structures in it. I am currently learning Ruby and I would really love to code some data structures like Tries, AVL etc. Are there any sites out there which outline how to go about doing this and can suggest exercises and optimizations based on the same.
Any help would be greatly appreciated. Thanks.
You can also start with Ruby Code Kata. They are seemingly real world problems with almost always an algorithm based problem lying underneath.
There are discussion forums available there to discuss each Kata, so that your feedback loop for learning would be completed.
Here's a free online book on creating data structures with Ruby:
http://www.brpreiss.com/books/opus8/
I would recommend learning the basics first, since they lay the foundation. Start simple with things like linked lists, binary search trees, stacks etc.
You can also look at TopCoder Tutorials.
PuzzleNode.com helped me.
There are 15 problems. You can finish in a day or two, longer if you plan on test driving the solutions. I like to think of each problem as being larger than a kata, but smaller than trying to implement a tic tac toe game in Ruby. You'll be exposed to parsing in Ruby, data structures and using possibly gems based on your implementation. There also fun; good luck!
I have a vague memory of a programming language where 1..10 meant "the range 1 inclusive to 10 exclusive", similar to python's range(1, 10), but I haven't the foggiest which, and this doesn't particularly lend itself to searches. Any help?
If the answer's "python", please forgive me. I know very little python.
Pascal supports that syntax. You can actually use this as a type, and I believe it's also used in specifying array bounds. (I'm not sure how much of this is standard Pascal and how much is Turbo Pascal extensions.)
Haskell does it.
It is Perl, called the "Range Operator"
http://www.cs.cf.ac.uk/Dave/PERL/node38.html
Groovy uses this syntax, too.
http://groovy.codehaus.org/Collections
F#, they are called Sequence Expressions
http://msdn.microsoft.com/en-us/library/dd233209.aspx (select the F# examples to see the code)
Ruby!
Since the OP already got the answer they were looking for, and this has kind of become a list of languages that use 1..n syntax, I'll add one more.
Maple
The wiki page shows a good example
myfac := n -> product( i, i=1..n );
Note however that this is 1 to 10 inclusive
Ruby has VERY similar syntax...
You can read more here:
http://www.ruby-doc.org/core/classes/Range.html
If it's a vague and distant memory, then I'd guess that Pascal or Delphi is the most likely candidate for the language you're thinking of.
It's most commonly used in Pascal in a case statement. See here for example syntax: http://en.wikipedia.org/wiki/Switch_statement#Pascal
It could also be any of a number of other languages that use this syntax, but without knowing a bit more about your programming history, my guess would still be Pascal / Delphi.