How to find the smallest number that is evenly divisible by all of the numbers from 1 to 20



  • Here's a Javascript implementation:
    function guess()
    {
    var smallest = parseInt(prompt('What is the smallest factor you want?',1)),
    largest = parseInt(prompt('What is the largest factor you want?',20),
    guess = parseFloat(prompt('OK, what do you *think* the smallest number that is evenly divisible by all the numbers from ' + smallest + ' to ' + largest ' is?',smallest * largest));
    if (isNaN(numbr) || isNaN(guess)) return;

    for { i = smallest; i <= largest; i++}
    {
    if(guess % i > 0){
    alert(guess + ' is the wrong answer! Better luck next time.');
    return;
    }
    }

    alert(guess + ' is the right answer! I hope you remember what the question was.');
    }


  • Here's my fibonacci implementation:

    TITLE Fibonacci
    ; Description: Write a program that computes the first 12 numbers of the fibonacci sequence
    ; Author: jjacksonRIAB

    .code

        COUNT    equ 12 ; first 12 numbers of the Fibonacci sequence
        
    main PROC
        
        ;               Zero out these registers
        xor           eax, eax
        xor           ebx, ebx
        
        ;               Initialize ecx
        mov          ecx, COUNT    
        
    Fibonacci:


        inc           ebx
        dec          eax
        xadd        ebx, eax
       
        loop         Fibonacci
        exit
        
    main ENDP

    END main

    If you can beat 3 actual instructions and a loop in assembly language, I'd like to see your solution.



  • This is a month-old thread that you guys resurrected.  If it hits the front page, discuss it there, please do not resurrect the original thread.

     

    Mods:  You know what to do. 



  •  


Log in to reply