Hmm,

I thought I understand this idea but I do not.

I did this in the playground :


| answer |
answer := Key5Solver new solver.
 ^ answer Result

class :

Object subclass: #Key5Solver
    instanceVariableNames: ''
    classVariableNames: 'Result'
    package: 'AdventOfCode2015-Day4 - Part1'


solver :


zeros := '000'.
zerosSize := zeros  size.
count := 0.
[   
    [    candidate := secret , count printString.
        ((MD5 hashMessage: candidate) hex first: zerosSize) = zeros
    ] whileFalse:
        [   
            count := count + 1.
        ].
   
] forkAt: 35 named: 'Mining'.


but still I do not see the answer.

Maybe I have to go for the blocking answer.

Roelof



Op 9-12-2018 om 23:10 schreef Ben Coman:
This is running the calculation in a new Process (in general terms, our "Process"es are "green-threads"). 
You can't "return" values between threads.  You need to pass it some other way through a variable. 
If you put that code into an instance method, then you could store the result in a class-variable.
Change the Transcript to ```self inform: 'FInished' ```  and then have a different method you call
after you see that to return the answer.

cheers -ben

On Mon, 10 Dec 2018 at 04:16, Roelof Wobben <r.wob...@home.nl> wrote:
Hello,

I got this code from the discord channel

secret := 'abcdef'.
zeros := '000'.
zerosSize := zeros  size.
count := 0.
[    
    [    candidate := secret , count printString.
        ((MD5 hashMessage: candidate) hex first: zerosSize) = zeros
    ] whileFalse: 
        [    (count \\ 10000) = 0 ifTrue: [ Transcript crShow: count ].
            count := count + 1.
        ].
    Transcript crShow: 'ANSWER = ' , count printString.
] forkAt: 35 named: 'Mining'

but I like that there is no transcipt in the code 

so my question is how can I change this part(
 Transcript crShow: 'ANSWER = ' , count printString.
) 

so it still returns the count.


I tried  ^count printstring but that is not allowed 


Regards, 


Roelof


Op 9-12-2018 om 12:29 schreef Roelof Wobben:
Helllo,

a question about day4 of 2015
is it right that I can only solve this bruteforece
so begin at for example 1 , encode it, check for 5 zeros if found then I have found it otherwise increase the counter and do it again


Reply via email to