English
Source / code snippets

Partitionierungen on the example "Meterstab in items hacken"

 

p.specht

In which and wieviele different "Zerhackungs-Anordnungen" can a Meßstab of z.B. 70 cm length chop, presupposed The slice are äusserst thinly (laser?) and any Einzelteile must 1 cm or one multiple of it long his? thereby should The physische order the Einzelstücke alike his, together must tappt im dunkeln only 70 cm yield.

The question diving u.a. in the Wellenphysik, in the technical chemistry, but too at pack of Standardprodukten in vorggegebene boxes on. The gentlemen Zoghbi and Stojmenovic could moreover 1998 Your ZS1-Algorithmus present, the still viermal faster as any recent was. In reinem XProfan need one naturally something longer as in Maschinencode, but for demonstration-Zwecken reicht the nachstehende Machwerk thoroughly. The response: 70 can on 4.087.967 types in items chopped plus once integrally let go.


Quellenangabe: item from "Fast Algorithms for Generating Integer Partitions. international journal of computer Mathematics, 70, 1998" 
Window Title "Algorithm ZS1: Erzeugung of/ one complete, "+\
"revers-geordneten Partitionierung without Wiederholung"
'Q: Antoine Zoghbi, Ivan Stojmenovic: almost Algorithms for Generating Integer Partitions
'   published in: "International journal of computer Mathematics, 70, 1998, 319-332."
's: [url]https://citeseerx.is.psu.edu/viewdoc/download?doi=10.1.1.42.1287&rep=rep1&type=pdf[/url]
'T: Translation to XProfan 11.2a 2016-07ff by P.woodpecker, Vienna/Austria
'No Warranty whatsoever! without jedwede Gewähr! legal situation ungeprüft.
Window Style 24:Window 0,0-%maxx,%maxy:font 2:randomize
declare z$,z&,tm&,cnt&,bench&:   Rept:
Cls:Print "\n  ZAHL, The partitioniert go should (0: Ende; Minuszahl: only Zeitmessung)? : ";
z$="":input z$:bench&=0:case val(z$)<0:bench&=1:z&=rnd(30):case z$>"":z&=abs(val(z$))

if z&=0:print "\n  Result: vain crowd.\n\n  Program ends! ":beep:waitinput 4000:END:endif

    case bench&:print "\n  Messung runs ..."
    tm&=&GetTickCount
    cnt& = Algorithm_ZS1(z&,bench&)
    print "\n  ";cnt&;" Partitionen created."

    if bench& : tm&=&GetTickCount-tm&

        print "\n  Laufzeit for n = ";z&;": ";tm&;" [ms] or. ";tm&/1000;" [s] or. ";tm&/60000;" [mins]"

    endif

    sound 2000,60
    waitinput
    Goto "Rept"
    END

    Proc Algorithm_ZS1 :parameters n&,bench&

        declare x&[n&],i&,m&,h&,r&,t&,cnt&

        whileloop n&

            x&[&loop]=1

        endwhile

        x&[1]=n&
        m&=1:h&=1
        cnt&=1
        casenot bench&:print "\n>>> ";x&[1]'show or do something useful

        while x&[1]<>1

            if x&[h&]=2'Easy case, applies often

                ' h is the index of the last part of partition which is greater than 1
                ' m is the number of parts.
                inc m&:x&[h&]=1:dec h&

            else

                r&=x&[h&]-1
                t&=m&-h&+1
                x&[h&]=r&

                while t&>=r&

                    inc h&
                    x&[h&]=r&
                    t&=t&-r&

                endwhile

                if t&=0

                    m&=h&

                else

                    m&=h&+1

                    if t&>1

                        inc h&:x&[h&]=t&

                    endif

                endif

            endif

            inc cnt&

            ifnot bench&:print "    ";:whileloop m&:print x&[&Loop],:endwhile:print:endif

                'or do something useful with the result line

            endwhile

            return cnt&

        ENDPROC

 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/20/21  
 




p.specht

here The AUFSTEIGENDE Version the Partitionierungsmethode: The ZS2-Algorithmus, replenished as appendix to that obigen Posting.
Window Title "Algorithm ZS2: Erzeugung of/ one complete, "+\
"AUFSTEIGEND geordneten Partitionierung without Wiederholung"
'Q: Antoine Zoghbi, Ivan Stojmenovic: almost Algorithms for Generating Integer Partitions
'   published in: "International journal of computer Mathematics, 70, 1998, 319-332."
's: https://citeseerx.is.psu.edu/viewdoc/download?doi=10.1.1.42.1287&rep=rep1&type=pdf
'T: Translation to XProfan 11.2a 2016-07ff by P.woodpecker, Vienna/Austria
'No Warranty whatsoever! without jedwede Gewähr!
'
'Test your results against "Partition Numbers" of https://oeis.org/A000041
'00>>> 1, 1, 2, 3, 5,   7, 11, 15, 22, 30,
'10>>> 42, 56, 77, 101, 135,   176, 231, 297, 385, 490,
'20>>> 627, 792, 1002, 1255, 1575,   1958, 2436, 3010, 3718, 4565,
'30>>> 5604, 6842, 8349, 10143, 12310,   14883, 17977, 21637, 26015, 31185,
'40>>> 37338, 44583, 53174, 63261, 75175,   89134, 105558, 124754, 147273,173525
'50>>> ...
Window Style 24:Window 0,0-%maxx,%maxy:randomize:font 2
declare z$,z&,tm&,cnt&,bench&:   Rept:
Cls:Print "\n  ZAHL, which partitioniert go should (0: Ende; Minuszahl: only Zeitmessung)? : ";
z$="":input z$:bench&=0:case val(z$)<0:bench&=1:z&=rnd(30):case z$>"":z&=abs(val(z$))

if z&=0:print "\n  Result: vain crowd.\n\n  Program ends! ":beep:waitinput 4000:END:endif

    case bench&:print "\n  Messung runs ..."
    tm&=&GetTickCount
    cnt& = Algorithm_ZS2(z&,bench&)
    tm&=&GetTickCount-tm&
    print "\n  ";cnt&;" Partitionen created."

    if bench&:print "\n  Laufzeit for n = ";z&;": ";tm&;" [ms] or. ";tm&/1000;" [s] or. ";tm&/60000;" [mins]"

        endif :sound 2000,60:waitinput
        Goto "Rept"
        END

        Proc Algorithm_ZS2 :parameters n&,bench&

            declare x&[n&],i&,m&,h&,r&,j&,cnt&

            if n&=1:print "       ";1 :cnt&=1:goto "ZS2_exit":endif

                :whileloop n&:x&[&loop]=1:endwhile
                cnt&=1

                ifnot bench&:print "\n>>> ";:whileloop n&:print x&[&Loop],:endwhile:print

                endif'or do something useful with the result line

                x&[0]=-1:x&[1]=2:m&=n&-1:h&=1:inc cnt&

                ifnot bench&:print "    ";:whileloop m&:print x&[&Loop],:endwhile:print

                endif'or do something useful with the result line

                while x&[1]<>n&

                    if (m&-h&)>1

                        inc h&
                        x&[h&]=2
                        dec m&

                    else

                        j&=m&-2

                        While x&[j&]=x&[m&-1]

                            x&[j&]=1
                            dec j&

                        endwhile

                        h&=j&+1
                        x&[h&]=x&[m&-1]+1
                        r&=x&[m&]+x&[m&-1]*(m&-h&-1)
                        x&[m&]=1
                        case (m&-h&)>1:x&[m&-1]=1
                        m&=h&+r&-1

                    endif

                    inc cnt&

                    ifnot bench&:print "    ";:whileloop m&:print x&[&Loop],:endwhile:print:endif

                        'or do something useful with the result line

                    endwhile

                    ZS2_exit:
                    return cnt&

                ENDPROC

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/20/21  
 




p.specht

Partitionen the length 1 To max. M count
-----------------------------------------------------
enclosed one rekursives Zählprogramm for amount möglicher Zerschnipselungen (="Partitionen") one n units long Stabes (="Anordnung of Elementen") in Teilstrecken the length of 1 To maximum M (= "Klassen To Klassengröße M").
Window Title "Teilungsmöglichkeiten zählen":Window Style 24:cls
Print "\n this Program counts The possible Teilungen of n Elementen"
print "\n for zulässige Teilungsgrößen of 1 To M Elementen.\n"
declare n&,m&,count!
again:
clear n&,m&,count!
print "\n    Gesamtlänge n = ";:input n&
print "\n Max. Teillänge M = ";:input m&
print "\n Count yields ";stature$("%g",Count_partitions(n&,m&));" possible Teilungen!\n"
waitinput:cls:goto "nochmal"

proc count_partitions :parameters n&,m&

    if n&=0:return 1

    elseif n&<0:return 0

    elseif m&=0:return 0

    else

        return count_partitions(n&-m&,m&)+count_partitions(n&,m&-1)

    endif

Endproc


Probe: count(6,4) ought to 9 yield:

6 = 2 + 4
6 = 1 + 1 + 4
6 = 3 + 3

6 = 1 + 2 + 3
6 = 1 + 1 + 1 + 3
6 = 2 + 2 + 2

6 = 1 + 1 + 2 + 2
6 = 1 + 1 + 1 + 1 + 2
6 = 1 + 1 + 1 + 1 + 1 + 1

... is correct means!
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/24/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.989 Views

Untitledvor 0 min.
p.specht11/20/21
Uwe Lang11/20/21
Manfred Barei11/19/21
Wilfried Friebe11/17/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (3x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie