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

NEED URGENT HELP

Name: edo-chan 2011-12-28 11:11

sup /prog/

Ive asked this everywer already but peopl seem too lame to make even a simple program like so i hope the mighty anon programers of 4chan are more skilled

what im trying to do is to Write a method taking two parameters x and n that computes the nth power of x without using ^ or declaring a new variable inside the method or using Math lib.
and it has to be coded in JAVA (i know it sux but dont ask why i use dat shit)
hep plox!

Name: Anonymous 2011-12-29 16:29

>>67
Man you're hella dumb.

you just made me miss norcal so bad right now...

Name: Anonymous 2011-12-29 16:30

>>81
He hella mad brah.

Name: Anonymous 2011-12-29 16:30

>>78
No, but someone did pay me, and a lot I might add, to help with the programming part of SMART FIT technology.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:30

Do i even have to argue anymore? it seems it's being done for me....

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-12-29 16:33

>>84
You have no ground to stand on. You're technical responses are weak at the very best and you still haven't told any of us what you do for a living. Are you ashamed of the fact that you have a general labor job?

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:36

I don't do anything for a living... im a student and proud of it... i do have one question to ask you
>>85
When you worked on that kodak thingy-muh-bobbers did you actually "code " it or did you just pressed the button that said compile...

Name: Anonymous 2011-12-29 16:37

>>83
So you're rich and can have as many KODAK MOMENTS (tm) as you want, yet here you are, browsing /prog/.

Name: Anonymous 2011-12-29 16:38

>>73
/g/ /a/ /c/
please go back to the imageboards you faggot

this is for real programmers

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:39

