Coder Social home page Coder Social logo

kotlin-algorithm's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @gazolla
  • ๐Ÿš€ Passionate about technology and always seeking new knowledge. After some time away, I am getting back into Java programming and undergoing a refresher to update my skills.
  • ๐Ÿ‘€ I have a great interest in Artificial Intelligence and love exploring new tools and development methodologies. I am always open to collaborating on interesting projects
  • ๐ŸŒฑ Iโ€™m currently learning ...
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on swift and java projects
  • ๐Ÿ“ซ How to reach me [email protected]

Top Langs Your GitHub stats

kotlin-algorithm's People

Contributors

bitdeli-chef avatar gazolla avatar keshava11 avatar lsoares avatar morilog avatar nicopasso avatar vanshg 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  avatar  avatar

kotlin-algorithm's Issues

Improvement suggestions for shuffle

I was looking for code to do shuffle. I feel there are two problems with your solution:

  1. the function mutates the list given to it (and sort of pretends that it didn't by returning the result of the shuffle additionally as it's return value)
  2. it doesn't use existing code for shuffling

I wrote this code for my project:

/**
 * Returns a randomized list.
 */
fun <T> Iterable<T>.shuffle(seed: Long? = null): List<T> {
    val list = this.toMutableList()
    val random = if (seed != null) Random(seed) else Random()
    Collections.shuffle(list, random)
    return list
}

It reuses existing code to do the shuffling and can be called like other kotlin collection functions.

Shuffle isn't correct

fun <T:Comparable<T>>shuffle(items:MutableList<T>):List<T>{
    val rg : Random = Random()
    for (i in 0..items.size - 1) {
        val randomPosition = rg.nextInt(items.size)
        val tmp : T = items[i]
        items[i] = items[randomPosition]
        items[randomPosition] = tmp
    }
    return items
}

This algorithm doesn't shuffle it correctly, not every permutation is equiprobable. You have to do:

val randomPosition = rg.nextInt(i + 1)

to fix it.

More information:
https://blog.codinghorror.com/the-danger-of-naivete/

various clarifications for inclusion as external libs

I just googled for a Kotlin Stack class and found this library...

i'd like to open this up for discussion:

things that are currently undefined:

no POM -- was there ever any intent or success with:
git submodule add https://github.com/<User>/Kotlin-Algorithm.git
?

no packages declared in the kotlin source -- curious things happen with root package in jvm

no README declaration of whether this lib attempts pure java or js stdlib -- inconsistent due to:

junit imports in the same hierarchy as the source code -- tests are nice... but this lib is inconsistent.

i'd like to use the simple Stack class and go back to playing with my own project... but my inclination is to suggest one of the active maintainers provide one or more or pom, gradle, and raw git submodule imports, with package hierarchy chosen ... git submodule add "Kotlin-Algorithm" into src/main/kotlin does not imply a pleasant packagename, but there's no reason it could not be robust as a git submodule.

for now i'm fine cutting and pasting these gems, but had to scratch my head a minute to figure out what is going on, an unexpected cost.

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.