Comparing a specific character of an array index in Ruby -


what i'm trying input numbers through hash function, , storing resulting hash array. i'm trying find if numbers result in similar hashes match in last characters. i'm trying find largest possible matching characters.

i have hash array created. code doing this:

create hash array
i=1
computation i, new result call 'result'
put result hash pointing created it
hash[result]=i

so have this:

{"abcd"=>1}
increment i
loop until condition

so when increment i, , put thru computation again, want check if there similarities previous results, first comparing character @ end of result

say when put 2 through computations result in "hwed", want way compare , see "abcd" , "hwed" match in last character. know how can this.

what you're trying (perform sequence of operations , store each computation's result) can done simply, though in ruby there many other potential ways it.

you haven't explained problem enough understand you're practically trying achieve. in generic sense:

hash = {   word1: { word: "cat", computations: [] }   word2: { word: "dog", computations: [] }   word3: { word: "pig", computations: [] } }  hash.each |key, val|   # each key symbol , each val hash   100.times     val[:computations] << val[:word].chars.shuffle.join   end end 

so computations arrays filled 100 shuffles of word string. @ point can whatever need computations array (such comparison)


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -