Giter VIP home page Giter VIP logo

prime_sums's Introduction

prime_sums

Written for an internship application. When ran, this prints the prime sums of the digits of each number from 1-100,000.

sum-digits takes a number and returns the sum of each digit in the input. A loop separates each digit in the number recursively. The remainder of the digit when divided by ten is taken (producing the last digit in the number) and added to the sum. The digit is then divided by ten, and the process continues until the digit is less than or equal to one.

is-prime takes a number and returns a boolean representing whether or not the input is prime. In order to determine primality, this function searches for the existance of factors. To do this, a loop counts up from 2 and determines if that number is a factor. If n is 2, we know it is not prime and the loop ends. If n is less than or equal to one, it is not prime and the loop ends. If both of those cases are false, then the loop begins to iterate through integers until it either finds a factor or reaches the square root of the input. Each factor in a composite number is multiplied by another factor, and stopping at the square root of n eliminates this redundancy.

lists-prime takes no arguments. Doseq—which was used rather than loop so that a print statement could be applied to each result—begins to loop through each number from 1 to 100,000 (inclusive). sum-digits1 is called on each number. If calling is-prime on the result from sum-digits results in true, then the sum is printed.

In the future, I would like to improve the efficiency of this program. Generating the range of numbers is time intensive. I might have been able to cut that down if I created a function that produced . And while I was glad that I was able to increase efficiency by reducing the number of factors I had to test in is-prime, I think there is more room for improvement. Rather than test each factor individually, I could have found a way to cut out all multiples of smaller prime numbers. I also could have automated testing, rather than the manual testing I did as I wrote each piece. Overall, I enjoyed getting to play around in clojure again, and I was proud to see that I still remembered quite a bit from last summer.

prime_sums's People

Contributors

lazartea avatar

Watchers

James Cloos 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.