Giter Site home page Giter Site logo

dmitrytsyvtsyn / kotlin-algorithms-and-design-patterns Goto Github PK

View Code? Open in Web Editor NEW
805.0 805.0 103.0 7.15 MB

This repository contains the most common algorithms and data structures written in the Kotlin language with simple and concise code.

License: MIT License

Kotlin 100.00%
abstract-factory-pattern adapter-pattern algorithm algorithms algorithms-and-data-structures builder-pattern command-pattern data-structures decorator-pattern design-pattern design-patterns facade-pattern flyweight-pattern kotlin observer-pattern singleton-pattern strategy-pattern

kotlin-algorithms-and-design-patterns's People

Contributors

dmitrytsyvtsyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlin-algorithms-and-design-patterns's Issues

observers must be declared as set

private val observers = mutableListOf() // in this line use of mutableSetOf is needed

override fun observe(observer: Observer) {
observers.add(observer)//'cause you can add same observer many times
}

Naive factorial implementation

The current implementation of factorial has two problems:

  1. It demonstrates literally nothing except the factorial's definition. To be meaningful it should contain some optimizations like prime factorization.
  2. It uses Int, hence it is correct only in [ 0 .. 12 ] range.
    image
    Even using ULong will allow values only from 0 to 20 inclusively, so only long arithmetic can have any practical value because for standard integer types the optimal algorithm is just to access array:
val factorials: ULongArray = ulongArrayOf(1uL, 1uL, 2uL ...)

Add visitor pattern

Visitor is one of the few patterns that could be helpfull in Kotlin. I think it would be nice to have it.

Factorial loop can be start from 2

fun compute(number: Int) : Int {
var result = 1
for (i in 1..number) { //loop can be i in 2..number as in FactorialBig
result *= i
}
return result
}

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.