home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (nsieve.groovy)

This example Groovy source code file (nsieve.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

primes, primes, stringbuffer, stringbuffer

The Groovy nsieve.groovy source code

/* The Computer Language Benchmarks Game 
   http://shootout.alioth.debian.org/

   contributed by Pilho Kim
*/

def countSieve(m, primes) {
      def i, k
      def count = 0

      i = 2
      while (i <= m) { 
          primes[i] = true
          i++
      }

      i = 2
      while (i <= m) { 
         if (primes[i]) {
            k = i + i
            while (k <= m) {
                 primes[k] = false
                 k += i
            }
            count++
         }
         i++
      }
      return count
}

def padNumber(number, fieldLen) {
      def bareNumber = "" + number
      def numSpaces = fieldLen - bareNumber.length()
      def sb = new StringBuffer(" "*numSpaces)
      sb.append(bareNumber)
      return sb.toString()
}

def n = 2
if (args.length > 0) 
    n = args[0].toInteger()
if (n < 2) 
    n = 2

def m = (1<

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy nsieve.groovy source code file:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.