zoukankan      html  css  js  c++  java
  • Predict your age!

    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

        sqrtss 求根号

        

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

  • 相关阅读:
    c++中sort()及qsort()的用法总结
    POJ的层次感分类
    DFS练习-HDU1010
    Dijkstra&&Floyd
    DFS练习一---HDU 1342
    快速幂取模算法
    树的实现
    C++的队列和pair
    BFS练习-POJ.2386
    Codeforces 1139E(二分图最大匹配)
  • 原文地址:https://www.cnblogs.com/pppyyyzzz/p/13633738.html
Copyright © 2011-2022 走看看