• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Advent Of Code 2016 day 14 part two

 
Bartender
Posts: 5558
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is about Advent of Code 2016, day 14 part two. I cannot get that part solved, and I cannot get the example given. Here is a link to that exercise:  link to aoc2016_14_2

In the example they say that 10 is the first index, and that is what I get as well. However, they state that 22551 is the index of the 64th key, its hash containing "fff" and the hash of "abc22859" has "fffff".

My code however says that 22551 is not a key. The hash I get from index 22551 is "2df6e9378c3c53abed6d3508b6285fff", indeed containing "fff", but the hash of "abc22859" is "d489b5d5080a10bed5f4924dfcb1ab4f", so it does not contain "fffff". I looked on internet, but found no clear explanations. Some had the same problem as I, some had no problems at all, and some pointed out that you had to watch the order of the keys found (but I think they were using a Set to store the keys, and I am using an ArrayList).

Has anyone made this exercise, or can anyone shed some light into my darkness? This is the code I use:

and this is the output:


 
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I'm hooked. I haven't done this one yet but I've made a start and I'll get back to you if I figure something out.
 
Tim Cooke
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have arrived at the puzzle you are working on Piet. While I am having compute time problems, I think I can see where you're going wrong.

You are finding the "stretched" hash of the original key "abc22551" with a triple character sequence correctly, but when you are checking the next 1000 hashes for a five character sequence you are not checking stretched hashes, only normal one time md5 hashes.

"abc22859" Normal hash: d489b5d5080a10bed5f4924dfcb1ab4f
"abc22859" Stretch hash: 2e559978fffff9ac9c9012eb764c6391
 
Tim Cooke
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sorted out my time problems with some function memoization.

I did it in Python and was using @functools.cache for memoization which is an unbounded cache but it failed ("Killed" was the message) due to what I can only assume is momory space problems. I put some bounds on the cache with @functools.lru_cache(1000) and all was good. It took about 45 seconds to run which is good enough for me today.
 
Piet Souris
Bartender
Posts: 5558
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim!

I interpreted this part wrong: "The rest of the process remains the same (...)"

I put 100.00 normal hashes and 50.000 stretched hashes in a HashMap upfront, took more than a minute. Isn't there some clever theorem about repeated hashes?
 
Tim Cooke
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could replace the up front hash cache generation by using getOrDefault followed by a putIfAbsent. For example:


You might of course run into memory space problems as you have just rolled your own unbounded cache, which is generally not a good idea.

It's fun to play though.
 
Piet Souris
Bartender
Posts: 5558
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good idea! I'll keep that in mind.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic