Giter Site home page Giter Site logo

zentrocdot / prime-numbers Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 181 KB

Calculation of Prime Number s using bash

Home Page: https://launchpad.net/~zentrocdot/+archive/ubuntu/prime-numbers/+packages

License: MIT License

Shell 31.44% Roff 15.59% Makefile 3.24% Euphoria 43.99% Elixir 5.74%
bash composite-number composite-numbers natural-number prime-number prime-numbers python sieve sieve-of-eratosthenes

prime-numbers's Introduction

README

The program prints the prime numbers in a given range from 0 to n. The number separator in the output is a simple space.

Motivation

Motivation was to writing a simple program for calculating prime numbers which are printed in one line without a trailing line break. The program is intended to work as simple generator of prime numbers for other scripts. For prime numbers less than 100000 the underlying algorithms is fast enough.

Pseudo Code

Underlying algorithm as pseudo code

Data: Integer number n
Output: Prime numbers smaller than n
Function: prime_numbers
    A ← array of size n with boolean values set to true
    for i ← 2 to √n do
        if A[i] is true then
            j ← i * i
            while j ≤ n do
                A[j] ← false
                j ← j + 1
            end
        end
    end    
    return array with prime numbers and composite numbers
end

Output format

A simple call looks like:

hades@hades:~$ prime_numbers
hades@hades:~$ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97hades@hades:~$

Without given boundary prime_numbers print the primes in a range of 0 to 100.

A call with a boundary looks like:

hades@hades:~$ prime_numbers 1000
hades@hades:~$2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 
109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239
241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 
389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 
547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 
691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 
859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997hades@hades:~$ 

The prime numbers in a range of 0 to 1000 are printed without line break.

Outstanding issues

Writing this program I had in mind to compare the results from Bash with other programming languages like Python and C/C++. Open issue is the question how the memory managment can be optimised. It is also of interest how the calculation time can be reduced by change of the programming language and by modifying the code.

To-Do

The range of calculated prime numbers should be variable in the future. It should also be possible to get prime numbers or composite numbers. It should also be possible to consecutive prime numbers. And the program should be able to print the number of counted prime numbers or composite numbers. The package needs also a function if a number is a prime number or a composite number.

Other Prime Number Programs

I found so far two over Ubuntu installable programs with which prime numbers can be calculated [1,2].

References

[1] manpages.ubuntu.com/manpages/noble/en/man1/primesieve.1.html

[2] manpages.ubuntu.com/manpages/noble/man1/matho-primes.1.html

See also

[GT] github.com/guidotheelen/prime_numbers/blob/master/lib/prime_numbers.dart

[RM] rimonmostafiz.github.io/blog/sieve-of-eratosthenes-memory-efficient-implementation/

[BG] www​.baeldung.com/cs/prime-number-algorithms


It would be grateful if you decide to support the work here.


If you like what I present here, and if it helps you above, donate me a cup of coffee ☕.
I drink a lot of coffee while programming and writing 😃.

Buy Me A Coffee

I loved the time when you could get also a hamburger 🍔 for one euro!


Here are some other good ways to simply donate a coffee to me via my favourite coins 💰.

TQamF8Q3z63sVFWiXgn2pzpWyhkQJhRtW7 Tron
DMh7EXf7XbibFFsqaAetdQQ77Zb5TVCXiX Doge
12JsKesep3yuDpmrcXCxXu7EQJkRaAvsc5 Bitcoin
0x31042e2F3AE241093e0387b41C6910B11d94f7ec Ethereum

Page last modified 10/03/2024

prime-numbers's People

Contributors

zentrocdot 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.