GithubHelp home page GithubHelp logo

smgladkovskiy / 3nplus1 Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 42 KB

Realisation of Collatz conjecture (or 3n+1 problem) written on go.

License: MIT License

Go 91.80% Makefile 8.20%
3nplus1-problem collatz-conjecture ulam-conjecture kakutani-s-problem thwaites-conjecture hasse-s-algorithm syracuse-problem hailstone-sequence hailstone-numbers

3nplus1's Introduction

3n+1 problem

Realisation of Collatz conjecture (or 3n+1 problem) written on go.

Program tries to iterate through numbers from 1 to X and run recursive cycle with conditions:

  • if number is odd it multiplied by 3 and add 1
  • if number is even it divided by 2
  • if resulted number is 1 cycle ends
  • else resulted number passed on the entry of the same cycle

As a result, the program displays:

  1. number it reached in the iteration
  2. time it took to iterate
  3. an amount of numbers in all iterations
  4. the largest number that was reached during the iteration
  5. ten most used while iterating numbers (too much time to wait this data)

How to run

To run iterations to the number 10 with defined power, run:

make run_iterator MAXIPOWER=6

or with go run:

go run main.go iterator --max-power 6

To make run with profiling, use make command run_iterator_profiled.

To investigate profiling data run:

make profile_cpu

or

make profile_mem

for CPU or Memory profiling.

Current results

As for now, algorithm counts numbers on 6 cores Intel Core i7 macbook pro:

  • from 1 to 10e6 in about 0.9-2 seconds
  • from 1 to 10e7 in about 10-13 seconds
  • from 1 to 10e8 in about 1m50s-2m30s
  • from 1 to 10e9 in about an hour o so
  • from 1 to 10e10 already more than I can wait :)...

it optimized to run from the beginning (1) to the end. So, iterating from 10e7 to 10e8 takes more than hour instead of couple minutes.

Trying to optimize it more...

3nplus1's People

Contributors

smgladkovskiy avatar

Stargazers

 avatar  avatar

Watchers

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