Parallel Sieve of Eratosthenes in Bash

Discussion in 'NZ Computing' started by Lawrence D¹Oliveiro, Oct 2, 2004.

  1. I remember this version of the algorithm from a Comp Sci course many
    years ago. How high will it go before your system gets bogged down? :)

    Also, if anyone can suggest a fix for the stream of syntax errors that
    happen when you try to abort, I'd be grateful.

    ----
    #!/bin/bash
    if test x$1 != x; then
    read start
    echo $start
    while true; do
    read num
    echo "if ("$num" % "$start" != 0) { print "$num', "\n" }' | bc
    done | $0 $1
    else
    num=1
    incr=1
    while true; do
    num=$(echo $num + 1 | bc)
    echo $num
    done | $0 xxx
    fi
    Lawrence D¹Oliveiro, Oct 2, 2004
    #1
    1. Advertising

  2. Lawrence D¹Oliveiro

    Harry Guest

    Lawrence D¹Oliveiro wrote:

    > I remember this version of the algorithm from a Comp Sci course many
    > years ago. How high will it go before your system gets bogged down? :)
    >
    > Also, if anyone can suggest a fix for the stream of syntax errors that
    > happen when you try to abort, I'd be grateful.
    >
    > ----
    > #!/bin/bash
    > if test x$1 != x; then
    > read start
    > echo $start
    > while true; do
    > read num
    > echo "if ("$num" % "$start" != 0) { print "$num', "\n" }' | bc
    > done | $0 $1
    > else
    > num=1
    > incr=1
    > while true; do
    > num=$(echo $num + 1 | bc)
    > echo $num
    > done | $0 xxx
    > fi


    Why don't you just use a recursive macro in dc (bc is front end
    for dc)?


    3sx 100000sy 0sz
    [dd :q 2+ SlSm lmll LmLl <h] sh
    ly 1+ 3 lhx sjsj 2 2:q
    [lx ;q 0 !=b lx2+sxlx ly >a] sa
    [lx p Sp ly lxd*szlz <c] sb
    [0lz:q lxlz+sz lylz <c] sc
    2psj
    lax
    Harry, Oct 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. damon
    Replies:
    7
    Views:
    10,516
    cartersanders
    Aug 29, 2007
  2. steelneck

    Bash script and sessioncookies

    steelneck, Feb 23, 2005, in forum: Firefox
    Replies:
    2
    Views:
    1,026
    steelneck
    Feb 25, 2005
  3. Lawrence D'Oliveiro

    sieve.py

    Lawrence D'Oliveiro, Sep 30, 2005, in forum: NZ Computing
    Replies:
    0
    Views:
    482
    Lawrence D'Oliveiro
    Sep 30, 2005
  4. Lawrence D'Oliveiro

    Adobe Reader Leaks Like A Sieve

    Lawrence D'Oliveiro, Aug 7, 2009, in forum: NZ Computing
    Replies:
    2
    Views:
    317
    Lawrence D'Oliveiro
    Aug 8, 2009
  5. Lawrence D'Oliveiro

    Parallel Sieve of Eratosthenes

    Lawrence D'Oliveiro, Nov 14, 2009, in forum: NZ Computing
    Replies:
    0
    Views:
    886
    Lawrence D'Oliveiro
    Nov 14, 2009
Loading...

Share This Page