首页 > 其他 > 详细

Predict your age!

时间:2020-09-08 21:52:29      阅读:48      评论:0      收藏:0      [点我收藏+]
Description:

My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!

In honor of my grandfather‘s memory we will write a function using his formula!

  • Take a list of ages when each of your great-grandparent died.
  • Multiply each number by itself.
  • Add them all together.
  • Take the square root of the result.
  • Divide by two.

Example

predictAge(65, 60, 75, 55, 60, 63, 64, 45) === 86

Note: the result should be rounded down to the nearest integer.

Some random tests might fail due to a bug in the JavaScript implementation. Simply resubmit if that happens to you.

 

 

section .text
global predict_age
predict_age:
                imul    rdi, rdi
                imul    rsi, rsi
                imul    rdx, rdx
                imul    rcx, rcx
                imul    r8, r8
                imul    r9, r9
                mov     r10, [rsp + 8]
                imul    r10, r10
                mov     rax, [rsp + 16]
                imul    rax, rax
                add     rsi, rdi
                add     rcx, rdx
                add     r9, r8
                add     rax, r10
                add     rcx, rsi
                add     rax, r9
                add     rax, rcx
                cvtsi2ss    xmm0, rax
                sqrtss      xmm0, xmm0
                cvttss2si   rax, xmm0
                shr     rax, 1
                ret

相关指令:http://www.yjxsoft.com/forum.php?mod=viewthread&tid=6164

题目地址:https://www.codewars.com/kata/5aff237c578a14752d0035ae/solutions

Predict your age!

原文:https://www.cnblogs.com/pppyyyzzz/p/13633738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!