. . . .. . . . . . . . . . . ,.-‘”. . . . . . . . . .``~.,
. . . . . . . .. . . . . .,.-”. . . . . . . . . . . . . . . . . .“-.,
. . . . .. . . . . . ..,/. . . . . . . . . . . . . . . . . . . . . . . ”:,
. . . . . . . .. .,?. . . . . . . . . . . . . . . . . . . . . . . . . . .\,
. . . . . . . . . /. . . . . . . . . . . . . . . . . . . . . . . . . . . . ,}
. . . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . . ,:`^`.}
. . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . ,:”. . . ./
. . . . . . .?. . . __. . . . . . . . . . . . . . . . . . . . :`. . . ./
. . . . . . . /__.(. . .“~-,_. . . . . . . . . . . . . . ,:`. . . .. ./
. . . . . . /(_. . ”~,_. . . ..“~,_. . . . . . . . . .,:`. . . . _/
. . . .. .{.._$;_. . .”=,_. . . .“-,_. . . ,.-~-,}, .~”; /. .. .}
. . .. . .((. . .*~_. . . .”=-._. . .“;,,./`. . /” . . . ./. .. ../
. . . .. . .\`~,. . ..“~.,. . . . . . . . . ..`. . .}. . . . . . ../
. . . . . .(. ..`=-,,. . . .`. . . . . . . . . . . ..(. . . ;_,,-”
. . . . . ../.`~,. . ..`-.. . . . . . . . . . . . . . ..\. . /\
. . . . . . \`~.*-,. . . . . . . . . . . . . . . . . ..|,./.....\,__
,,_. . . . . }.>-._\. . . . . . . . . . . . . . . . . .|. . . . . . ..`=~-,
. .. `=~-,_\_. . . `\,. . . . . . . . . . . . . . . . .\
. . . . . . . . . .`=~-,,.\,. . . . . . . . . . . . . . . .\
. . . . . . . . . . . . . . . . `:,, . . . . . . . . . . . . . `\. . . . . . ..__
. . . . . . . . . . . . . . . . . . .`=-,. . . . . . . . . .,%`>--==``
. . . . . . . . . . . . . . . . . . . . _\. . . . . ._,-%. . . ..`

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-12-29 16:40

>>86

>did you just pressed the button that said compile...

You're also naive to the real world. Has anyone ever shown you have code gets built out in the real world? Maybe you should see if you can take a tour of IBM or Microsoft you halfwit.

Also, I wrote some code, because that is what I'm getting paid to do. Now do society a favor and not become a programmer. For whatever reason, this doesn't seem to be your think. Maybe you should take up something a bit easier. Say like being a business major.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:41

I do believe that i am a real programmer. I only browse /a/ /c/ /g/ because i do appreciate a good fan art of the manga variety and the technology board isn't that bad.

Name: Anonymous 2011-12-29 16:43

>>91
You aren't a real programmer until you do the stuff for a living you idiot. I hate to break it to you, but there is a vast difference between writing simple toys programs found in your typical computer programming books and writing real world programs.

Name: Anonymous 2011-12-29 16:43

Hey kodak, how many times did the SMART FIT bug out and fill your albums with creepy stock photos of black children playing while adults watch in the background smiling? Before you got it right, that is.

Name: isMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:44

>>90
Just asking an honest question... Wasn't sure given your knowledge of the subject.I wouldn't want to go to microsoft but IBM sounds nice... Unfortunately i don't live close to either so ill have to take you up on your offer later. Though i will be a programmer for Google upon graduation. If you would like in a couple of years you can stop by Googleplex and i give you a free tour of Google.

Name: Anonymous 2011-12-29 16:44

>>92
Do you seriously still have to type your entire name and tripcode every time you post? What browser do you use Kodak-san?

Name: Anonymous 2011-12-29 16:45

>>93
Hush you.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:46

>>91
Well then i'd like a correction.. I'm am an aspiring programmer... Does that fit better?

Name: Anonymous 2011-12-29 16:47

>>96
Because it happened to me once, is there a place I can file bug reports?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-12-29 16:48

>>94
I doubt it. You still can't figure out how to solve the OP's problem. By the way, it can be done without recursion, and yes, you don't need to introduce any new variables! Geeze, if you can't figure out a somewhat easy puzzle, how the hell do you expect to be able to answer the really challenging questions during the Google interview?

Name: Anonymous 2011-12-29 16:48

>>93
Stock photos always creep me out like that, it's like the adults are there smiling at this random kid who they don't even know.

Name: Anonymous 2011-12-29 16:48

>>95
I use IE.

Name: --- 2011-12-29 16:48

Check em' binary literal for a prime number.

Name: Anonymous 2011-12-29 16:49

>>101
So IE doesn't offer you auto-fill on /prog/, or did you turn it off?

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:50

i know it can be done without recursion. Thank you for your concern in my future affairs with google. It is nice to know that people here are helpful enough to provide suggestions and go over this ordeal with me. I am an aspiring programmer i know this to be true and i don't understand how someone who has worked long and hard on such successful software as SmartFit (TM) can't understand a simple statement as such...

Name: Anonymous 2011-12-29 16:50

>>103
I turned it off.

Name: Anonymous 2011-12-29 16:51

>>104
Then why can't you write it? The solution you posted isn't correct.

Name: Anonymous 2011-12-29 16:52

>>104
Well, again, at least I know enought about programming to be able to do it for a living. And what the hell? You still use notepad? Are you too stupid to learn a proper editor like vi or emacs?

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:52

By what do you mean?? Ohh... yes i noticed there was an error in their later on... i rewrote it but i was in such a heated discussion i hadn't reposted it...

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2011-12-29 16:53

>>108
YOUR GOD DAMN PROGRAM ISN'T THE CORRECT SOLUTION. WHICH PART OF THIS DON'T YOU UNDERSTAND YOU STUPID FUCKER?

Name: Anonymous 2011-12-29 16:54

>>69

the recursive ones that don't use tail recursion that also make p recursive calls will likely stack overflow for large values of p. But if you use a solution that only makes log(p) recursive calls, you are likely safe. Anyways, I think that one can be made tail recursive. You just have to go from the most significant bits down to the least significant bits:


unsigned long long square(unsigned long long x) {
  return x*x;
}

unsigned long long power_(unsigned long long x, unsigned long long p, unsigned long long bit_mask, unsigned long long accumulation_product) {
  if(bit_mask == 0) {
    return accumulation_product;
  } else if(p & (1<<bit_index)) {
    return power_(x, p & ~bit_mask, bit_mask, accumulation_product*x);
  } else {
    return power_(x, p, bit_mask>>1, square(accumulation_product));
  }
}


I should test this though. Also there is a chance to optimize the odd case.

(x)^(2n+1) = (x^(2n))*x = ((x^(n))^2)*x = x*square(power(x,n))

so it would go to the next bit, regardless if it was even or odd, rather than making the odd power even and relying on the next recursive call to go to the next bit.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:54

>>107
I use notepad because i don't want to be distracted by the features that modern day IDE's envelope one with. For example.. the problem with netbeans that you talked about earlier... System.out.println(someMethodReturningAnInt()); comes out as an error but when compiling command line and writing in notepad one does not have to deal with these falsifications

Name: Anonymous 2011-12-29 16:55

>>108
As an apology to Kodak-san I think you should make him a small Kodak Gallery Photo Book using Smart Fit technology, it's really affordable right now just $8.99 I think he would really like it.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:56

>>112
I will get the duck tape...

Name: Anonymous 2011-12-29 16:56

>>111
Uh.... please tell me that you're really not this god damn stupid.

Name: Anonymous 2011-12-29 16:56

>>110

wupsy, forgot the actual power function:


unsigned long long power(unsigned long long x, unsigned long long p) {
  return power_(x, p, ((unsigned long long)1)<<((sizeof(unsigned long long)*8)-1), 1);
}

Name: Anonymous 2011-12-29 16:56

>>112
Don't fill it with creepy stock photos of black children smiling I don't think he likes that.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 16:57

>>116
wouldn't dream of it
>>114
what do you mean?

Name: Anonymous 2011-12-29 17:00

>>117
You're stupid. You're justifications for using notepad reflect the fact that you really are ignorant to what goes on. Why don't you just fucking leave here and actually learn about editors.

Name: IisMathwizard !!b/mIEkVC6+3Cvk1 2011-12-29 17:02

I have learned about the editors and i do, as mentioned a while back, have netbeans and eclipse. I use notepad because i am a fan of writing everything from scratch. i don't understand why not appreciating "extra features" is a crime???

Name: Anonymous 2011-12-29 17:02

>>63
You know the best thing about you trying to act like you know shit is that your code didn't event work properly, i even copied and pasted it just to make sure i didn't type it wrong:



[ Thu Dec 29 04:58:03 ]
[ @ ~/host/prog ] $ cat pow.java
public class pow
{
    public static void main(String args[])
    {
        int
            x = Integer.parseInt(args[0]),
            n = Integer.parseInt(args[1]);
        System.out.println("FOR:"+powi(x,n));
        System.out.println("REC:"+powr(x,n));
    }

    public static double powr(int x,int n)
    {
        if(x == 1 || n == 0) return 1.0;
        return n < 0 ? (1.0/(powr(x,-n-1)*x)) : powr(x,n-1)*x;
    }

    public static double powi(int x,int n)
    {
        int count = 0;
        boolean neg = false;
        if(n == 0){
            return 1;
        }
        if(n < 0){
            n = -1 *n;
            neg = true;
        }
        for(;count < n-1; count ++){
            x*=x; //<-- this is your poor mistake, so much for being good at Math
        }
        if(neg){
            return (1/(double)x);
        }
        return x;
    }
}
[ Thu Dec 29 04:59:38 ]
[ @ ~/host/prog ] $ java pow 2 2
FOR:4.0
REC:4.0
[ Thu Dec 29 04:59:42 ]
[ @ ~/host/prog ] $ java pow 2 4
FOR:256.0    <--- WRONG
REC:16.0
[ @ ~/host/prog ] $ java pow 10 12
FOR:0.0      <--- Your own example didn't even work
REC:1.0E12
[ Thu Dec 29 05:00:02 ]
[ @ ~/host/prog ] $ java pow 2 560
FOR:0.0
REC:3.7739624248215414E168    <-- So much for that stack overflow....

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