Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Perl to Java

Name: Anonymous 2012-02-22 11:29

How would this perl code look like in Java?

http://pastebin.com/GPzQFxPL

Name: Anonymous 2012-02-22 11:36

'my' should be outside the parentheses FYI

Name: Anonymous 2012-02-22 11:39

(defun recur (m n)
  (if (= n m)
    (progn
      (dotimes (i m)
        (write-string "*"))
      (terpri))
    (progn
      (dotimes (i m)
        (write-string "*"))
      (terpri)
      (recur (incf m) n)
      (dotimes (i (- m 1))
        (write-string "*"))
      (terpri))))

(recur 3 5)

Name: Anonymous 2012-02-22 11:45

>>3
Oh you.

Name: Anonymous 2012-02-22 11:51

Learn D

Name: Anonymous 2012-02-22 12:00

>>2
Okay.

I also derped the title.

Name: Anonymous 2012-02-22 12:56

You must be retarded. I've written this in four minutes and I have exactly one week of Java experience. You already have the algorithm, just do it the same fucking way, unless you're too stupid to use a for loop. In that case, kill yourself.

Name: Anonymous 2012-02-22 13:54

More text triangles? Is Kodak still practicing?

Name: Anonymous 2012-02-22 17:03

>>3
How do you configure Emacs to indent branches of the if macro by two spaces instead of four?

Name: Anonymous 2012-02-22 17:07

>>8
I bet you can't tell me the basic algorithmic framework that was used for my triangle code! Yes, it's that fucking elite, because I can draw pretty much any triangle based off that framework.

Name: Anonymous 2012-02-22 18:30

>>9
By using vim.

Name: Anonymous 2012-02-22 18:55

>>11
Vim doesn't even have Lisp-aware indenting. It also doesn't have paredit mode or colorized faces, and it doesn't work inside eshell so I have to open a separate terminal. Why would I use it?

Name: Anonymous 2012-02-22 18:57

>>7
>I've written this in four minutes and I have exactly one week of Java experience
Sure...

Name: FEAR_MY_TRIANGLE 2012-02-22 19:29


#include <iostream>
using namespace std;

int main(void)
{
    int r, c;
    int n = 9;
   
    for (r = 1; r <=n; r++, cout << endl)
        for (c = 1; c <=n; c++)
            cout << (r == 1 || r == n ||
                 (r <= c && r + c <= n + 1) ||
                 (r >= c && r + c >= n + 1 ) ? '*' : ' ');
   
    return 0;  
}

Name: Anonymous 2012-02-22 19:33

Programming newfag here.

If the code has a for/while loop, can it still be considered as a recursion?

Name: Anonymous 2012-02-22 20:17

>>15
As long as it calls itself, it's recursion. So, possibly.

Name: Anonymous 2012-02-22 20:20

>>15
A recursive function is allowed to have a loop in it, but that would be kind of confusing. Loops and recursion are two high-level ways of looking at the same thing. You generally pick one or the other to implement a particular algorithm so someone reading the code doesn't have to mentally translate between the two to figure out what's going on.

If loops are the only control flow being used, like in >>14, then it's not recursion at all!

Name: Anonymous 2012-02-22 20:33

>>17
How do you figure you no talent bitch? There are some depth and breadth first search algorithms that have for loops in the the recursion. If I wouldn't know better, I would almost thing that you are kind of slow when it comes to computer programming.

Name: Anonymous 2012-02-22 20:37

>>18
no talent bitch
Cut that out.

Name: Anonymous 2012-02-22 20:39

>>19
I'm not the one making the idiot staments. Geeze, maybe you should in fact read a book. My gosh you are one stupid human being.

Name: Anonymous 2012-02-22 20:45

>>20
er *idiotic*

Name: Anonymous 2012-02-22 20:48

>>19
Don't get all defensive just because he called you out. Admit you were wrong and let him feel your tits. And then, go back to school and learn to use a computer.

Name: Anonymous 2012-02-22 20:50

inb4 Kodak-san derails the entire thread for 100 posts

Name: Anonymous 2012-02-22 20:53

>>22
Huh? Tell us again how using a for loop in recursion is confusing you no talent bitch.

Name: Anonymous 2012-02-22 20:53

>>18
There are some depth and breadth first search algorithms that have for loops in the the recursion.
I'm sure there are. Can't think of any right now. Say what you like about my failure to memorize all the algorithms I might ever need instead of consulting my books now and then.

Anyway I would argue that such algorithms are probably confusing. Wanna post a couple?

Name: Anonymous 2012-02-22 20:56

pearls before swine in hipster coffee hmmm I wonder how that will turn out

Name: Anonymous 2012-02-22 20:58

>>25
Your problem is that you don't think before you post.

Name: Anonymous 2012-02-22 21:01

Name: Anonymous 2012-02-22 21:01

>>25
Are you fucking serious? Tell me what code you wrote so I know to go noewhere near it

Twist ending: >>25 has never written a line of code ever

Name: Anonymous 2012-02-22 21:03

>>25
reported

Name: Anonymous 2012-02-23 1:10

Name: Anonymous 2012-02-23 5:30

public class Main {
    private static recur(int m, int n) {
        if(m == n) {
            for(int i = 0; i < m; i++) System.out.print("*");
            System.out.println();
        }
        else {
            for(int i = 0; i < m; i++) System.out.print("*");
            System.out.println();
            recur(++m, n);
            for(int i = 0; i < m - 1; i++) System.out.print("*");
            System.out.println();
        }
    }
    public static void main(String[] args) {
        recur(3, 5);
    }
}

Name: Anonymous 2012-02-23 5:31

>>16
Not true. I take it you haven't red you're SICP today?

Name: Anonymous 2012-02-23 10:00

>>33
haven't read you're SICP
you're SICP
I AM SICP, MOTHERFUCKER

Name: Anonymous 2012-02-23 11:25

>>34
Much better. 7/10.

Name: Anonymous 2012-02-23 13:15

>>35
I try my best.

Don't change these.
Name: Email:
Entire Thread Thread List