nCr Engine(C++) + A joke

madurax86

Member
Jun 29, 2006
4,385
88
0
Java is abit high level on variables we can code somthing similar to that in vb6(using strings and it'll have a very high storage) but speed gets lower so i stayed with c++, in this one nCr is not only being calculated; the simplifying of factorials is done thru the code too:P
 

charmer

Active member
  • May 5, 2006
    1,694
    9
    38
    Colombo, Sri Lanka
    hi mate,
    can u make a random number generator which predticts the next drawing number (between 1-40) according to the previous 10 drawn numbers for bingo / lotto games please
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    charmer said:
    hi mate,
    can u make a random number generator which predticts the next drawing number (between 1-40) according to the previous 10 drawn numbers for bingo / lotto games please

    you can code it your self
    open up vb6
    draw a button, double click on it to goto code view
    and put this code in
    Code:
        Randomize
        MsgBox (Fix(Rnd * 39)+1)

    +1 is used to remove outputing 0 :P
    remove the (Fix(Rnd*39)+1) and put rnd*40 if you want real output too(this will only give integer output)
     
    Last edited:

    Im.Just.a.Fool

    Junior member
  • Apr 2, 2009
    202
    19
    18
    කියන්නෙම නෑ
    madurax86 said:
    Java is abit high level on variables we can code somthing similar to that in vb6(using strings and it'll have a very high storage) but speed gets lower so i stayed with c++, in this one nCr is not only being calculated; the simplifying of factorials is done thru the code too:P

    What is the range of long long in C++?

    If the range is from -2^63 to 2^63-1, the program I posted in #14 should work well when converted into C++.
     
    Last edited:

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Im.Just.a.Fool said:
    What is the range of long long in C++?

    If the range is -2^64 to 2^64-1, the program I posted in #14 should work well when converted into C++.

    dont know ban :P i just put it because double tends to use scientific notation at 6 numbers(i think) nCr needs precision more than that ne so I used the long long, and long long long turned out to be the joke :D
    Do you use the factorial simplification in ur code?
    like, nCr=fact(n)/fact(r)*fact(n-r)

    if (r>n-r),
    nCr=[(r+1)(r+2)(r+3)......(n-1)(n)]/(n-r)!

    if (r<n-r),
    nCr=[(n-r+1)(n-r+2)(n-r+3)......(n-1)(n)]/(n-r)!

    for another simplification do the integer dividing too, I did that in my code. If java has more variable length then use these too then the output will be much larger :D and faster
     

    Im.Just.a.Fool

    Junior member
  • Apr 2, 2009
    202
    19
    18
    කියන්නෙම නෑ
    madurax86 said:
    Do you use the factorial simplification in ur code?

    I did the following:

    n! / (r! * (n-r)!) = (n * (n-1) * ... * (n-r+2) * (n-r+1) ) / (1 * 2 *...*(n-1) * n)

    E.g. For n = 50 and r = 24,
    50! / (24! * 26!) = (50 * 49 *...*28 * 27) / (1 * 2 * ...* 23 * 24)

    ita passe (50 * 49 *...*28 * 27) wala prathamaka sadaka hoyala pf array eke values increment karanawa. E.g. number eka 24 nam pf[2] thun parak increment wenawa, pf[3] eka parak increment wenawa.

    ita passe (1 * 2 * ...* 23 * 24) wala prathamaka sadaka hoyala ewa pf array eke danata thiyena values walin adu karanawa.

    anthimata pf array eke ithuru wenne nCr wala prathamaka sadaka tika. ea tika wadi karala nCr calculate karanawa.
     
    Last edited:

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Im.Just.a.Fool said:
    kohoma hari C++ wala long long variable eka 32 bit walata wada wadi wenna one.

    nathnam nCr(51,25) = 247,959,266,474,052 value eka store karala thiyaganna bahane :D

    247,959,266,474,052 store karanna adu gane 48 bits one :)

    machine eka nam 64bit capable eth windows xp 32bit professional ne hari koma hari output wenawa ne :P
    oyage krame hodai prathamaka saadaka walata man balanne haraye tiyena numbers walin lawaye eka number ekak hari bedenawa nam purna sankyawak denna bedala harayai lawayai wenama sulu karala passe bedhanawa :D
     

    Im.Just.a.Fool

    Junior member
  • Apr 2, 2009
    202
    19
    18
    කියන්නෙම නෑ
    madurax86 said:
    machine eka nam 64bit capable eth windows xp 32bit professional ne hari koma hari output wenawa ne :P
    oyage krame hodai prathamaka saadaka walata man balanne haraye tiyena numbers walin lawaye eka number ekak hari bedenawa nam purna sankyawak denna bedala harayai lawayai wenama sulu karala passe bedhanawa :D


    ah ow eka thamai oyage program eken karanne. For e.g. for nCr(51, 25)

    x = 29 31 35 37 39 41 43 9 47 4 49 10 51
    y = 21 25 26

    kiyana values thamai ithuru wenne. anith numbers okkoma are nested for loops deken sulu karaddi kapila kapila yanawa :D


    n = 52 weddi x wala numbers wadi karaddi p variable eka overflow wenawa. ethakota thamai output eka waradinne
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Im.Just.a.Fool said:
    ah ow eka thamai oyage program eken karanne. For e.g. for nCr(51, 25)

    x = 29 31 35 37 39 41 43 9 47 4 49 10 51
    y = 21 25 26

    kiyana values thamai ithuru wenne. anith numbers okkoma are nested for loops deken sulu karaddi kapila kapila yanawa :D


    n = 52 weddi x wala numbers wadi karaddi p variable eka overflow wenawa. ethakota thamai output eka waradinne

    yup eka thama 51ta witharak thibbe
    wena kramyak ahu une na thawa optimize karanna oya range ekatama
     

    Im.Just.a.Fool

    Junior member
  • Apr 2, 2009
    202
    19
    18
    කියන්නෙම නෑ
    madurax86 said:
    yup eka thama 51ta witharak thibbe
    wena kramyak ahu une na thawa optimize karanna oya range ekatama


    machan are you a university student or still schooling?

    mata business programming wadiya allanne naha :no:. me wage ewatanam kamathi :D


    But I'm just a fool so moley bohoma aduwen thamai wada karanne :rofl:. padam karannath hari kammali. godak aya danna dewal walin bagayakwath mama danne na.

    Scientific programming/System programming karana ayata lankawe jobs thiyenawada?
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Im.Just.a.Fool said:
    machan are you a university student or still schooling?

    mata business programming wadiya allanne naha :no:. me wage ewatanam kamathi :D


    But I'm just a fool so moley bohoma aduwen thamai wada karanne :rofl:. padam karannath hari kammali. godak aya danna dewal walin bagayakwath mama danne na.

    Scientific programming/System programming karana ayata lankawe jobs thiyenawada?

    just a student still :P thama uni giye naa
    ehema hithanna epaa programming walata moleta wadaa one creativity im sure you can find a better job if you dont get on to the normal business/database based programming courses i recon UCSC post graduate karanna puluwan nam hodai habai un uth lankawe anith aya wagema thama unicode wade patan gaththama mata hodata theruna unge hatith(only the profs and academic staff not the students) reply ekak wath naa mail ekata anthimedi manma thaniyen hoya gaththaa :P ohoma thamaa
    goto my blog for more info on that
    if want a new release of the prog download this the one in the blog is abit old
    this one has a bug too it cant type numbers :P fixed that i'll up it later, im going now tc
    http://madurax86.comuv.com/Unicode.zip