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

Can /prog/ please comment on my code?

Name: Anonymous 2010-08-02 19:20


class prob3{
   
    static long BigBossPrimeOne;
   
    public static void primeFactor(long n){
    boolean prime = true;
    long n1=0;
    long n2=0;
    for(long i=2;(i<=(n/2))&&(prime!=false);i++)
        if ((n%i)==0){
        prime = false;
        n1=i;
        n2=n/i;   
        }   
    if ((prime==true)&&(n>BigBossPrimeOne))
        BigBossPrimeOne = n;
   
    if (prime==false){
        primeFactor(n1);
        primeFactor(n2);
        }            
    }

    public static void main(String args[]){
 
    primeFactor(600851475143L);
    System.out.println(BigBossPrimeOne);
    }

}


I'm just doing the Euler thing to pass the time and I thought why not post this on /prog/ for some insight.

Using the Java language.

Feel free to give me any advice.

Thanks!

Please don't mind the presentation. It's the first time using Emacs and I was under the clock (did this in 15 minutes).

Name: Anonymous 2010-08-03 6:51

>>37 Ok, its now converted to Purebasic4.5 and added a CPU speed for speedstep/dynamic mhz detection.

Procedure GetCycleCount():  !RDTSC  
::ProcedureReturn:EndProcedure;
Procedure CPUSPEED(): Protected A.q,B.q: time_fix2:A = GetCycleCount(): Sleep_(100): B = GetCycleCount():While (B-A)<1: Goto time_fix2:Wend: ProcedureReturn (B-A)/100000:EndProcedure;
Define.q n,i=5,s=2,starttime,endtime:OpenConsole():If CountProgramParameters():n.q=Val(ProgramParameter()):Else:n.q=600851475143:EndIf:starttime=GetCycleCount():
While n<>2 And (Not (n%2)) :n=n>>1::Wend:While n<>3 And (Not (n%3)) :n=n/3::Wend:
While ((i*i)<=n) :While n<>i And (Not (n%i)) :n=n/i::Wend:: s=s!2: i=i+s+2:Wend:endtime=GetCycleCount()-starttime:
PrintN(Str(n)):PrintN("Elapsed:"+Str(endtime)+" cycles at speed "+Str(CPUSPEED())+" MHZ"):

Name: Anonymous 2010-08-03 7:27

>>41
Too bad cause PureBasic is 3 times slower than GCC

Name: Anonymous 2010-08-03 7:56

Old crap from when I did that problem:

import Prelude hiding (all, filter, takeWhile, last)
import Data.List.Stream
n = 600851475143

primeFactors = [x | x <- [3..floor $ sqrt $ fromIntegral n],
               n `mod` x == 0, isPrime x]

main = print $ last primeFactors

primes :: [Int]
primes = 2 : filter isPrime [3,5..]

isPrime :: Int -> Bool
isPrime n = all ((/=0) . mod n) $ takeWhile (\p -> p*p <= n) primes


% time (for i in `seq 1 1000`; do ./a.out >/dev/null; done)
0,26s user 1,09s system 95% cpu 1,412 total
% time (for i in `seq 1 1000`; do ./3 >/dev/null; done)
32,64s user 2,21s system 90% cpu 38,368 total

Name: Anonymous 2010-08-03 7:58

JavaScript conversion(which is faster than java unsurprisingly)
n="600851475143",i=5,s=2;start=new Date();
while((n!=2)&&(!(n%2))) n>>=1;;while((n!=3)&&(!(n%3))) n/=3;;
while((i*i)<=n){while((n!=i)&& (!(n%i)))n/=i;;i+=2+(s^=2);}
end=new Date();alert(n+ "Elapsed:"+(end-start)+" ms");

Name: Anonymous 2010-08-03 11:03

>>40

I think >>39 was joking.

Name: Anonymous 2010-08-03 12:49

>>45
I think >>38 was too, what with his "cleaner" code being less readable than >>21. Some kind of parody of ENTERPRISE coding standards or something.

>>38
int main() is wrong. it should always be either int main(void) or int main(int argc, char *argv[argc]).

Name: Anonymous 2010-08-03 13:13

>>46
int main(int argc, char *argv[argc])
That won't work and you should know it.

Name: Anonymous 2010-08-03 14:42

>>47
*argv[argc] is a null pointer. just saying, faggot.

Name: Anonymous 2010-08-03 14:43

>>47
It does work. The ANSI/ISO/IEC C standard guarantees it.

Name: Anonymous 2010-08-03 17:02

>>1
Euler
using the Java language
( ≖‿≖)

Name: Anonymous 2010-08-03 19:15

>>50

Makes for a more interesting challenge no?

What are you a faggot?

And besides if you ever participated in Euler you'll find that Java ISN'T the most cumbersome and sluggish language used.

Name: Anonymous 2010-08-03 19:22

>>51
Do you mean to say that you've solved every Euler project in every language conceivable, and have found some to be less efficient than Java?

Name: Anonymous 2010-08-03 20:26

>>52

derailed deduction

less efficient than Java

I believe that's 80% the programmers fault.

Name: Anonymous 2010-08-03 20:40

>>52
I can name a few that have no programs you wouldn't be hard pressed to underperform using Java. I'll start with malbolge. Should I go on?

Name: Anonymous 2010-08-03 20:53

>>52

Wait.

Are you implying that Java is the slowest widely used language?

I will give you the benefit of doubt due to my ignorance on the topic but still hardly believable.

Name: Anonymous 2010-08-03 22:16

>>51
No, I've solved a dozen or two problems.  Stop assuming, idiot.

Name: Anonymous 2010-08-03 23:16


include <stdio.h>

int main(void)
{
        unsigned long target = 600851475143L;
        unsigned int i = 1;
        unsigned int x;
        for (i = 1; target > 1; ++i)
        {
                /* already know it ain't divisble by 2, 3, or 5 */
                x = 6*i+1;
                if (0 == target % x)
                {
                        target /= x;
                }
                else
                {
                        x += 4;
                        if (0 == target % x)
                        {
                                target /= x;
                        }
                }
        }
        printf("%u\n", x);
        return 0;
}

project-euler→$ time ./a.out
6857

real    0m0.002s
user    0m0.000s
sys     0m0.004s
project-euler→$

Name: Anonymous 2010-08-04 4:37

>>53
Hardly derailed. Read >>51 again, they must have used Java as well as some other language in order to come to that conclusion.
In fact, >>51 didn't say “participated in Euler using Java”. His conclusion doesn't follow the rest of his post.
>>54
You're multiple negatives are confusing. What?
>>55
I'm not implying anything. In fact, given the absurd proposal in >>52 that >>51 has done that, I'd be implying the exact opposite if I were to imply at all.

Name: Anonymous 2010-08-12 10:13

This is the way!

Name: Anonymous 2010-08-12 14:30

It's not that hard. Here's a naive solution in CL. I like Haskell's ranges, so I decided to implement something similiar...


; euler 10

(defun square (n)
  (* n n))

(defun number-line (a b)
  (let ((numbers
     (make-array 1 :fill-pointer 0 :adjustable t)))
    (do ((i a (1+ i)))
    ((> i b) numbers)
      (vector-push-extend i numbers))))

(defun move-up (item sequence)
  (elt sequence (1+ (position item sequence))))

(defun multiple-p (n b)
  (and (/= n b) (= (mod n b) 0)))

(defun sieve-of-eratosthenes (n)
  (let ((numbers (number-line 2 n)))
    (do ((p 2 (move-up p numbers)))
    ((> (square p) n) numbers)
      (setf numbers (delete-if (lambda (x) (multiple-p x p)) numbers)))))

(defun problem-10 ()
  (reduce #'+ (sieve-of-eratosthenes 2000000)))

Name: ghd hair 2010-08-30 23:45


You can go to the party with so beautiful hair style made by ghd straighteners.Besides that, there are also several styles to choose from within the ghd hair straightener tools, one is the ghd mk4.GHD can not only create smooth, sleek and curly hair but also enable you to straighten your hair and then gives it flips, curls or waves what you want. Make sure that you hold your hair firmly when straightening your hair so that GHD can distribute heat in an even fashion.Since hair straighteners,are based on heat technology, they may damage your hair if they are not used properly.
http://www.ghdhairsonsale.com

Name: Anonymous 2010-08-31 0:58

>>64
You can go to the party with so beautiful hair style made by ghd straighteners.
FUCK YES I'VE ALWAYS WANTED BEAUTIFUL HAIR

also enable you to straighten your hair and then gives it flips, curls or waves what you want
IT JUST GETS BETTER AND BETTER

Name: Anonymous 2010-08-31 4:59

>>65
You do realize that she talks about pubic hair, don't you?

Name: Anonymous 2010-08-31 5:38

>>66
You do realize that she talks about general pubic hair, don't you?

Name: Anonymous 2010-08-31 7:58

>>67
Do you realize that she talks about GENERAL PUBIC LICENSE hair, don't you?

Name: Anonymous 2010-08-31 8:00

>>68

oh wow Shiitchan, why do you remove my [o] and [u] tags inside the [spoiler]?

Name: Anonymous 2010-08-31 8:36

>>69
I actually like it more.

Name: Anonymous 2010-08-31 9:20

>>69
WORKS ON MY MACHINE

Name: Anonymous 2010-08-31 10:23

>>69
Works on my machine. You must not be using Anonix.

Name: Anonymous 2010-08-31 20:13

>>48
Actually, *argv[argc] is a char.
argv[argc] is a null pointer (for their initial values).

Name: Anonymous 2010-12-10 16:58

Name: Anonymous 2011-02-04 15:51

Name: Anonymous 2011-02-17 20:07

that's cool and all, but check my doubles over there

Name: tiffany and company 925 2012-03-06 23:39

http://www.tiffany-cool.com                                            tiffany jewelry    
http://www.tiffany-cool.com/tiffany-silver-rings/discount-tiffany-signature-ring-black.html                                            peridot two teardrop ring
http://www.tiffany-cool.com/tiffany-silver-money-clips.html                                            tiffany and company 925

Name: North Face Pink Ribbon Denali 2012-09-27 21:26

Name: Anonymous 2012-09-27 21:30

>>1
Commented.

/*
class prob3{
   
    static long BigBossPrimeOne;
   
    public static void primeFactor(long n){
    boolean prime = true;
    long n1=0;
    long n2=0;
    for(long i=2;(i<=(n/2))&&(prime!=false);i++)
        if ((n%i)==0){
        prime = false;
        n1=i;
        n2=n/i;   
        }   
    if ((prime==true)&&(n>BigBossPrimeOne))
        BigBossPrimeOne = n;
   
    if (prime==false){
        primeFactor(n1);
        primeFactor(n2);
        }            
    }

    public static void main(String args[]){
 
    primeFactor(600851475143L);
    System.out.println(BigBossPrimeOne);
    }

}
*/

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