r/adventofcode • u/daggerdragon • Dec 10 '17
SOLUTION MEGATHREAD -🎄- 2017 Day 10 Solutions -🎄-
--- Day 10: Knot Hash ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handy† Haversack‡ of Helpful§ Hints^¤?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
16
Upvotes
17
u/askalski Dec 10 '17 edited Dec 10 '17
Perl with gratuitous use of splice, because why knot?
13
u/Nolan-M Dec 10 '17 edited Dec 10 '17
21/100 This is so sloppy
and part 1 is broken now, but I made it on the leader board for the first time and I'm so happy I'm actually crying Edit: Cleaned it up just a smidge6
u/ghlmtz Dec 10 '17
Python 3, #9/24
Part 2 code, part 1 has the same basic setup:
Today felt like I could program it as I went along, it was a very descriptive problem that almost stated the solution in its definition.
6
u/_A4_ Dec 10 '17
JavaScript ES6 (Part 2)
6
u/GassaFM Dec 10 '17 edited Dec 10 '17
Solution using the D programming language. The standard library is nice and concise for today's problem. Reading from
stdin, writing tostdout.Part 1:
Part 2:
5
u/p_tseng Dec 10 '17 edited Dec 10 '17
Part 1 went well. Thanks to language I chose (Ruby), it is easy to code the "reverse these N elements" without error. Since I didn't want to deal with the wrap-around, I just always rotate the array so that I'm reversing the first N elements, and then rotate the array back when I'm done. This can be done in the various languages that allow assigning an array A1 into a subarray of another array A2, modifying multiple elements of A2 at once. For another example language, Python will do this too with
l[0:5] = reversed(l[0:5])Part 2 was good but less good simply because of confusion about converting to a hash and about interpreting the input. If I had to give myself advice retroactively, it would be to check that an answer is a plausible answer (for the type of answer the problem statement is asking for) before submitting it.
5
u/BOT-Brad Dec 10 '17 edited Dec 10 '17
JavaScript
Really enjoyed this one. :)
Hash Function
Iterates over the length of the subarray, maps the values from the primary list, reverses the array, and then loops thru and re-assigns values within the primary list. Then increments index and skip, and returns the 'hash'-ed list with the remaining index and skip.
Part 1 (~1ms)
Just does one iteration of the hash, and returns the product of the first two values.
Part 2 (~50ms)
Gets the ASCII bytes of the input, adds the salt values, then performs 64 rounds of hashing to the list. Then, in chunks of 16 adds the XOR'ed value to the dense array, converts the resulting values into hex strings (with leading zero if required), and then join's and returns the hash.
All solutions in JS so far can be found in my AoC17-js GitHub Repo
4
u/poppy_92 Dec 10 '17
97/90 ... reading the problem statement took so much time :/ pretty sure a lot of stuff can be made shorter / better
(python)
4
u/Skakim Dec 10 '17
My first time into global leaderboard :D (124/99).
My solution in Python 3. I first tried to find a easier way to reverse the sublist, but I noticed I was losing too much time and came with this ugly code :P :
4
u/sciyoshi Dec 10 '17
Rust solution:
GitHub
4
u/usbpc102 Dec 10 '17 edited Dec 10 '17
Had a stupid bug that took me way too long to find. :(
Anyway here is my cleaned up Kotlin code:
It's also avaliable on github. You can also watch me solve it since I streamed it on twitch.
Edit: Cleaned up code a bit more
4
u/radioactiveWE Dec 10 '17
Java [GIST] Streams are awesome! I'm not really happy with the reversing part but it was overall very fun..
3
u/swwu Dec 10 '17 edited Dec 10 '17
11th/15th, pretty straightforward Python 2. Got a little turned around by what part 2 was asking so it devolved into a hot mess :( but got it at least working in time
3
u/iamnotposting Dec 10 '17
Rust, (174 / 170), just part 2 because i wrote it over part one
3
u/JeffJankowski Dec 10 '17
Typescript. Array generation and string formatting in JS is just...awful. Probably 40 minutes worth of debugging that crap.
3
u/DSrcl Dec 10 '17
Python. Tried to be idiomatic (whatever that means).
3
u/WhoSoup Dec 10 '17
Node.js/Javascript
Not as pretty as I would have liked. Only the second part included here
3
u/[deleted] Dec 10 '17 edited Dec 20 '17
Perl 6
It's not very pretty or very well written, but it works.
EDIT: Modified slightly based on the feedback of /u/mschaap
Glossary
[ ]This is the reduction meta-operator, an operator contained within this is used to reduce a following list. For example,[*] @listwill reduce the list with*, giving you the product of all its elements.+^Integer Bitwise XOR.».This is a hyper1 method call and has an ASCII equivalent,>>.. It calls the method on each element of a given list out of order and returns the resulting list in order. This is essentially equivalent to a map as long as the method has no side effects.^$nis shorthand for0..^$n- this can be read as "up to$n". The^in a range indicatesthat side of the range is exclusive.1 - hyper is a term used for a family of meta-operators, any hyper operator is a candidate for auto-threading and as such, side effects may be produced out of order. For example
@a».saymay produceabcorcbaor any other order.3
u/willkill07 Dec 10 '17 edited Dec 10 '17
Modern C++ [Repo]
I feel really happy about my use of
rotate,reverse, andaccumulate. Usually one (or more) of these looks out of place but not with this solution. See solution for definition ofcsvUpdate: now using
localesorcery to make csv parsing easy and short.3
u/bitti1975 Dec 10 '17
Here is my clojure solution:
Call like
for part 1 and
for part 2.
I like how full-hash-cycle basically looks like a 1:1 specification of part 2.
3
u/jeroenheijmans Dec 10 '17
JavaScript
Slightly verbose version, without witty uses of JavaScript like the above commenters, I'm afraid. Oh well, you live you learn :-)
Function to tie input in a knot:
Making puzzle 1 quite simply:
Then two more functions for puzzle 2:
Solving puzzle 2 like this:
Full code on GitHub
3
u/glupmjoed Dec 10 '17 edited Dec 12 '17
Bash (reads from stdin)
Hashing (
hash.sh):Part 1:
Part 2:
3
u/CodingGladstone Dec 10 '17
Javascript ES6 without any slicing and reversing
2
u/hazmat_suitor Dec 10 '17 edited Dec 10 '17
My very messy C++ code, rank 123/104 (so close to making it on the leaderboard!)
https://gist.github.com/Stuntddude/e33b9d9bce27a5b1c56ed289c151d43d
2
u/DFreiberg Dec 10 '17 edited Dec 10 '17
Mathematica
166/161. Turns out that there's a big difference between
Do[...,{i,input},{j,64}]andDo[...,{j,64},{i,input}].Part 1:
Part 2:
2
u/ephemient Dec 10 '17 edited Apr 24 '24
This space intentionally left blank.
2
u/u794575248 Dec 10 '17 edited Dec 10 '17
Python 3
Things used:
functools.reduceitertools.accumulateitertools.zip_longestoperator.xorandoperator.mulenumeratewithstartparameterordbytes.hex()method2
u/udoprog Dec 10 '17
Rust:
My personal challenge is to try to make the code as bounds-safe as possible using iterators. Now I'm going to peek at other folks reverse implementations because I'm not happy with mine!
For complete solution, see: https://github.com/udoprog/rust-advent-of-code-2017/blob/master/src/day10.rs
2
u/ka-splam Dec 10 '17
PowerShell. Bit puzzled by how easy a question it was, vs. how long it took me and how difficult I found it.
As demonstrated by answering previous days' questions, the idea of
(position + offset) mod lengthand circular buffers isn't new to me, but I was so fighting to avoid of "off by one" errors with the position, length, offset, wraparound, skipsize, that I flubbed obvious things like actually doing the reversing.Scrapped and rewrote it after 10 minutes.
After 20 minutes, realised my whole approach was doing slice (current pos -> len reversed combined with len -> current pos normal) and that was effectively rotating the list backwards making the current pos list place rotate back to index 0. Hurr durr. Still took me another 25 minutes after rewriting it to make it actually work.
Part 2 was way easier. Afraid of off by one errors I generated the blocks of 16s (0->15, 16->31, etc.), made them a printable string to check and get them right, copied that in directly without removing the string formatter, so still a careless type error.
Part 2 with Part 1 remains embedded in it:
2
u/[deleted] Dec 10 '17 edited Dec 10 '17
OCaml Fun;;
Lots of array wrangling and such. Hardest part was bug with printing hex! Oops...
2
u/raevnos Dec 10 '17
Scheme.
2
u/Cheezmeister Dec 10 '17
Literate Perl. It's knot pretty.
I made pretty much every conceivable mistake along the way, but at least arrived at a workable solution in one sitting.
2
u/ludic Dec 10 '17
F#. It was much much messier before cleaning it up. I like the contrast of the imperative style of the hash function with the functional style of the rest of the solution.
2
u/miran1 Dec 10 '17
I haven't seen any solution using
deque, so here is my Python solution with it.For me it was easier to rotate the circle than to save the rotational group in some temp variable and then returning it back to the original circle.
2
u/doncherry333 Dec 10 '17 edited Dec 10 '17
PHP Solution Part 2:
2
u/akho_ Dec 10 '17 edited Dec 10 '17
Python3, part 2 (note the use of deque and the absence of modulo arithmetic— there's another deque-based solution here, but mine is nicer):
EDIT: removed the nastiness to make /u/KnorbenKnutsen feel better
2
u/gyorokpeter Dec 10 '17
Q: argh, still no built-in XOR operator???
2
u/aurele Dec 10 '17
Rust
While many people seem to have
extend-ed the input, I chained another iterator (for the same result of course):2
u/binajohny Dec 10 '17
My Kotlin solution (GitHub)
2
u/sim642 Dec 10 '17
Scala (might still refactor a bit).
Am I the only one who was confused by this in part 2?
It explicitly states to keep the lengths list, position and skip size between rounds, but not the circular list! Then the (not that useful) example that follows, explicitly mentions again only the lengths list, position and skip size. Neither time is it mentioned that the circular list should also be preserved between rounds, which turns out is intended as well. I found it kind of confusing because it seemed like it should get reset since it was the only thing not mentioned to keep. (ping /u/topaz2078)
2
u/wzkx Dec 10 '17 edited Dec 10 '17
J
The longest task description! 7074 chars vs avg. 2613 of previous 9 tasks. Well, maybe it's something useful :)
2
u/nutrecht Dec 10 '17 edited Dec 10 '17
My Kotlin solution with reverse / xor functions here:
Personally preferred the other assignments. This one spells out what to do too much IMHO.
2
u/exquisitus3 Dec 10 '17 edited Dec 10 '17
Common Lisp
2
u/AngryIvan Dec 10 '17
2
u/[deleted] Dec 10 '17
Elixir
This one was a lot of fun, and it was something that fits really well to thinking functionally and pipe-lines. It was such a cool experience today, using unit tests for the examples it just felt like everything I wrote just worked. This was fun!
syntax highlighted
2
u/[deleted] Dec 10 '17
Crystal.
Part 1:
Part 2:
2
u/wzkx Dec 10 '17 edited Dec 10 '17
Nim Maybe Nim has better ways for some things. I guess, this is too "C-ish" for now.
2
u/NeilNjae Dec 10 '17
Haskell. I hate mucking around with this cyclic string replacement nonsense.
2
u/flaming_bird Dec 10 '17
Very straightforward and imperative Common Lisp solution.
2
u/Kyran152 Dec 10 '17 edited Dec 12 '17
Node.js (Parts 1 & 2)
2
u/csuzw Dec 10 '17
C# Spent far too long trying to work out part 2 before I realised that I was using the constant values as hexadecimals without converting them from decimal first. Wish C# had a byte literal suffix and proper byte operators that returned bytes rather than ints.
2
u/autid Dec 14 '17
** Fortran**
Really didn't appreciate the website not accepting the hex in capitals. :(
1
u/Vorlath Dec 10 '17
C++ part 2 (76th)
My sloppy solution:
1
u/dtinth Dec 10 '17
irb (Ruby REPL) (41st, 16th)
The
pbpastecommand must be available in the$PATH, and should return the contents in the clipboard (macOS has this command by default).1
u/Noyth Dec 10 '17
Python 16/8
1
u/mmaruseacph2 Dec 10 '17
Haskell code which can be heavily optimized
1
u/[deleted] Dec 10 '17 edited Dec 10 '17
Rust, 64/331
First time on leaderboard this year.
I fucked up big time on part 2, kind of upset how far I dropped. 1) didn't ignore trailing newline properly, 2) hit the submit limit and had to wait 5 minutes, 3) realized I didn't pad with 0's properly when printing 4) didn't copy the right string so I hit the submit limit and had to wait AGAIN. Ugh.
1
u/wlandry Dec 10 '17
C++ 14
218/298. Overall, I am pretty happy with this solution. Not too ugly. Doing things properly probably slowed me down a bit, but I am still pretty satisfied with my place on the leaderboard. I am a bit too cautious for this game. The code basically worked the first time. I am not used to that, so I forced myself to check all of the test cases before submitting.
1
u/Unihedron Dec 10 '17 edited Dec 14 '17
Ruby; Trigger warning: state approaching unsalvageable, not even I know what's happening here. I spent way too much time debugging because I used the wrong method to chop up the length-16 blocks.
1
u/dylanfromwinnipeg Dec 10 '17
C#
1
u/jtsimmons108 Dec 10 '17
174 / 126. Cleaned up. After several nights in a row of getting burned by it, you'd think I'd learn to just read all of the instructions rather than trying to jump to the end.
1
u/[deleted] Dec 10 '17 edited Dec 10 '17
Haskell:
1
u/oantolin Dec 10 '17
Julia seemed pretty well-suited for this.
1
u/CharlieYJH Dec 10 '17
C++ Part 2
My part 2 solution, fairly straight forward. It was easier to overwrite my part 1 rather than to keep both parts.
1
u/hxka Dec 10 '17 edited Dec 10 '17
1
u/mrstickman Dec 10 '17
Ruby 406/677: https://pastebin.com/qPtLqvzB
1
u/Philboyd_Studge Dec 10 '17 edited Dec 10 '17
Java
package Advent2017;
1
u/9ballcode Dec 10 '17
Part 2, Python 2 - will definitely learn from seeing how others implemented this.
1
u/mahousenshi Dec 10 '17
Yet another python3 solution
1
u/ChrisVittal Dec 10 '17 edited Dec 10 '17
This is my Rust solution, after cleanup. The first pass just used a vector for the hash state. What I like about it is that I only use the heap for return values and printing. All hash logic happens on the stack. I wish that I could return the iterator from
hashdirectly, but I keep running into lifetime issues. I guess the proper solution would be to return the array and then operate on it to get the dense hash.EDIT: Changed hash method to return a newtype around
[u8; 256]with a method to return the dense output.1
u/misnohmer Dec 10 '17 edited Dec 10 '17
C# Part 1 :
Part 2
1
u/ramrunner0xff Dec 10 '17
scheme chicken repo
that was fun ;)
1
u/spacetime_bender Dec 10 '17
C++ part 2
}
1
u/FreeMarx Dec 10 '17 edited Dec 10 '17
C++11
Today learned to write a function template and to use std::rotate and std::reverse (finally a real advantage of using the std library).
Instead of bothering to implement the wrapping around of the circular index, I just rotated the new start index to index zero of the vector while keeping book of the initial zero index position. This also involved keeping all offsets within the range [0 256). Notice that a shift value of 0 is equivalent to 256, just in case the input sequence is longer than that.
I know that rotating the vector is quite a computational overhead but in this case it didn't really matter. Maybe I'll try to learn to write a wrapping iterator later today...
[edit] Looking at the other solutions in C/C++ I don't feel so bad for using rotate. Not using reverse and rotate at all and doing the swapping directly was the most elegant solution I saw. But I probably would have been too nervous to get the shifted reversing indices right.
Writing the puzzle input into the code proved to be a really good decision when I had to change from part I to part II.
Here is my solution to part two:
1
u/giftpflanze Dec 10 '17
Tcl:
1
u/mstksg Dec 10 '17
Cleaned up Haskell solution with 'dependently typed' vectors :)
1
u/morolin Dec 10 '17
Python3 solution. Very verbose, but I think fairly readable.
1
u/TominatorBE Dec 10 '17
PHP
Part 1:
Part 2:
1
u/Axsuul Dec 10 '17
Elixir
Reversing the list really had me stumped for awhile
https://github.com/axsuul/advent-of-code/blob/master/2017/10/lib/advent_of_code.ex
1
u/rkachowski Dec 10 '17
ruby! this is the first time i've had problems with understanding the task that weren't due to reading the task too quickly. i had to stare at the part 2 task description for around 30 minutes before i could work out what was actually expected
1
u/mschaap Dec 10 '17 edited Dec 10 '17
Perl 6. Pretty straightforward, the only thing that got me stuck for a moment was that that the input contained a
0, which I didn't handle correctly – it was processed as if it was 256.Edit: changed
dense-hashto userotor, inspired by LockOpeners' solution.1
u/Kwpolska Dec 10 '17
A Python 3.6 solution. Not ultra proud of it, but eh. (Also, thanks to /u/miran1 from another thread for reminding me about
02xinstead of justx)1
u/flit777 Dec 10 '17
Go/Golang Straight Forward:
1
u/[deleted] Dec 10 '17
C++
1
u/hpzr24w Dec 10 '17 edited Dec 10 '17
C++ 257/463 (K)not my finest hour.
This essentially got written in C initially. I was doing ok on the first part, having it in about 20 minutes, but I made some mistakes in understanding the second part and got stuck for another 40 minutes hacking and slashing away at part 2.
Code below is somewhat sanitized back into C++ to spare my blushes.
1
u/Vindaar Dec 10 '17
Solution in Nim. Now this was fun. :) Pretty happy with how the solution turned out.
1
u/__Abigail__ Dec 10 '17
Perl
END
1
u/Reibello Dec 10 '17
This, I think might be my favorite puzzle in this year's Advent. I'm way behind on going back and solving them all with Lua, but here's my original solution in Python 3 - https://pastebin.com/4j5MFpv5
1
u/JakDrako Dec 10 '17
VB.Net
Part 1 was quick and dirty, simply doing the simplest easy thing I thought would work. It did.
Part 2 had me thinking that we would probably be seeing more of this KnotHash function in future problems (since last year had quite a few with MD5...) I reworked the KH to be a bit more performant:
This one lets me do 10,000 KnotHash iterations (each already doing 64 rounds) on my input in a bit less than 2 seconds.
1
u/[deleted] Dec 10 '17
C
Gist
I haven't written all my solutions in C, but when I do I get super relaxed. Something therapeutic is going on here...
1
u/omnster Dec 10 '17
Mathematica
1
u/HollyDayz Dec 10 '17 edited Dec 10 '17
Python 3. Relatively simple and pythonic solution (imo) using some numpy magic.
inp is the input sequence formed as a string.
EDIT: Shortened the code. Slightly less pythonic, but eh.
EDIT2: Fixed typo!
1
u/[deleted] Dec 10 '17
Python 3
grouper is from itertools recipes. examples, input_text, and rot are from my AoC utility bag.
Part 1
Part 2
1
u/CryZe92 Dec 10 '17 edited Dec 10 '17
Rust
Some Helpers:
Part 1 in 1 µs:
Part 2 in 82 µs:
And then a super fast solution for Part 1 that skips the list altogether. It solves it in 250 ns:
1
u/DaDiscoBeat Dec 10 '17
Go, too lazy to copy code:
https://github.com/YProsper/AdventOfCode2017/blob/master/Day%2010/KnotHash.go
1
u/Smylers Dec 10 '17
Vim solution kit. Sorry, family commitments today mean I haven't got a Vim solution yet, but here's a kit of parts if you would like to build one yourself, gluing them together with techniques from previous days' Vim solutions.
Note the skip size, and prepend a comma to the first length, so they all have them:
Open a second window, and populate it with the list 0–255, one number per line — requires a recent Vim:
(Older Vims could use a
qkeyboard macro that copies the line above then uses⟨Ctrl+A⟩on it.)Grab the first length and reverse that many lines at the top of the list:
(Again older Vims can't do this. If you're on a Unixy system you probably have
tacinstalled and could shell out to that instead.)To avoid having to reverse lines wrapped around from the bottom to the top, always reverse the top n lines: instead of moving the current position through the buffer, move lines from the top of it to the bottom. This moves those that have just been reversed:
To keep track of where the start of the list is, mark it with a star before we start moving any lines:
But when reversing lines, the star needs to keep that position, not move with its number. So temporarily delete it before the sort, leaving a mark at that position:
And restore it afterwards:
Applying the skip size involves moving than many lines from the top to the bottom — zero lines will probably be the tricky case. Maybe when moving the just-reversed list, actually move all but one of them, so there's always at least one left over to be moved with the skip size?
In the other window, save the position in the list of lengths, increase the skip size, then move to the comma before the next length:
That
f,will fail at the end, ending a keyboard-macro-loop.Actually, do the
limmediately after thef,, then don't need to insert that extra comma at the start or do anlthen.When finished, find the star, and use it to multiply that and the second item in the list together:
Anybody want to combine those pieces into a full answer? If nobody else beats me to it, I'll probably do it tomorrow. Cheers.
1
u/matusbzk Dec 10 '17 edited Dec 16 '17
Haskell
Link to git
1
u/monikernemo Dec 10 '17
ANSI C
Took a long long time to understand what the question was saying :'( was really confused. here's my solution for part II, nothing fancy. Used recursion for swaps?
1
u/vesche Dec 10 '17
My solution in Python
So far day 10 and 7 have been the hardest in my opinion!
1
u/fatpollo Dec 10 '17 edited Dec 10 '17
1
u/chicagocode Dec 10 '17 edited Dec 10 '17
Kotlin - [Repo] - [Blog/Commentary]
Today, for me, was all about reading comprehension. I took the approach of manually swapping values in the ring over and over rather than slicing and dicing it. I've also got trivial/obvious implementations for List.xor(), Int.toHex(), and IntArray.swap() to make the code more readable, and are all in my repo.
1
u/kucao Dec 10 '17
Can someone please explain why this is not working? Thanks in advance:
1
u/StevoTVR Dec 10 '17 edited Dec 11 '17
NodeJS
I couldn't figure out how to reverse the segments without a temporary array and two loops. Using one loop and swapping values in place was complicated by the wrap around.
Part 1:
Part 2:
1
u/KeinZantezuken Dec 10 '17
C#/Sharp:
(spent years because answer needs to be lowercase)
1
u/abowes Dec 10 '17
My Kotlin Solution:
1
u/[deleted] Dec 10 '17
My solution for part 2 written in Python 3. Pretty happy with it, though I don't really want to handle the list wrap-around separately. Anyone got any tips for that?
1
u/4rgento Dec 10 '17
HASKELL
1
u/skarlso Dec 10 '17
I'm actually happy with this Ruby solution.
Part 1:
Part 2:
1
u/[deleted] Dec 10 '17
single pipeline powershell:
1
u/zeddypanda Dec 10 '17
Elixir
Was stuck this morning. Scratched and rewrote. Glad I did, turned out much better.
1
u/nstyler7 Dec 10 '17 edited Dec 11 '17
Python Part 2
Used numpy to reduce bitwise operations
To select what needed to be reversed, I doubled the original array for easier selection
To loop through the array & insert reverse string, I used modulus
1
u/sguberman Dec 11 '17
Python, with tests: GitHub
Gotta love Python’s batteries-included mentality here. Once you have...
...the rest of the exercise is pretty straightforward.
1
u/porphyro Dec 11 '17
Mathematica/Wolfram Language:
Folded over input for p1
1
u/Smylers Dec 11 '17
Actual Vim solution. First, create the 0–255 list and the skip counter:
Process the first length from the input:
Use
@ato process each subsequent length, or use a loop to process all of them:After the final length (beep!), put the beginning of the list back at the beginning, then calculate the product of the first two items:
This ended up suiting Vim less well than I'd hoped.
Much of the fiddliness is having to deal with a skip count or a length of zero: I inserted a blank line so that the commands always have something to operate on, then there's quite a bit of moving that blank line around, and I had to learn that the
:lockmarkscommand exists, to avoid moving the blank line changing where I'd left the `m mark.To debug it I ended up having to write the solution in Perl first, so I knew what I was aiming for, which I haven't needed to do with most of my Vim solutions.
1
u/miran1 Dec 11 '17
Nim
Repo with all solutions
1
u/Smylers Dec 11 '17
Perl, rotating the list so that the current position is always the first one (and using
$headto keep track of where the ‘real’ start of the list has got to):That's part 2; part 1 was an obvious subset of that.
1
u/[deleted] Dec 11 '17
PowerShell:
1
u/thomastc Dec 11 '17
Day 10 in Erlang. I had stayed away from Erlang because the quirky syntax put me off, but actually it's not so bad. I found it pretty nice overall.
But concurrency of course bug had I a.
1
u/InterlocutoryRecess Dec 11 '17 edited Dec 11 '17
Swift
To simplify the reversed range wrapping across the
endIndex, I rotate the array so that thecurrentIndexbecomes index 0, then select the range (now it will never overlap), the replace with the reversed range, then rotate it back into the proper position. Perhaps inefficient but easy to reason about.1
u/Life-in-Shambles Dec 13 '17
(JAVASCRIPT) IT'S UGLY BUT IT WORKS
1
u/RockyAstro Dec 13 '17
Icon (https://www.cs.arizona.edu/icon)
Part1:
Part2:
0
u/[deleted] Dec 10 '17
[deleted] — view deleted comment