GithubHelp home page GithubHelp logo

arxcis / adventofcode2018 Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 3.0 581 KB

The many languages challange

Home Page: https://adventofcode.com/2018

Go 8.31% Shell 45.23% C++ 15.90% JavaScript 9.26% Python 7.03% Rust 14.29%

adventofcode2018's People

Contributors

arxcis avatar celebrian avatar meltinglava avatar tholok97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

adventofcode2018's Issues

day06 bash improve performance

Finishes in 8 minutes on my machine

  ✔ day06-chronal-coordinates › test › main.bash (8m 18.4s)
    ℹ 3909 === 3909 1 of 2
    ℹ 36238 === 36238 2 of 2

Would be interesting to investigate if something can be done to improve performance.

I am not qualified yet, as I have not completed the task in any other language. But I will be ready to discuss as soon as I get there.

getting error trying to run the tests.

running any of the npm commands i get:

> ava --verbose


  ✖ Couldn't find any files to test

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! adventofcode2018@ all: `ava --verbose`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the adventofcode2018@ all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Test hangs after success on Bash day3

When I call npm run generate && npm run bash day03-no-matter-how-you-slice-it/ I get this:

tholok:~/code/forked$ npm run generate && npm run bash day03-no-matter-how-you-slice-it/

> adventofcode2018@ generate /home/tholok/code/forked
> node generate.js

Generated day01-chronal-calibration/test.js
Generated day02-inventory-management-system/test.js
Generated day03-no-matter-how-you-slice-it/test.js
Generated day04-respose-record/test.js
Generated day05-alchemical-reduction/test.js

> adventofcode2018@ bash /home/tholok/code/forked
> ava --verbose --match='*.bash' "day03-no-matter-how-you-slice-it/"


  ✔ test › main.bash (59.4s)

...and then it hangs forever.

It gives the right output, so I suspect there is something wrong with the tests. @Arxcis any idea what could be causing this?

Versions:

tholok:~$ node --version
v11.2.0
tholok:~$ npm --version
6.4.1

At the latest pulled down commit at the time of writing.

I'll let it run for a while and see how long it takes

Troubles with passing input

Day 3 requires the input to be read line-by-line. Doing ./main.bash $(cat input) gives the input as a long array of strings for me, the newlines disappear. Doing ./main.bash "$(cat input)" however does retain the newlines.

How do the other languages behave here? Is it Bash's fault, or does $(cat input) without quotes expand to a sequence of strings for you as well?

This is code I'm testing with:

CLAIMS="$@"

while read -r line; do
    echo "... $line ..."
done <<< "$CLAIMS"

./main.bash $(cat input) gives ... #1 @ 1,3: 4x4 #2 @ 3,1: 4x4 #3 @ 5,5: 2x2 ...

./main.bash "$(cat input) gives

... #1 @ 1,3: 4x4 ...
... #2 @ 3,1: 4x4 ...
... #3 @ 5,5: 2x2 ...

For now I'll solve using the quoted version. Passing input this way in AoC is new to me so I might be misunderstanding something here 😋

Suggested improvement for C++ day 1

I'm not sure what the etiquette on suggested improvements is in the repo, please let me know any opinions around that. Could be appropriate to discuss in the README as well.

In day01-chronal-calibration/main.cpp a std::map is used to store seen frequencies. Wouldn't a std::set be more idiomatic, since the value stored for each element (1) is never used? The change would mostly be for readability. I'm not sure about the performance differences, but a quick google says they basically have the same lookup and insert times.

The Bash and Golang solutions use maps as well, but they don't have built-in sets to take advantage of.

Language priority list

Languages which is going to be prioritized so far

  • Bash
  • C#
  • C++
  • Clojure
  • Go
  • Kotlin
  • Nodejs
  • Perl
  • Python3
  • R
  • Rust
  • Swift

Use Cargo insted of rustc

Cargo is rust package manager, that wraps the compiler. Since rust has the idea that the std only gives you the most common tools to make good libraries.
Also you now do not have to do a compile and then a run of the executable. cargo run does that all for you. It will also download, and compile all your dependencies. In my life i have only used rustc once. This is also necessary so that editors recognize all the code. Thinking of using grabinput for grabbing all the input. as the code is redundant and the logic is not interesting.

Also you probably want to run cargo run --release to get the optimised version. Atleast one of the AOC is going to require some computation.

Generate tests

  • All tests are almost identical, and there is a lot of repetition from folder to folder. This makes generating tests very simple.

  • The generator would generate a test.js in each folder.

  • We could have a npm build test, npm run test and npm remove test

Example from day01

import test from 'ava'
import {
    testGo,
    testCpp,
    testBash,
    testRust,
} from '../test-util'

const dirpath = __dirname
test('main.go', async t => await testGo(t, dirpath))
test('main.cpp', async t => await testCpp(t, dirpath))
test('main.bash', async t => await testBash(t, dirpath))
test.skip('main.py', async t => await testPython(t, dirpath))
test.skip('main.rs', async t => await testRust(t, dirpath))

Only test the specific day and language you are making a pull request for

Travis has an Environment variable TRAVIS_PULL_REQUEST_BRANCH

if people name their branches in a strict manner, we can use it to conditionally test only one language-day-pair:

  • Branch day01-js -> npm run js day01/
  • Branch day01-rs -> npm run rs day01/
  • Branch day02-py -> npm run py day02/

else npm run all

Maximum time for solutions?

My current Bash solution for day 3 part 1 is estimated to take 2 hours. I'm hoping this is my fault and not Bash, since then I can at least improve upon it, but if it turns out some languages will just be this slow, how do we handle this in automated testing?

One solution would be for Travis to do a git diff to figure out what files are changed, and only test those. Normally this is a nono, but since the files are all independant programs that are not affected by each other I'd say it's excusable.

Would be a shame to block certain languages from entering.

Refactor Bash solutions to follow Google style guide on naming

The style guide: https://google.github.io/styleguide/shell.xml#Naming_Conventions.

I can do this myself of course, posting it here for reference later.

I've used uppercase for variables (except for loop variables for some reason) in the Bash solutions. I want to change it to follow the Google style guide that uses lower case for normal variables and upper case for constants (revolutionary idea! :o). Constants in Bash can be made with readonly and declare -r btw, never knew.

[spoilers] day06-bash logic question

During the solve in Bash for day6 I think made a false assumption about the area to search while looking for answers to part 1. It happened to work out with the input I had, so I did not prioritize fixing it at the time. I think I know a way to fix it, but my fix seems a little dirty, so I'd love to get input on what other people did 😋

(My solution is also very slow.. #38)

Spoilers below!

The mistake I made

When looking for locations that could count towards the area of locations that is closest to a finite coordinate I search in a square from the left-most x and y of any coordinate to the right-most x and y of any seen coordinate. So given three coordinates A, B and C (and some excluded ones below that make C finite) the search area could look like this:

0: not searched
x: search area

0 0 0 0 0 0 0 0 0
0 A x x x x x B 0
0 x x x x x x x 0
0 x x x C x x x 0
...(more coordinates below)

My solution would see A and B, and determine that the only area it needs to search for locations closest to C is the area marked as x. 0 means the location is never looked at. This works out fine in this example, but here is an example that does not work with my solution:

0 0 0 0 0 0 ! 0 0 0 0 0 0
0 A x x x x x x x x x C 0
0 x x x x x C x x x x x 0
...(more coordinates below)

In this example the location marked as "!" is closest to C, so it should be counted towards it's area for the solution of part 1. My code only looks at the area marked as x though, so it would get the answer wrong here.

A fix

A solution would be for the code to search through the area in a diamond shape like this:

0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 x 0 0 0 0 0 0
0 0 0 0 0 x x x 0 0 0 0 0
0 0 0 0 x x x x x 0 0 0 0
0 0 0 x x x x x x x 0 0 0
0 0 x x x x x x x x 0 0 0
0 A x x x x x x x x x C 0
0 x x x x x C x x x x x 0
...(more coordinates below)

This would catch the example above, and (I think) it would catch any other such edge cases. This fix seems a little dirty though, and would require over double the area to be searched...

Let me know if anything is unclear. Any input is awesome. Guessing someone found a smarter way of searching :)

Solutions to only day 1 or 2?

Are solutions to only one part of a day "innafor" (😋), or do you think we should finish both before adding.

If there is a short and clear way to mark that a day has only been solved for part 1 or 2 in the table it could work out well 😋

Something like:

day 3 day 4
Bash part 1 only X

Got my Bash day 3 part 1 down to 2 minutes (from 2 hours), so would love to add it.

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.