Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Bit more code to share from a little exercise I was doing in Groovy-ness.

Returns a list of prime numbers between start and end (max - 2147483647 ) or if no end value is supplied works out if start is prime by returning it, in both case returns false if there are no answers.

It get slow with wide ranges or very high numbers but works right the way up the the top.

// Primes ( start ; end )
// 13_06_01 JR
// v1.0
// returns all primes between start and end
// if no value for end just works out if the start is prime 
// works up to 2147483647 (largest integer) TAKES A LONG TIME UP THERE!!

start = start.toInteger()
end = !end ? start + 1 : end.toInteger()
primes = (start..end).findAll{ it ->
	(2..<it).every { divisor ->
		it % divisor != 0
	}
}
primes ?: false

/*
long way of writing it out....
start = start.toInteger()
if (end == null){
	end = start + 1
} else {
	end = end.toInteger()
} //end if
primes = (start..end).findAll{ it ->
	(2..<it).every { divisor ->
		it % divisor != 0
	}
}
if (primes == null){
	return false
}
return primes
*/
  • 1 month later...

Hi John

 

You can speed this up fairly easily. You don't need to test all the way to the end of your number range. You can stop as soon as you reach the square root of value in your "end" variable.

 

 

 

Bit more code to share from a little exercise I was doing in Groovy-ness.

Returns a list of prime numbers between start and end (max - 2147483647 ) or if no end value is supplied works out if start is prime by returning it, in both case returns false if there are no answers.

It get slow with wide ranges or very high numbers but works right the way up the the top.

// Primes ( start ; end )
// 13_06_01 JR
// v1.0
// returns all primes between start and end
// if no value for end just works out if the start is prime 
// works up to 2147483647 (largest integer) TAKES A LONG TIME UP THERE!!

start = start.toInteger()
end = !end ? start + 1 : end.toInteger()
primes = (start..end).findAll{ it ->
	(2..<it).every { divisor ->
		it % divisor != 0
	}
}
primes ?: false

/*
long way of writing it out....
start = start.toInteger()
if (end == null){
	end = start + 1
} else {
	end = end.toInteger()
} //end if
primes = (start..end).findAll{ it ->
	(2..<it).every { divisor ->
		it % divisor != 0
	}
}
if (primes == null){
	return false
}
return primes
*/

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.