I thought about this for the last hour, and I ran out of hair.
I enjoy AdventOfCode.com. Day 4 (10/10, will play again) and I want this little function to work. (Please do not comment on how incredibly beautiful my code is. It should have been quick and dirty, but now it’s just dirty. Damn, I don’t even know if the code has a chance to work. Anywho ...)
func countDigestLeadingZeros( theDigest:[UInt8] ) -> Int { var theCount: Int = 0 print(theDigest[0]) while ((theCount < 16) && (countLeadingZeroNybbles( theDigest[theCount] as Int)>0)) { theCount++ } return theCount }
The error occurs when theDigest[theCount] is “It is not possible to adjust the value of type“ [UInt8]. ”Although I am not familiar with Swift, I am sure that it tells me that I cannot use an index (of any type) in the UInt8s array. attention, however, that the print(theDigest[0]) line print(theDigest[0]) does not cause errors.
I was looking for the hell out of this, but either I am missing an obvious solution or I can’t interpret the results that I found, most of which seem inappropriate for such a seemingly simple problem.
source share