Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 591b1cc3 rédigé par Titouan CASTRO's avatar Titouan CASTRO
Parcourir les fichiers

newwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

parent 8c1b0d70
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 303 ajouts et 0 suppression
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/dev_efficace.iml" filepath="$PROJECT_DIR$/.idea/dev_efficace.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.8" />
<option name="languageVersion" value="1.8" />
</component>
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="KotlinJavaRuntime" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21" />
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.21/kotlin-stdlib-jdk8-1.8.21.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.8.21/kotlin-stdlib-1.8.21.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.21/kotlin-stdlib-common-1.8.21.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.21/kotlin-stdlib-jdk7-1.8.21.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.21/kotlin-stdlib-jdk8-1.8.21-javadoc.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.8.21/kotlin-stdlib-1.8.21-javadoc.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.21/kotlin-stdlib-common-1.8.21-javadoc.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.21/kotlin-stdlib-jdk7-1.8.21-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.21/kotlin-stdlib-jdk8-1.8.21-sources.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.8.21/kotlin-stdlib-1.8.21-sources.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.21/kotlin-stdlib-common-1.8.21-sources.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$USER_HOME$/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.21/kotlin-stdlib-jdk7-1.8.21-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/dev.iml" filepath="$PROJECT_DIR$/dev.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
\ No newline at end of file
fun main(args: Array<String>) {
println("Hello World!")
var test = arrayListOf<Int>(2,0,9,6,7,5,3,4)
println(test)
triSelection(test)
println(test)
// Try adding program arguments via Run/Debug configuration.
// Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html.
//println("Program arguments: ${args.joinToString()}")
println("Monaco's Flag! come on!")
//var flagM = Array<String>(12){"W";"R";"R";"W";"R";"W";"R";"W";"W"}
var flagM = arrayOf ("W","R","W","R","W","R","W","W","R","R","W","R")
println("Input Flag is, f")
for (s in flagM) {
print(" $s")
}
println()
/*
for (elt in flagM.iterator()) print (elt.toString()+" ")
println()
for (i in 0..flagM.size-1) print(flagM[i].toString()+" ")
*/
flagM = makeMonacoFlag(flagM)
println("Output Flag is, f")
for (elt in flagM.iterator()) print (elt.toString()+" ")
println("Euclide World!")
// Try adding program arguments via Run/Debug configuration.
// Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html.
val a = 57
val b = 11
val re :Pair<Int, Int> = euclideNat(a,b) /* returns a pair with Q, R */
println("Résultat de la division de $a par $b est : ${re.first} et reste ${re.second}")
}
fun triSelection(T : ArrayList<Int>){
require(T.filter { it >=0 }.size == T.size) {"pas bon"}
var N = T.size
var i=1
var k: Int
var m : Int
while(i != N+1){
k=i+1
m=i
while(k !=N+1){
if (T[k-1]<T[m-1]){
m = k
}
k+=1
}
T[i-1] = T[m-1].also{T[m-1]=T[i-1]}
i += 1
}
}
/*------------------------------------------
Correct construction of Monaco's flag
with systematic loop construction :
(invariant, stop condition, initialisation, progress, termination variant)
JCA - IUT - Nantes Université - Décembre 2022
------------------------------------------*/
fun makeMonacoFlag (flag : Array<String>):Array<String> {
/* rearrange Flag to make it as Monaco's Flag Red|White */
/*---preconditionn--- : Flag should contain either White or Red---*/
require(flag.isNotEmpty()) {"Input Flag should not be empty"}/* at least 1 element*/
require(flag.all { it == "W" || it == "R"}){"Flag data should contain only W or R"}
/*---init---*/
var posR = 0 /* it is endRed+1 */
val nbElt= flag.size /* it is startW-1*/
var posW = nbElt-1
var previousExpr : Int /* to check the decreasing variant*/
previousExpr = posW-posR
assert(previousExpr in -1..nbElt) {"Variant out of bounds"}
while(posR<=posW) {
/*---loop invariant ---*/
assert(
(flag.sliceArray(0..posR - 1)
.all { it == "R" }) /* from begining to endR-1 : there are red from startW+1 to end there are White*/
&& (flag.sliceArray(posW + 1..nbElt-1).all { it == "W" })
) {"Invariant violated"}
previousExpr = posW-posR
/*---progress---*/
if (flag[posW] == "W") {
posW-=1
} else { /* flag[posW] = "R" */
if (flag[posR] == "W") {
var tmp: String
tmp = flag[posW]
flag[posW] = flag[posR]
flag[posR] = tmp
posW -= 1
posR += 1
} else {
/* flag[posR]= "R"*/
posR+=1
}
}
/*---termination, VARIANT should decrease---*/
println("previous value = $previousExpr")
assert(previousExpr > posW-posR) {"Termination not ensured"}
}
return flag
}
/*--------------------------
Implementation in Kotlin of the Euclidian Division
December 7th, 2022
JCA, IUT, Nantes Université
--------------------------*/
fun euclideNat(a:Int, b: Int): Pair<Int,Int> {
// divides A per B, returns <quotient, rest>
var q:Int
var r:Int
var previousR : Int // Varaint Value: to deal with *Termination*
/*---precondition---*/
require((a>= 0) && (b > 0)) {"precondition not respected"}
/*---init---*/
q = 0
r = a
previousR = r
println("q= $q, r= $r, a= $a, b= $b")
while (r >= b){
/*invariant*/
assert((a==q*b+r) && (r>=b)){"invariant not true"}
/*---progress---*/
previousR = r
r -= b
q += 1
/*--- termination---*/
assert(previousR > r) {
"terminaision terms does not decrease"
}/* r should decrease at each iteration step */
}
/*---postcondition---*/
assert(a==q*b+r) {"postcondition not true"}
return Pair(q,r)
}
,E224359T,u-inf-j-e113-21,20.12.2023 10:14,file:///var/home/E224359T/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;
\ No newline at end of file
Fichier ajouté
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter