Giter Site home page Giter Site logo

aoc-2020's Introduction

aoc-2020

FIXME: description

Installation

Download from http://example.com/FIXME.

Usage

FIXME: explanation

$ java -jar aoc-2020-0.1.0-standalone.jar [args]

Options

FIXME: listing of options this app accepts.

Examples

...

Bugs

...

Any Other Sections

That You Think

Might be Useful

License

Copyright © 2020 FIXME

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

aoc-2020's People

Contributors

stefanlarsson avatar

Watchers

 avatar  avatar

aoc-2020's Issues

How to best run Day 3.2?

Your solution looks even weirder than mine. Yours:

(apply * (map #(apply tree-sum-gradient (cons lines %)) grads))))

Mine:

(reduce * (map #(count-trees input %) params))

Params is a list of tuples. I skipped using apply, because it became pretty nasty to read, but rather modified my functions parameters:

[input [dx dy]]

This makes apply unnecessary. However I am not sure if both of these lines are idiomatic... I can read them quite fine, but something is a bit off...

Threading macros

You came to a very similar solution as mine (and much earlier at that), as can be seen here:

(def count-letters-in-all #(count (apply clojure.set/intersection (map unique-letters-in-string %))))

I want to raise one point though: There are too many nested function calls! :)

I have become a big fan of the threading macros. especially this task lends itself well to threading:

(defn sum-of-anyone-answers
  "calculates the sum of all answers where anyone of each group answered"
  [input]
  (->> input
       (map #(clojure.string/replace % #"\n" "" ))
       (map set)
       (map count)
       (reduce +)
       )
  )

Instead of nesting we get a relatively clean, imperative-style syntax, that is -- in my opinion -- visually easier to parse.

The second part of the task looks slightly more nasty in my solution, since I used nested collections:

(defn sum-of-everyone-answers
  "calculates the sum of all answers where everyone of each group answered"
  [input]
  (->> input
       (map clojure.string/split-lines)
       (map #(map set %))
       (map #(apply clojure.set/intersection %))
       (map count)
       (reduce +)
       )
  )

But the level of nesting is still pretty shallow...

No Integer overflow?

One of the reasons why my code is so slow is because I use bigint I think. Of course my time complexity is also horrendous (n^2 in part 2). However when looking at your code:

(let [numbers (filename-to-integers "resources/day9/input.txt")]

I don't see you using bigint. How do you avoid running into parse errors? Let me guess: you don't even read in the whole file but it's a lazy evaluation and you never get to the big numbers?

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.