Compared elementes of hash (subtraction) RUBY
I have this structure
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [148507632380, 153294624079]
map = Hash[x.zip([y, z].transpose).sort]
#=>
# 8349310431=>[667984788, 148507632380],
# 8349314533=>[667987788, 153294624079]
#
and I need to compare, the keys with the rest of the keys, but if the subtraction of the keys is less than 100, you have to compare the first elements to which the key points and if this subtraction of elements is less than 100 the procedure is repeated with the second element that the key points to
example
key[0] - key[1] = 8349310431−8349314533 = 4102 (with value absolute)
so now we subtract the first elements that the key points to, because it is greater than 100 the subtraction
element1Key1 - element1Key2 = 667984788 - 667987788 = 3000 (with value absolute)
as the subtraction is greater than 100 we repeat this with the second elements
element2Key1 - element2Key2 = 15329460 - 15329462 = 2 (with value absolute)
as it is less than 100 we stop here and keep this in a counter can be
if the subtraction is less than 100 since the operation with the keys, it can not be stopped there, it is necessary to do it until the second element to which the key points.
but how do I do it
Sorry for my English, but I don't speak it, I hope you understand, and thanks
ruby hash
|
show 3 more comments
I have this structure
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [148507632380, 153294624079]
map = Hash[x.zip([y, z].transpose).sort]
#=>
# 8349310431=>[667984788, 148507632380],
# 8349314533=>[667987788, 153294624079]
#
and I need to compare, the keys with the rest of the keys, but if the subtraction of the keys is less than 100, you have to compare the first elements to which the key points and if this subtraction of elements is less than 100 the procedure is repeated with the second element that the key points to
example
key[0] - key[1] = 8349310431−8349314533 = 4102 (with value absolute)
so now we subtract the first elements that the key points to, because it is greater than 100 the subtraction
element1Key1 - element1Key2 = 667984788 - 667987788 = 3000 (with value absolute)
as the subtraction is greater than 100 we repeat this with the second elements
element2Key1 - element2Key2 = 15329460 - 15329462 = 2 (with value absolute)
as it is less than 100 we stop here and keep this in a counter can be
if the subtraction is less than 100 since the operation with the keys, it can not be stopped there, it is necessary to do it until the second element to which the key points.
but how do I do it
Sorry for my English, but I don't speak it, I hope you understand, and thanks
ruby hash
1
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
1
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42
|
show 3 more comments
I have this structure
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [148507632380, 153294624079]
map = Hash[x.zip([y, z].transpose).sort]
#=>
# 8349310431=>[667984788, 148507632380],
# 8349314533=>[667987788, 153294624079]
#
and I need to compare, the keys with the rest of the keys, but if the subtraction of the keys is less than 100, you have to compare the first elements to which the key points and if this subtraction of elements is less than 100 the procedure is repeated with the second element that the key points to
example
key[0] - key[1] = 8349310431−8349314533 = 4102 (with value absolute)
so now we subtract the first elements that the key points to, because it is greater than 100 the subtraction
element1Key1 - element1Key2 = 667984788 - 667987788 = 3000 (with value absolute)
as the subtraction is greater than 100 we repeat this with the second elements
element2Key1 - element2Key2 = 15329460 - 15329462 = 2 (with value absolute)
as it is less than 100 we stop here and keep this in a counter can be
if the subtraction is less than 100 since the operation with the keys, it can not be stopped there, it is necessary to do it until the second element to which the key points.
but how do I do it
Sorry for my English, but I don't speak it, I hope you understand, and thanks
ruby hash
I have this structure
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [148507632380, 153294624079]
map = Hash[x.zip([y, z].transpose).sort]
#=>
# 8349310431=>[667984788, 148507632380],
# 8349314533=>[667987788, 153294624079]
#
and I need to compare, the keys with the rest of the keys, but if the subtraction of the keys is less than 100, you have to compare the first elements to which the key points and if this subtraction of elements is less than 100 the procedure is repeated with the second element that the key points to
example
key[0] - key[1] = 8349310431−8349314533 = 4102 (with value absolute)
so now we subtract the first elements that the key points to, because it is greater than 100 the subtraction
element1Key1 - element1Key2 = 667984788 - 667987788 = 3000 (with value absolute)
as the subtraction is greater than 100 we repeat this with the second elements
element2Key1 - element2Key2 = 15329460 - 15329462 = 2 (with value absolute)
as it is less than 100 we stop here and keep this in a counter can be
if the subtraction is less than 100 since the operation with the keys, it can not be stopped there, it is necessary to do it until the second element to which the key points.
but how do I do it
Sorry for my English, but I don't speak it, I hope you understand, and thanks
ruby hash
ruby hash
edited Nov 14 '18 at 9:04
Stefan
76.5k895144
76.5k895144
asked Nov 14 '18 at 8:18
Alejandro RodriguezAlejandro Rodriguez
133
133
1
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
1
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42
|
show 3 more comments
1
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
1
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42
1
1
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
1
1
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42
|
show 3 more comments
1 Answer
1
active
oldest
votes
Does this make sense?
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [15329460, 15329462]
[x, y, z].detect # => [15329460, 15329462]
Just in case, why build a hash?
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295692%2fcompared-elementes-of-hash-subtraction-ruby%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Does this make sense?
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [15329460, 15329462]
[x, y, z].detect # => [15329460, 15329462]
Just in case, why build a hash?
add a comment |
Does this make sense?
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [15329460, 15329462]
[x, y, z].detect # => [15329460, 15329462]
Just in case, why build a hash?
add a comment |
Does this make sense?
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [15329460, 15329462]
[x, y, z].detect # => [15329460, 15329462]
Just in case, why build a hash?
Does this make sense?
x = [8349310431, 8349314513]
y = [667984788, 667987788]
z = [15329460, 15329462]
[x, y, z].detect # => [15329460, 15329462]
Just in case, why build a hash?
answered Nov 14 '18 at 21:18
iGianiGian
4,4292625
4,4292625
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295692%2fcompared-elementes-of-hash-subtraction-ruby%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This question would be a lot easier on the eyes if the numbers were changed to 1-2 digits.
– Kimmo Lehto
Nov 14 '18 at 8:30
You're absolutely right, but I'm in college and the data they will give us is that long
– Alejandro Rodriguez
Nov 14 '18 at 8:36
1
You could edit it for us.
– Kimmo Lehto
Nov 14 '18 at 8:52
"we stop here and keep this in a counter can be" – what does that mean? How does your expected result look like?
– Stefan
Nov 14 '18 at 9:05
From where 8349314533 is coming? And 15329460 and 15329462?
– iGian
Nov 14 '18 at 13:42