Archive

Posts Tagged ‘fortran’

Kombinatorik {n \choose k}: effiziente Berechnung der Varianten

April 14th, 2009 jens 1 comment

Ich hatte schon früher das Problem einen Algorithmus zu finden um alle Varianten der Positionierung von k Elementen auf n Plätzen zu ermitteln (also {n \choose k} Möglichkeiten der Positionierung), besonders wenns um Speichereffizenz (nicht alle Kombination speichern) geht. Jupp hat mich heut wieder auf das Problem gestoßen und ich hab endlich eine “schöne” Lösung gefunden (es wird nicht viel benötigt, nur ein paar Schleifen und die Berechnung des Binomialkoeff.):

program iterkombi
	implicit none
	integer(kind=4), parameter :: n=6, k=2
	integer(kind=4) :: tmpN, tmpK, ind, pos, i, j
	integer(kind=4), dimension(1:n) :: arrayP
	character(len=15) :: str
 
	! schleife über Nr. der Kombination
	do j=1, binomial(n,k), 1
		ind = j
		tmpN = n; tmpK = k
		pos = 0; arrayP = 0
		! jedes der k Elemente positionieren
		do i=1, k, 1
			pos = pos + 1
			do while( ind - binomial(tmpN-1,tmpK-1) > 0 )
				ind = ind - binomial(tmpN-1,tmpK-1)
				tmpN = tmpN - 1
				pos = pos + 1
			end do
			tmpN = n - pos
			tmpK = tmpK - 1
			arrayP( pos ) = 1
		end do
		write(str,*) n
		write(unit=*,fmt='(A,I0,A,A,'//str//'I1)') "Belegungsarray (Nr. ", j, "): ", char(9), arrayP
	end do
 
	contains
 
	function binomial( n,k )
		integer(kind=4) :: binomial
		integer(kind=4) :: n, k, i, x, y
		x = 1; y = 1
		do i=k+1, n, 1
			x = x*i 	! n!/k!
		end do
		do i=2, n-k, 1
			y = y*i 	! (n-k)!
		end do
		binomial = x / y
	end function
end program

Ausgabe:

Belegungsarray (Nr. 1): 	110000
Belegungsarray (Nr. 2): 	101000
Belegungsarray (Nr. 3): 	100100
Belegungsarray (Nr. 4): 	100010
Belegungsarray (Nr. 5): 	100001
Belegungsarray (Nr. 6): 	011000
Belegungsarray (Nr. 7): 	010100
Belegungsarray (Nr. 8): 	010010
Belegungsarray (Nr. 9): 	010001
Belegungsarray (Nr. 10): 	001100
Belegungsarray (Nr. 11): 	001010
Belegungsarray (Nr. 12): 	001001
Belegungsarray (Nr. 13): 	000110
Belegungsarray (Nr. 14): 	000101
Belegungsarray (Nr. 15): 	000011

Der Vorteil: es kann jede Kombination einzeln berechnet werden ohne zu wissen wie die vorherige Kombination aussah.

f95 snippets for gedit

April 6th, 2009 jens 1 comment

stefan used the “snippets” plugin while presenting us some code of his practical. these plugin is really powerful to reduce time while programming. fortran is supported by default, but there are no implemented snippets. so i searched some minutes for some snippets, but nothing.

i want this, so i have to implement it ;)
f95 snippets

Categories: linux, nerdcore, software Tags: , ,

Fortran77 4.0 Referenzhandbuch

March 21st, 2009 stefan No comments

Gerade benötigte ich einige detailiere Infos zu Fortran77-Datentypen und das weise Intenrnet hat wieder etwas tolles ausgespuckt. Auf der Webseite von SUN Microsystems gibt es nämlich ein über 500 Seiten starkes Handbuch zu Fortran. Das ganze steht auch als PDF kostenlos zum download bereit und zwar genau HIER.

Categories: software Tags: ,

wp-syntax

February 15th, 2009 robin 2 comments

mal sehen ob’s klapp … F90 pseudocode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module wp-syntax
implict none
 
contains
 
subroutine wp-syntax-avail-lang
    char(len=200),dimension(100) :: all_languages = (/ abap, actionscript, actionscript3, ada, apache,&
        & applescript, aptsources, asm, asp, autoit, avisynth, bash, bf, blitzbasic, bnf, boo, c, cmac,&
        & caddcl, cadlisp, cil, cfdg, cfm, cobol, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel,&
        & email, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict,&
        & idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, lolcode, &
        & lotusformulas, lotusscript, lscript, lua, m68k, make, matlab, mirc, mpasm, mxml, mysql, nsis, objc,&
        & ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php,&
        & plsql, povray, powershell, progress, prolog, providex, python, qbasic, rails, reg, robots, ruby, sas,&
        & scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript,&
        & vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, winbatch, xml, xorg_conf, xpp, z80 /)
    integer(kind=4) :: i
 
    do i=1, size(all_languages,1)
        write(*,*) all_languages(i)
    end do
 
end subroutine
Categories: nerdcore Tags: ,