Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA04
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christler Jefferson Mbouopda Fotie
IA04
Commits
025cadb8
Commit
025cadb8
authored
3 years ago
by
Sylvain Lagrue
Browse files
Options
Downloads
Patches
Plain Diff
permutations added
parent
66080155
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
go.mod
+3
-0
3 additions, 0 deletions
go.mod
go.sum
+0
-0
0 additions, 0 deletions
go.sum
utils/permutations.go
+58
-0
58 additions, 0 deletions
utils/permutations.go
with
62 additions
and
1 deletion
README.md
+
1
−
1
View file @
025cadb8
#
ia
04
#
Quelques utilitaires IA
04
This diff is collapsed.
Click to expand it.
go.mod
0 → 100644
+
3
−
0
View file @
025cadb8
module
gitlab.utc.fr/lagruesy/ia04
go 1.16
This diff is collapsed.
Click to expand it.
go.sum
0 → 100644
+
0
−
0
View file @
025cadb8
This diff is collapsed.
Click to expand it.
utils/permutations.go
0 → 100644
+
58
−
0
View file @
025cadb8
// Package utils provides some usefull tools for IA04
package
utils
// ReverseIntSlice reverses the given slice
func
ReverseIntSlice
(
a
[]
int
)
{
n
:=
len
(
a
)
for
i
:=
0
;
i
<
n
/
2
;
i
++
{
a
[
i
],
a
[
n
-
i
-
1
]
=
a
[
n
-
i
-
1
],
a
[
i
]
}
}
// Factorial returns the product of all positive integers less than or equal to n
func
Factorial
(
n
int
)
int
{
res
:=
1
for
i
:=
0
;
i
<=
n
;
i
++
{
res
*=
i
}
return
res
}
// FirstPermutation returns the slice of int [0, 1, ..., n]
func
FirstPermutation
(
n
int
)
(
a
[]
int
)
{
a
=
make
([]
int
,
n
)
for
i
:=
0
;
i
<
n
;
i
++
{
a
[
i
]
=
i
}
return
}
// NextPermutation returns the next lexicographical permutation of a slice a
// The result is stored in a new slice
func
NextPermutation
(
a
[]
int
)
(
res
[]
int
,
ok
bool
)
{
n
:=
len
(
a
)
res
=
make
([]
int
,
n
)
copy
(
res
,
a
)
if
n
<
2
{
return
res
,
false
}
k
:=
n
-
2
for
a
[
k
]
>=
a
[
k
+
1
]
{
k
--
if
k
<
0
{
return
res
,
false
}
}
l
:=
n
-
1
for
a
[
k
]
>=
a
[
l
]
{
l
--
}
res
[
k
],
res
[
l
]
=
res
[
l
],
res
[
k
]
ReverseIntSlice
(
res
[
k
+
1
:
])
return
res
,
true
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment