Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

domenica 7 settembre 2008

little scala snippet


def showRow(arra: Array[int], molt: int, mod: int ,unitari : boolean ):Array[int] = {
val a2 = arra.map( s => ( s * molt ) % mod )

if ( unitari )
println ( a2.map( s => if ( s == 1 s == ( mod -1 ) ) 1 else 0 ).toString )
else
println( a2.toString )
a2
}

def shoMatr( mod: int , unitari : boolean ) {

println( if ( unitari ) "elementi unitari" else "tabella moltiplicativa" )

val array = new Array[int]( mod - 1 ).indices.map( s => s + 1 )

array.foreach( p => showRow( array , ( array indexOf p ) + 1 , mod , unitari ) )

}



Nessun commento: