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

Sieve of Eratosthenes

Name: Anonymous 2006-11-19 7:22

I'm trying to write it in Java but so far it doesn't even zero multiples of 2. Halp?

import java.util.*;
public class Sito {
    public static void main(String[] args) {
    int n=10;
    int[] zbior = new int[n];
    for(int i=0;i<zbior.length;i++)
    {
        zbior[i]=i+2;
    }

    for(int i=0;i<zbior.length;i++)
    {
        System.out.print(zbior[i]+"  ");
    }
    System.out.println();
   
    int liczbaSprawdzana=0;
    zbior[5]=0;
   
    for(int i=liczbaSprawdzana+1;i<zbior.length;i++)
    {
        if (zbior[i]==0) continue; /*&&zbior[i]%zbior[liczbaSprawdzana]==0*/
        if (zbior[i]%zbior[liczbaSprawdzana]==0)
            {
                zbior[i]=0;
            }
    }
   
   
    for(int i=0;i<zbior.length;i++)
    {
        System.out.print(zbior[i]+"  ");
    }
       
    }
}

Name: java sucks 2006-11-19 7:46

java sucks.
Learn C.

Name: Anonymous 2006-11-19 8:07

>>1
Program in English you goddamn commie.

Name: Anonymous 2006-11-19 8:37

Haskell owns.

sieve :: [Int] -> [Int]
sieve [] = []
sieve (x:xs) = x : sieve (filter (\ n -> (mod n x) /= 0) xs)


sieve [2..100]
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]

(Unfortunately, I didn't find out a way of avoiding the lambda expression through function composition, anyone know how to reverse args, or something, for the modulo?)

Name: Anonymous 2006-11-19 8:40

>>4
Nevermind, flip did it after all.

Name: Anonymous 2006-11-19 13:39

Haskell is unreadable and ugly

Name: Anonymous 2006-11-19 14:01

>>6
No.

sieve (x:xs) = x : sieve (filter ((/= 0) . (flip mod x)) xs)
(Best Practice Enterprise Grade Scalable Haskell) vs. (Java that looks like C, and it doesn't use any spaces)
[/m]if (zbior[i]==0) continue; /*&&zbior[i]%zbior[liczbaSprawdzana]==0*/[/m]

Which one do you prefer? (PROTIP: The first one.)

Name: Anonymous 2006-11-20 17:37 (sage)

(/= 0)
lol is dat sum FORTRAN

Name: Anonymous 2010-12-17 1:28

Xarn is a bad boyfriend

Name: Anonymous 2010-12-21 3:57

Name: Anonymous 2011-02-04 12:54

Name: Anonymous 2011-02-04 16:19

Name: Sgt.Kabu࿳ﲫkiman唨䉫 2012-05-28 20:52

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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