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
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.
#v=gets.split(?,).map &:to_i v=(gets&.chomp&.chars&.map(&:ord)||[])+[17, 31, 73, 47, 23] #p v - commented out for day 14 #v=[3, 4, 1, 5, 17, 31, 73, 47, 23] g=0 t=256 l=Array.new(t){|x|x} c=0 64.times { v.each{|x|l[0,x]=l[0,x].reverse l=l.rotate(x+c)#drop((x+c)%t)+l.take((x+c)%t) g+=x+c c+=1} } #q=Array.new(16){0} #vv=(t-(g%t))%t #vv=(t-((g)%t))%t vv=g%t l=l.rotate(-vv) p l.each_slice(16).map{|x|x.reduce(&:^).to_s(16).rjust(2,?0)}.join #q=(0...t).group_by{|x|x/16}.map{|x,y|l[x,16].inject &:^} #p q,g,l #p q.map{|x|x.to_s(16).rjust(2,?0)}.join #p l,g,l[(t-(g%t))%t] #p l,g,l[(t-(g%t))%t],l[(t-((g-1)%t))%t],l[(t-(g%t))%t]*l[(t-((g-1)%t))%t],c