Number 20 factorial on java

Discussion in 'OT Technology' started by morgue, Jun 2, 2006.

  1. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    what problem would that cause? I think that the range values of of 'int' doesn't cover 20! is that it?
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    perl -e '$myrand = int(rand(25)); @list = (1,2,3,4,5,6,7,8,9,10,0,11,12,13,14,15,16,18,19,20); $isUnique = map { eval($_ == $myrand)} @list; print "$myrand is unique: $isUnique\n" unless $isUnique; print "$myrand is not unique: $isUnique\n" if $isUnique;'

    I don't really know what you're asking, but there's some novel perl code.
     
  3. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    suppose java could handle factorial like "3!" which would be 3*2*1=6

    What problem would this encounter? "20!"
     
  4. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Integer overflow, most likely.
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Wait a minute...was this a homework question?
     
  6. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    yes, i wanted to know if there's something else other than overflow of an int value... why?
     
  7. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Because asking (and answering) schoolwork questions is generally discouraged on OT; ethics and all that jazz.
     
  8. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    well that's dumn :S
     
  9. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    Float or Double work? I forget the max sizes, but i believe it's 2^127
     
  10. Kingfisher

    Kingfisher Keepin L's lit

    Joined:
    Mar 29, 2003
    Messages:
    4,736
    Likes Received:
    0
    Location:
    Southern California
    look up Fibonacci numbers

    private function fib(n as integer)
    return fib(n-1) + fib(n-2)

    something like that anyways, uses recursion.
     
  11. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    I don't know about Java, but in normal languages, float has less range than int does (since some of the 32 bits have to be used for the exponent and decimal places).

    Calculating 20! in C, it appears that it does indeed overflow a 32-bit integer (which isn't surprising).
     
  12. w0lverine

    w0lverine New Member

    Joined:
    Feb 22, 2005
    Messages:
    47
    Likes Received:
    0
    java.math.BigInteger is your friend :hsd:
     

Share This Page