Giter Site home page Giter Site logo

prime-stepper's Introduction

prime-stepper

What does it do?

Why develop a program that lists prime numbers when you can instead write a program that lists how many steps it takes to get to the next prime number? This results in the same information but compressed down quite a bit.

For instance, instead of returning the first 20 primes:

2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71

Why not instead return the steps it takes to get to the next prime, start at 1?

1,1,2,2,4,2,4,2,4,2,4,2,6,4,2,4,6,6,2,6

Already, just in the first 20, you can see that the information is compressed. With a larger example you would see a much larger compression.

This program returns the first x steps you request starting at 1. So to get the above first 20 steps, just run:

prime-stepper 20

If you want to start at another number other than 1, add that as a second argument:

# Return next 20 steps, but starting at 1000 instead of 1.
prime-stepper 20 1000

And that's it.

Why?

I wrote this as a quick utility to spit out the first million steps starting at 100,000. This data was then used in my HTML5 pixi-prime-viewer application. Check out a demo here.

Prerequisites

You'll need to install leiningen to run or build this app. Try running the lein command from your terminal to see if you already have it installed.

Usage

To get started without having to build a jar, simply run:

lein run <steps> [<start]>

where steps is the number of steps to generate and start is what number to start from. start defaults to 1 if not provided.

If you want to have a jar that you can copy to other systems and run whenever, build a jar:

lein uberjar

This will spit out a jar file in the target/uberjar/ directory. Use this standalone jar anywhere that java is installed:

java -jar target/uberjar/prime-stepper-0.1.0-standalone.jar <steps> [<start>]

Examples

Using leiningen:

# Generate 5 steps starting at 1
> lein run 5
1,1,2,2,4

# Same thing.  Explicitly set start at 1
> lein run 5 1
1,1,2,2,4

# Generate 5 steps starting at 7
> lein run 5 7
4,2,4,2,4

Using jar:

# Generate 5 steps starting at 1
> java -jar prime-stepper-0.1.0-standalone.jar 5
1,1,2,2,4

# Same thing.  Explicitly set start at 1
> java -jar prime-stepper-0.1.0-standalone.jar 5 1
1,1,2,2,4

# Generate 5 steps starting at 7
> java -jar prime-stepper-0.1.0-standalone.jar 5 7
4,2,4,2,4

License

Copyright (c) 2015 Alfred J Fazio

Distributed under the MIT License

prime-stepper's People

Contributors

afazio avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.