• Stars
    star
    7
  • Rank 2,294,772 (Top 46 %)
  • Language
    Scala
  • License
    Other
  • Created about 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Playing with primes using scala language. Draw Ulam spiral, ...

primes tests License Maven

Playing with primes using scala language. Draw Ulam spiral, ...

To generate a 1000x1000 ulam spiral use :

$ sbt "run 1000"

It will generate a PNG image file named "ulam-spiral-500.png"

To starts the console and play with primes :

$ sbt console"

scala> val ngen = new PrimesGenerator[Long]
ngen: fr.janalyse.primes.PrimesGenerator[Long] = fr.janalyse.primes.PrimesGenerator@27313524

scala> import ngen._
import ngen._

scala> primes.to(LazyList)(500)
res0: Long = 3581

scala> primes.take(15).toList
res1: List[Long] = List(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)

scala> sexyPrimes.take(5).toList
res2: List[Long] = List(5, 7, 11, 13, 17)

scala> isolatedPrimes.take(10).toList
res3: List[Long] = List(23, 37, 47, 53, 67, 79, 83, 89, 97, 113)

scala> checkedValues.filter(_.isPrime).find(_.nth==100000)
res4: Option[fr.janalyse.primes.CheckedValue[Long]] = Some(CheckedValue(1299709,true,100000))

scala> checkedValues.filter(_.isPrime).to(LazyList)(0)
res5: fr.janalyse.primes.CheckedValue[Long] = CheckedValue(2,true,1)

scala> checkedValues.filter(_.isPrime).to(LazyList)(99)
res6: fr.janalyse.primes.CheckedValue[Long] = CheckedValue(541,true,100)

scala> checkedValues.filter(!_.isPrime).drop(1000).take(10).mkString("\n")
res7: String = 
CheckedValue(1198,false,1001)
CheckedValue(1199,false,1002)
CheckedValue(1200,false,1003)
CheckedValue(1202,false,1004)
CheckedValue(1203,false,1005)
CheckedValue(1204,false,1006)
CheckedValue(1205,false,1007)
CheckedValue(1206,false,1008)
CheckedValue(1207,false,1009)
CheckedValue(1208,false,1010)

scala> checkedValues.filter(_.isPrime).drop(10000).take(10).mkString("\n")
res8: String = 
CheckedValue(104743,true,10001)
CheckedValue(104759,true,10002)
CheckedValue(104761,true,10003)
CheckedValue(104773,true,10004)
CheckedValue(104779,true,10005)
CheckedValue(104789,true,10006)
CheckedValue(104801,true,10007)
CheckedValue(104803,true,10008)
CheckedValue(104827,true,10009)
CheckedValue(104831,true,10010)

scala> mersennePrimes.take(8).toList
res6: List[Long] = List(3, 7, 31, 127, 8191, 131071, 524287, 2147483647)
  (for mersenne primes, switch to BigInt...)

scala> val dp = new PrimesDefinitions[BigInt]()
scala> dp.eratosthenesSieve(100).last
res0: fr.janalyse.primes.CheckedValue[BigInt] = CheckedValue(100,false,3,74)

scala> ulamSpiralToPngFile(500, checkedValues, "ulam-spiral.png")

scala> sacksInspiredSpiralToPngFile(500, 3, checkedValues, "ulam-sacks-like.png")

  

and so one...

More Repositories

1

jassh

High level scala SSH API for easy and fast operations on remote servers.
Scala
71
star
2

code-examples-manager

Software tool to manage your notes, scripts, code examples, configs,... to publish them as gists or snippets
Scala
37
star
3

zio-lmdb

Lightning Memory Database (LMDB) for scala ZIO
Scala
36
star
4

jajmx

scala JMX API
Scala
31
star
5

sotohp

Photos management
Scala
27
star
6

scala-drools-dummy-project

Minimalist scala drools project
Scala
19
star
7

coursier-launcher

coursier docker container for efficient application or service download and startup
Makefile
9
star
8

zwords

A wordle game for communities
Scala
8
star
9

jaseries

scala API for time numerical series operations.
Scala
7
star
10

zio-worksheet

Simplified ZIO user experience in REPL, worksheet or script contexts
Scala
6
star
11

bootstrap

scala script bootstrap mechanism with #include support
Scala
6
star
12

the-weakest-link

Scala
4
star
13

custom-collection

Custom scala collection examples
Scala
4
star
14

scala-dummy-project

scala dummy project with standalone executable jar
Shell
3
star
15

drools-scripting

Drools made easy to use for scripting or testing purposes
Scala
2
star
16

codingame-with-scalakit-example

codingame scalakit example using git submodule to reference the scalakit
Scala
2
star
17

simple-plugin-architecture

Scala simple plugin architecture (with plugin automatic compilation if required)
Scala
2
star
18

exproxy

a 2005 personal project...
Java
2
star
19

cntlm

dockerized cntlm
Shell
2
star
20

primes-scalatra-app

Scala
1
star
21

naturalsort

scala naturalsort algorithm
Scala
1
star
22

web-echo

A websocket/webhook JSON data recorder with API
Scala
1
star
23

akka-sandbox

temporary project to test and learn AKKA 2
Scala
1
star
24

advent-of-code-2023

Scala
1
star
25

bullyboy

sha1 brute force attack
Scala
1
star
26

the-rules-for-good-code-examples

Several rules to write the best possible source code examples
1
star
27

data-recorder

Scala
1
star
28

advent-of-code-2020

Scala
1
star
29

jenkins-phantomjs-slave

jenkins slave with phantomjs 1.9 docker image
1
star
30

dock-primesui

Shell
1
star
31

jenkins

Jenkins docker image
Shell
1
star