-2
1
I asked this question on programmers 10 days back but wasn't able to get the answer that I wanted.
Write program in java to print the squares of first 25 integers(1-25) without using any variables.
I am not looking for any theory explaining concepts about java or functional programming. I just want to know if its possible in java, the way the author has described in the original context.
--------Edit-------------------- Actually making it mutable variable makes it quite easy. The original context was
(take 25 (squares-of (integers))) Notice that it has no variables. Indeed, it has nothing more than three functions and one constant. Try writing the squares of integers in Java without using a variable. Oh, there’s probably a way to do it, but it certainly isn’t natural, and it wouldn’t read as nicely as my program above.
So try writing same program without using any variables.
2Isn't it just a simple recursion? I don't know much Java, so I don't want to write a real solution, but something like
printsq(from, to) { print(from*from); if (from < to) printsq(from+1, to); }
– ugoren – 2013-02-25T13:36:38.2302
Strongly related to Implement a sorting algorithm with no change, and I continue to think the whole business displays a lack of deep understanding about what your computer is doing. Furthermore, you got answers on programmers that are completely equivalent to what a pure functional language does under the hood.
– dmckee --- ex-moderator kitten – 2013-02-25T15:39:58.0771@dmckee: disagree. this is about code golf. you do it because it's fun and challenge. this is not about good design, but about creativity finding a solution to a problem that might or might not be useful to solve. – Atmocreations – 2013-05-13T18:30:23.067