├── r ├── "\?$*'ChouMi'*$?\" ├── README.md ├── student ├── quest8.txt ├── raid2 ├── revparams ├── sortparams ├── printparams ├── printprogramname └── raid1c.go ├── displayfile ├── quest8.txt └── main.go ├── hello.sh ├── skip.sh ├── countfiles.sh ├── my_answer.sh ├── displaya ├── pointone.go ├── raid1a └── raid1a ├── raid1b └── raid1b ├── raid1c └── raid1c ├── raid1d └── raid1d ├── raid1e └── raid1e ├── raid3 ├── raid3 ├── raid1a │ └── raid1a ├── raid1b │ └── raid1b ├── raid1c │ └── raid1c ├── raid1d │ └── raid1d ├── raid1e │ └── raid1e └── raid3.go ├── mastertheLS ├── listclear.go ├── swap.go ├── look ├── revparams ├── revparams └── revparams.go ├── displaya.go ├── printparams ├── printparams └── printparams.go ├── sortparams ├── sortparams └── sortparams.go ├── strlen.go ├── to-git-or-not-to-git.sh ├── ultimatepointone.go ├── onlya.go ├── onlyz.go ├── cat ├── quest8.txt ├── quest8T.txt └── main.go ├── displayz.go ├── printnbr.go ├── lookagain.sh ├── printdigits └── main.go ├── firstrune.go ├── nrune.go ├── printprogramname ├── printprogramname └── printprogramname.go ├── lastrune.go ├── foreach.go ├── hello.go ├── printalphabet └── main.go ├── sortwordarr.go ├── tolower.go ├── toupper.go ├── divmod.go ├── pilot.go ├── index.go ├── split.go ├── compare.go ├── concat.go ├── ultimatedivmod.go ├── who-are-you.sh ├── printwordstables.go ├── splitwhitespaces.go ├── isalpha.go ├── isnumeric.go ├── printstr.go ├── countdown.go ├── abort.go ├── activebits.go ├── basicjoin.go ├── isnegative.go ├── any.go ├── btreemin.go ├── btreemax.go ├── max.go ├── atoi.go ├── myfamily.sh ├── enigma.go ├── basicatoi.go ├── basicatoi2.go ├── map.go ├── compact.go ├── islower.go ├── isupper.go ├── findnextprime.go ├── isprintable.go ├── strrev.go ├── join.go ├── concatparams.go ├── fibonacci.go ├── listlast.go ├── btreeapplyinorder.go ├── btreeapplypreorder.go ├── btreeapplypostorder.go ├── pilot └── main.go ├── listsize.go ├── countif.go ├── listreverse.go ├── recursivepower.go ├── sortintegertable.go ├── unmatch.go ├── listat.go ├── collatz.go ├── point └── main.go ├── sqrt.go ├── btreelevelcount.go ├── iterativepower.go ├── capitalize.go ├── btreesearchitem.go ├── printreversealphabet └── main.go ├── listmerge.go ├── isprime.go ├── listfind.go ├── listpushback.go ├── iterativefactorial.go ├── comcheck └── main.go ├── recursivefactorial.go ├── rot14.go ├── appendrange.go ├── makerange.go ├── listpushfront.go ├── sortedlistmerge.go ├── sortlistinsert.go ├── btreetransplant.go ├── advancedsortwordarr.go ├── issorted.go ├── btreeisbinary.go ├── printcomb.go ├── listremoveif.go ├── raid1a.go ├── btreeinsertdata.go ├── atoibase.go ├── listforeach.go ├── listsort.go ├── printcombn.go ├── raid1c.go ├── btreedeletenode.go ├── boolean └── main.go ├── eightqueens.go ├── raid1b.go ├── printcomb2.go ├── listforeachif.go ├── btreeapplybylevel.go ├── convertbase.go ├── ztail └── main.go ├── printnbrbase.go ├── fixthemain └── main.go ├── doop └── main.go ├── raid1e.go ├── raid1d.go ├── main └── raid2.go ├── raid2 └── raid2.go └── done.tar /r: -------------------------------------------------------------------------------- 1 | R 2 | -------------------------------------------------------------------------------- /"\?$*'ChouMi'*$?\": -------------------------------------------------------------------------------- 1 | 01 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # piscine-go -------------------------------------------------------------------------------- /student/quest8.txt: -------------------------------------------------------------------------------- 1 | Almost there!! -------------------------------------------------------------------------------- /displayfile/quest8.txt: -------------------------------------------------------------------------------- 1 | Almost there!! -------------------------------------------------------------------------------- /hello.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hello GreyCoderK!" -------------------------------------------------------------------------------- /skip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ls -l | sed '1d; n; d' -------------------------------------------------------------------------------- /countfiles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find . -type f,d | wc -l -------------------------------------------------------------------------------- /my_answer.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | echo "Dartey Henv" 4 | 5 | -------------------------------------------------------------------------------- /displaya: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/displaya -------------------------------------------------------------------------------- /pointone.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func PointOne(n *int) { 4 | *n = 1 5 | } 6 | -------------------------------------------------------------------------------- /raid1a/raid1a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid1a/raid1a -------------------------------------------------------------------------------- /raid1b/raid1b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid1b/raid1b -------------------------------------------------------------------------------- /raid1c/raid1c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid1c/raid1c -------------------------------------------------------------------------------- /raid1d/raid1d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid1d/raid1d -------------------------------------------------------------------------------- /raid1e/raid1e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid1e/raid1e -------------------------------------------------------------------------------- /raid3/raid3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid3 -------------------------------------------------------------------------------- /student/raid2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/student/raid2 -------------------------------------------------------------------------------- /mastertheLS: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ls -CF --format=commas --tabsize=0 -t | sed 's/ //g' -------------------------------------------------------------------------------- /listclear.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListClear(l *List) { 4 | l.Head = nil 5 | } 6 | -------------------------------------------------------------------------------- /student/revparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/student/revparams -------------------------------------------------------------------------------- /student/sortparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/student/sortparams -------------------------------------------------------------------------------- /swap.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Swap(a *int, b *int) { 4 | *a, *b = *b, *a 5 | } 6 | -------------------------------------------------------------------------------- /look: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find . \( -type d,f \) \( -name "a*" -o -name "*z" -o -name "z*a!" \) -------------------------------------------------------------------------------- /raid3/raid1a/raid1a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid1a/raid1a -------------------------------------------------------------------------------- /raid3/raid1b/raid1b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid1b/raid1b -------------------------------------------------------------------------------- /raid3/raid1c/raid1c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid1c/raid1c -------------------------------------------------------------------------------- /raid3/raid1d/raid1d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid1d/raid1d -------------------------------------------------------------------------------- /raid3/raid1e/raid1e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/raid3/raid1e/raid1e -------------------------------------------------------------------------------- /revparams/revparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/revparams/revparams -------------------------------------------------------------------------------- /student/printparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/student/printparams -------------------------------------------------------------------------------- /displaya.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func main(){ 6 | fmt.Print("a\n") 7 | } 8 | -------------------------------------------------------------------------------- /printparams/printparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/printparams/printparams -------------------------------------------------------------------------------- /sortparams/sortparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/sortparams/sortparams -------------------------------------------------------------------------------- /strlen.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func StrLen(ch string) int { 4 | return len([]rune(ch)) 5 | } 6 | -------------------------------------------------------------------------------- /to-git-or-not-to-git.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl https://api.github.com/users/greycoderk | jq '.id' -------------------------------------------------------------------------------- /ultimatepointone.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func UltimatePointOne(n ***int) { 4 | ***n = 1 5 | } 6 | -------------------------------------------------------------------------------- /onlya.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func onlya(){ 6 | fmt.Print("a") 7 | } 8 | -------------------------------------------------------------------------------- /onlyz.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func onlyz(){ 6 | fmt.Print("z") 7 | } 8 | -------------------------------------------------------------------------------- /student/printprogramname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/student/printprogramname -------------------------------------------------------------------------------- /cat/quest8.txt: -------------------------------------------------------------------------------- 1 | "Programming is a skill best acquired by pratice and example rather than from books" by Alan Turing -------------------------------------------------------------------------------- /displayz.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func displayz(){ 6 | fmt.Println("z\n") 7 | } 8 | -------------------------------------------------------------------------------- /printnbr.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func PrintNbr(n int) { 6 | fmt.Print(n) 7 | } 8 | -------------------------------------------------------------------------------- /lookagain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find . \( -type d,f \) -name "*.sh" | sort -r | sed 's/.sh//g' | sed 's/^.*\///g' -------------------------------------------------------------------------------- /printdigits/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("0123456789") 7 | } 8 | -------------------------------------------------------------------------------- /firstrune.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func FirstRune(s string) rune { 4 | res := []rune(s) 5 | return res[0] 6 | } 7 | -------------------------------------------------------------------------------- /nrune.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func NRune(s string, x int) rune { 4 | res := []rune(s) 5 | return res[x-1] 6 | } 7 | -------------------------------------------------------------------------------- /printprogramname/printprogramname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreyCoderK/piscine-go/HEAD/printprogramname/printprogramname -------------------------------------------------------------------------------- /lastrune.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func LastRune(s string) rune { 4 | res := []rune(s) 5 | return res[len(res)-1] 6 | } 7 | -------------------------------------------------------------------------------- /foreach.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ForEach(f func(int), arr []int) { 4 | for _,res:= range arr{ 5 | f(res) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /hello.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func hello(){ 6 | fmt.Println("Hello World!") 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /printalphabet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main(){ 6 | fmt.Println("abcdefghijklmnopqrstuvwxyz") 7 | } -------------------------------------------------------------------------------- /sortwordarr.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "sort" 4 | 5 | func SortWordArr(array []string) { 6 | sort.Strings(array) 7 | } 8 | -------------------------------------------------------------------------------- /tolower.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func ToLower(s string) string { 6 | return strings.ToLower(s) 7 | } 8 | -------------------------------------------------------------------------------- /toupper.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func ToUpper(s string) string { 6 | return strings.ToUpper(s) 7 | } 8 | -------------------------------------------------------------------------------- /divmod.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func DivMod(a, int, b int,enerveur int ,div *int, mod *int) { 4 | *div = a / b 5 | *mod = a % b 6 | } 7 | -------------------------------------------------------------------------------- /pilot.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | type Pilot struct { 4 | Name string 5 | Life float32 6 | Age int 7 | Aircraft int 8 | } 9 | -------------------------------------------------------------------------------- /index.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func Index(s string, toFind string) int { 6 | return strings.Index(s, toFind) 7 | } 8 | -------------------------------------------------------------------------------- /split.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func Split(str, charset string) []string { 6 | return strings.Split(str,charset) 7 | } 8 | -------------------------------------------------------------------------------- /compare.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func Compare(s string, toFind string) int { 6 | return strings.Compare(s, toFind) 7 | } 8 | -------------------------------------------------------------------------------- /concat.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Concat(str1 string, str2 string) string { 4 | concat := "" 5 | concat = str1 + str2 6 | return concat 7 | } 8 | -------------------------------------------------------------------------------- /ultimatedivmod.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func UltimateDivMod(div *int, mod *int) { 4 | x := *div 5 | *div = *div / *mod 6 | *mod = x % *mod 7 | } 8 | -------------------------------------------------------------------------------- /who-are-you.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl https://raw.githubusercontent.com/kigiri/superhero-api/master/api/all.json | jq '. [] | select( .id == 70) | .name' -------------------------------------------------------------------------------- /printprogramname/printprogramname.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main(){ 9 | fmt.Println(os.Args[0]) 10 | } 11 | -------------------------------------------------------------------------------- /printwordstables.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func PrintWordsTables(table []string) { 6 | fmt.Print(ConcatParams(table)) 7 | fmt.Print("\n") 8 | } 9 | -------------------------------------------------------------------------------- /splitwhitespaces.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func SplitWhiteSpaces(str string) []string { 6 | tab := strings.Fields(str) 7 | return tab 8 | } 9 | -------------------------------------------------------------------------------- /isalpha.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "regexp" 4 | 5 | func IsAlpha(str string) bool { 6 | re := regexp.MustCompile("^[a-zA-Z0-9_]*$") 7 | return re.MatchString(str) 8 | } 9 | -------------------------------------------------------------------------------- /isnumeric.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "regexp" 4 | 5 | func IsNumeric(str string) bool { 6 | re := regexp.MustCompile("^[0-9_]*$") 7 | return re.MatchString(str) 8 | } 9 | -------------------------------------------------------------------------------- /printstr.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func PrintStr(s string) { 6 | for _, r := range s { 7 | z01.PrintRune(r) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /countdown.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func countdown(){ 6 | i := 9 7 | for i > 0 { 8 | fmt.Print(i) 9 | i-- 10 | } 11 | fmt.Print("\n") 12 | } 13 | -------------------------------------------------------------------------------- /abort.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "sort" 4 | 5 | func Abort(a, b, c, d, e int) int { 6 | tab := []int{a, b, c, d, e} 7 | sort.Ints(tab) 8 | return tab[2] 9 | } 10 | 11 | -------------------------------------------------------------------------------- /activebits.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ActiveBits(n int) uint { 4 | compte := 0 5 | for n > 0 { 6 | compte += n & 1 7 | n >>= 1 8 | } 9 | return uint(compte) 10 | } 11 | -------------------------------------------------------------------------------- /basicjoin.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BasicJoin(strs []string) string { 4 | concat := "" 5 | for _, res := range strs { 6 | concat += res 7 | } 8 | return concat 9 | } 10 | -------------------------------------------------------------------------------- /isnegative.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func IsNegative(nb int) { 6 | if nb >= 0 { 7 | fmt.Println("F") 8 | } else { 9 | fmt.Println("T") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /any.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Any(f func(string) bool, arr []string) bool { 4 | for _,res:= range arr { 5 | if f(res) { 6 | return true 7 | } 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /btreemin.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeMin(root *TreeNode) *TreeNode { 4 | if root == nil || root.Left == nil { 5 | return root 6 | } 7 | 8 | return BTreeMin(root.Left) 9 | } 10 | -------------------------------------------------------------------------------- /btreemax.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeMax(root *TreeNode) *TreeNode { 4 | if root == nil || root.Right == nil { 5 | return root 6 | } 7 | 8 | return BTreeMax(root.Right) 9 | } 10 | -------------------------------------------------------------------------------- /max.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Max(arr []int) int { 4 | max := arr[0] 5 | for i:=1; i < len(arr); i++ { 6 | if max < arr[i] { 7 | max = arr[i] 8 | } 9 | } 10 | return max 11 | } 12 | -------------------------------------------------------------------------------- /atoi.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strconv" 4 | 5 | func Atoi(s string) int { 6 | i, err := strconv.Atoi(s) 7 | 8 | if err == nil { 9 | return i 10 | }else{ 11 | return 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /myfamily.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl https://raw.githubusercontent.com/kigiri/superhero-api/master/api/all.json | jq --argjson id "$HERO_ID" '. [] | select(.id == $id) | .connections.relatives' | sed 's/^"\(.*\)"$/\1/' -------------------------------------------------------------------------------- /printparams/printparams.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | ) 7 | 8 | func main(){ 9 | args := os.Args[1:] 10 | for _,res:= range args{ 11 | fmt.Println(res) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /enigma.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Enigma(a ***int, b *int, c *******int, d ****int) { 4 | x:= *******c 5 | *******c = ***a 6 | y := ****d 7 | ****d = x 8 | z:= *b 9 | *b = y 10 | ***a=z 11 | } 12 | -------------------------------------------------------------------------------- /revparams/revparams.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | ) 7 | 8 | func main(){ 9 | args := os.Args[1:] 10 | for i:= len(args)-1;i>=0;i--{ 11 | fmt.Println(args[i]) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /basicatoi.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strconv" 4 | 5 | func BasicAtoi(s string) int { 6 | i, err := strconv.Atoi(s) 7 | 8 | if err == nil { 9 | return i 10 | }else{ 11 | return 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /basicatoi2.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strconv" 4 | 5 | func BasicAtoi2(s string) int { 6 | i, err := strconv.Atoi(s) 7 | 8 | if err == nil { 9 | return i 10 | }else{ 11 | return 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /map.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Map(f func(int) bool, arr []int) []bool { 4 | 5 | fin:= make([]bool, len(arr)) 6 | 7 | for i, res:= range arr { 8 | fin[i] = f(res) 9 | } 10 | 11 | return fin 12 | } 13 | -------------------------------------------------------------------------------- /compact.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Compact(ptr *[]string, length int) int { 4 | compte := 0 5 | for i:=0; i < length; i++{ 6 | if (*ptr)[i] != " " { 7 | compte++ 8 | } 9 | } 10 | return compte 11 | } 12 | -------------------------------------------------------------------------------- /islower.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "unicode" 4 | 5 | func IsLower(str string) bool { 6 | for _, res := range str { 7 | if !unicode.IsLower(res) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /isupper.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "unicode" 4 | 5 | func IsUpper(str string) bool { 6 | for _, res := range str { 7 | if !unicode.IsUpper(res) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /findnextprime.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func FindNextPrime(nb int) int { 4 | if IsPrime(nb) { 5 | return nb 6 | } else { 7 | n := nb + 1 8 | for IsPrime(n) == false { 9 | n++ 10 | } 11 | return n 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /isprintable.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "unicode" 4 | 5 | func IsPrintable(str string) bool { 6 | for _, res := range str { 7 | if !unicode.IsPrint(res) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /strrev.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func StrRev(s string) string { 4 | chars := []rune(s) 5 | for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 { 6 | chars[i], chars[j] = chars[j], chars[i] 7 | } 8 | return string(chars) 9 | } 10 | -------------------------------------------------------------------------------- /join.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Join(strs []string, sep string) string { 4 | concat := "" 5 | for i, res := range strs { 6 | concat += res 7 | if i != len(strs)-1 { 8 | concat += sep 9 | } 10 | } 11 | return concat 12 | } 13 | -------------------------------------------------------------------------------- /concatparams.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ConcatParams(args []string) string { 4 | str := "" 5 | 6 | for i,res:= range args { 7 | str += string(res) 8 | if i != len(args) - 1 { 9 | str += "\n" 10 | } 11 | } 12 | return str 13 | } 14 | -------------------------------------------------------------------------------- /fibonacci.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Fibonacci(x int) int { 4 | if x < 0 { 5 | return -1 6 | } else if 0 == x { 7 | return 0 8 | } else if 1 == x || 2 == x { 9 | return 1 10 | } else { 11 | return Fibonacci(x-1) + Fibonacci(x-2) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /listlast.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListLast(l *List) interface{} { 4 | if l.Head == nil { 5 | return nil 6 | }else{ 7 | current := l.Head 8 | for current.Next != nil { 9 | current = current.Next 10 | } 11 | return current.Data 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /btreeapplyinorder.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) { 4 | if root == nil { 5 | return 6 | } 7 | BTreeApplyInorder(root.Left, f) 8 | f(root.Data) 9 | BTreeApplyInorder(root.Right, f) 10 | } 11 | -------------------------------------------------------------------------------- /btreeapplypreorder.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) { 4 | if root == nil { 5 | return 6 | } 7 | f(root.Data) 8 | BTreeApplyPreorder(root.Left, f) 9 | BTreeApplyPreorder(root.Right, f) 10 | } 11 | -------------------------------------------------------------------------------- /btreeapplypostorder.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeApplyPostorder(root *TreeNode, f func(...interface{}) (int, error)) { 4 | if root == nil { 5 | return 6 | } 7 | BTreeApplyPostorder(root.Left, f) 8 | BTreeApplyPostorder(root.Right, f) 9 | f(root.Data) 10 | } 11 | -------------------------------------------------------------------------------- /pilot/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | piscine ".." 6 | ) 7 | 8 | func main() { 9 | var donnie piscine.Pilot 10 | donnie.Name = "Donnie" 11 | donnie.Life = 100.0 12 | donnie.Age = 24 13 | donnie.Aircraft = 1 14 | 15 | fmt.Println(donnie) 16 | } 17 | -------------------------------------------------------------------------------- /listsize.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListSize(l *List) int { 4 | if l.Head == nil{ 5 | return 0 6 | }else{ 7 | current := l.Head 8 | cmpt := 1 9 | for current.Next != nil { 10 | current = current.Next 11 | cmpt++ 12 | } 13 | return cmpt 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /countif.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func CountIf(f func(string) bool, arr []string) int { 4 | compte := 0 5 | for _,res:= range arr { 6 | if f(res) { 7 | compte += 1 8 | } 9 | } 10 | return compte 11 | } 12 | -------------------------------------------------------------------------------- /listreverse.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListReverse(l *List) { 4 | current := l.Head 5 | var prev *NodeL 6 | 7 | for current != nil { 8 | next := current.Next 9 | current.Next = prev 10 | prev = current 11 | current = next 12 | } 13 | 14 | l.Head = prev 15 | } 16 | -------------------------------------------------------------------------------- /recursivepower.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func RecursivePower(nb, power int) int { 4 | if power < 0 { 5 | return 0 6 | } else if 1 == power { 7 | return nb 8 | } else if 0 == power { 9 | return 1 10 | } else { 11 | return nb * RecursivePower(nb, power-1) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sortintegertable.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func SortIntegerTable(table []int) { 4 | i := 1 5 | for i < len(table) { 6 | if table[i-1] > table[i] { 7 | tmp := table[i] 8 | table[i] = table[i-1] 9 | table[i-1] = tmp 10 | i = 1 11 | } else { 12 | i++ 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /unmatch.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func Unmatch(arr []int) int { 4 | for _,res:= range arr { 5 | fois:= 0 6 | for _,el:= range arr { 7 | if el == res { 8 | fois++ 9 | } 10 | } 11 | if fois == 1 || fois % 2 == 1 { 12 | return res 13 | } 14 | } 15 | return -1 16 | } 17 | -------------------------------------------------------------------------------- /listat.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListAt(l *NodeL, pos int) *NodeL{ 4 | if l == nil { 5 | return nil 6 | } 7 | current := l 8 | index := 0 9 | for index < pos { 10 | if current.Next == nil { 11 | return nil 12 | } 13 | current = current.Next 14 | index++ 15 | } 16 | return current 17 | } 18 | -------------------------------------------------------------------------------- /collatz.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func CollatzCountdown(start int) int { 4 | step := 1 5 | if start > 0 { 6 | for start > 1 { 7 | if start % 2 == 1 { 8 | start = (start * 3) + 1 9 | }else{ 10 | start /= 2 11 | } 12 | step++ 13 | } 14 | }else{ 15 | return -1 16 | } 17 | return step 18 | } 19 | -------------------------------------------------------------------------------- /point/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type point struct { 6 | x, y int 7 | } 8 | 9 | func setPoint(ptr *point) { 10 | ptr.x = 42 11 | ptr.y = 21 12 | } 13 | 14 | func main() { 15 | points:= new(point) 16 | 17 | setPoint(points) 18 | 19 | fmt.Printf("x = %d, y = %d\n",points.x, points.y) 20 | } 21 | -------------------------------------------------------------------------------- /sortparams/sortparams.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "sort" 7 | ) 8 | 9 | func main(){ 10 | args := os.Args[1:] 11 | 12 | sort.Slice(args, func(i, j int) bool { 13 | return args[i] < args[j] 14 | }) 15 | 16 | for _,res:= range args{ 17 | fmt.Println(res) 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /sqrt.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "math" 4 | 5 | func Sqrt(nb int) int { 6 | if nb < 0 || math.MaxInt32 < nb { 7 | return 0 8 | } 9 | for i := 0; i < 101; i++ { 10 | if nb == i*i { 11 | nb = i 12 | break 13 | } else if i*i > nb { 14 | nb = 0 15 | break 16 | } 17 | } 18 | return nb 19 | } 20 | -------------------------------------------------------------------------------- /btreelevelcount.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeLevelCount(root *TreeNode) int { 4 | if root == nil { 5 | return 0 6 | } 7 | 8 | gauche := BTreeLevelCount(root.Left) 9 | droite := BTreeLevelCount(root.Right) 10 | 11 | if droite > gauche { 12 | return droite + 1 13 | }else{ 14 | return gauche + 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /iterativepower.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func IterativePower(nb, power int) int { 4 | if power < 0 { 5 | return 0 6 | } else if 1 == power { 7 | return nb 8 | } else if 0 == power { 9 | return 1 10 | } else { 11 | res := 1 12 | for i := 0; i < power; i++ { 13 | res *= nb 14 | } 15 | return res 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /capitalize.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "strings" 4 | 5 | func Capitalize(s string) string { 6 | res := strings.Title(ToLower(s)) 7 | indx := Index(s, "_") 8 | if indx == -1 { 9 | return res 10 | } else { 11 | res = strings.Replace(res, string(res[indx+1]), ToUpper(string(res[indx+1])), indx+1) 12 | return res 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /btreesearchitem.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { 4 | if root == nil { 5 | return nil 6 | } 7 | if elem < root.Data { 8 | return BTreeSearchItem(root.Left, elem) 9 | }else if elem > root.Data{ 10 | return BTreeSearchItem(root.Right, elem) 11 | }else{ 12 | return root 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /printreversealphabet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func reverse(s string) string { 6 | chars := []rune(s) 7 | for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 { 8 | chars[i], chars[j] = chars[j], chars[i] 9 | } 10 | return string(chars) 11 | } 12 | 13 | func main() { 14 | fmt.Printf("%v\n", reverse("abcdefghijklmnopqrstuvwxyz")) 15 | } -------------------------------------------------------------------------------- /listmerge.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListMerge(l1, l2 *List) { 4 | 5 | if l1 == nil || l2 == nil{ 6 | return 7 | } 8 | 9 | if l1.Head == nil { 10 | l1.Head = l2.Head 11 | l1.Tail = l2.Head 12 | return 13 | } 14 | 15 | current := l1.Head 16 | for current.Next != nil { 17 | current = current.Next 18 | } 19 | current.Next = l2.Head 20 | } 21 | -------------------------------------------------------------------------------- /isprime.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "math" 4 | 5 | func IsPrime(nb int) bool { 6 | if nb < 2 { 7 | return false 8 | } else if 2 == nb || 3 == nb { 9 | return true 10 | } else { 11 | limit := math.Sqrt(float64(nb)) 12 | for i := 2; i <= int(limit); i++ { 13 | if nb%i == 0 { 14 | return false 15 | } 16 | } 17 | return true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /listfind.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func CompStr(a, b interface{}) bool { 4 | return a == b 5 | } 6 | 7 | func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} { 8 | current := l.Head 9 | for current != nil { 10 | if CompStr(ref, current.Data) { 11 | return &ref 12 | } 13 | current = current.Next 14 | } 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /listpushback.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListPushBack(l *List, data interface{}) { 4 | n:=&NodeL{Data:data} 5 | if l.Head==nil{ 6 | l.Head=n 7 | }else{ 8 | listItem := l.Head 9 | for listItem.Next != nil { 10 | listItem = listItem.Next 11 | } 12 | listItem.Next = n 13 | l.Tail = n 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /iterativefactorial.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "math" 4 | 5 | func IterativeFactorial(x int) int { 6 | if 0 > x { 7 | return 0 8 | } else if 0 == x || 1 == x { 9 | return 1 10 | } else { 11 | res := 1 12 | for i := 2; i <= x; i++ { 13 | res *= i 14 | if math.MaxInt32 < res { 15 | res = 0 16 | break 17 | } 18 | } 19 | return res 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /comcheck/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "os" 5 | "fmt" 6 | ) 7 | 8 | func main(){ 9 | result := "" 10 | args := os.Args[1:] 11 | check := []string{"01", "galaxy", "galaxy 01"} 12 | for _, res:= range args { 13 | for _,item := range check { 14 | if res == item { 15 | result += "Alert!!!\n" 16 | break 17 | } 18 | } 19 | } 20 | fmt.Print(result) 21 | } 22 | -------------------------------------------------------------------------------- /recursivefactorial.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "math" 4 | 5 | func RecursiveFactorial(x int) int { 6 | if x < 0 || x > math.MaxInt32 { 7 | return 0 8 | } else if 0 == x || 1 == x { 9 | return 1 10 | } else { 11 | res := x*RecursiveFactorial(x-1) > math.MaxInt32 12 | if res { 13 | return 0 14 | } else { 15 | return x * RecursiveFactorial(x-1) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /rot14.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func rot14(b rune) rune { 4 | if b >= 'A' && b < 'M' || b >= 'a' && b < 'm' { 5 | return b + 14 6 | } 7 | if b >= 'M' && b <= 'Z' || b >= 'm' && b <= 'z' { 8 | return b - 12 9 | } 10 | return b 11 | } 12 | 13 | func Rot14(str string) string { 14 | result := "" 15 | for _, res:= range str{ 16 | result += string(rot14(res)) 17 | } 18 | return result 19 | } 20 | -------------------------------------------------------------------------------- /appendrange.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func AppendRange(min, max int) []int { 4 | if min >= max { 5 | var tab []int = nil 6 | return tab 7 | }else{ 8 | tab := []int{} 9 | 10 | for i:= min;i < max;i++ { 11 | tab = append(tab,i) 12 | } 13 | return tab 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /makerange.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func MakeRange(min, max int) []int { 4 | if min >= max { 5 | var tab []int = nil 6 | return tab 7 | }else{ 8 | tab := make([]int,max-min) 9 | j:=0 10 | for i:= min;i = n.Data { 9 | n.Next = l 10 | return n 11 | } else { 12 | temp := l 13 | for temp.Next != nil && temp.Next.Data < n.Data { 14 | temp = temp.Next 15 | } 16 | n.Next = temp.Next 17 | temp.Next = n 18 | } 19 | return l 20 | } 21 | -------------------------------------------------------------------------------- /btreetransplant.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { 4 | if root == nil { 5 | return nil 6 | } 7 | 8 | replacement := node 9 | if node.Parent == nil { 10 | root = rplc 11 | } else if node == node.Parent.Left { 12 | replacement.Parent.Left = rplc 13 | } else { 14 | replacement.Parent.Right = rplc 15 | } 16 | replacement.Parent = node.Parent 17 | 18 | return root 19 | } 20 | -------------------------------------------------------------------------------- /cat/quest8T.txt: -------------------------------------------------------------------------------- 1 | "Alan Mathison Turing was an English mathematician, computer scientist, logician, cryptanalyst. Turing was highly influential in the development of theoretical computer science, providing a formalisation of the concepts of algorithm and computation with the Turing machine, which can be considered a model of a general-purpose computer. Turing is widely considered to be the father of theoretical computer science and artificial intelligence." -------------------------------------------------------------------------------- /displayfile/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "io/ioutil" 7 | ) 8 | 9 | func main(){ 10 | args := os.Args[1:] 11 | if 0 == len(args) { 12 | fmt.Println("File name missing") 13 | }else if len(args) >= 2 { 14 | fmt.Println("Too many arguments") 15 | }else{ 16 | file, err:= ioutil.ReadFile(args[0]) 17 | 18 | if err != nil { 19 | fmt.Println(err) 20 | } 21 | fmt.Print(string(file)) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /advancedsortwordarr.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func AdvancedSortWordArr(array []string, f func(a, b string) int) { 4 | for i:=0;i < len(array) - 1; i++ { 5 | for j:= i+1; j < len(array); j++{ 6 | if f(array[i],array[j]) == 1 { 7 | temp := array[i] 8 | modify(array, i, array[j]) 9 | modify(array, j, temp) 10 | } 11 | } 12 | } 13 | } 14 | 15 | func modify(array []string, ind int, val string){ 16 | array[ind] = val 17 | } 18 | -------------------------------------------------------------------------------- /issorted.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func IsSorted(f func(a, b int) int, tab []int) bool { 4 | ascendant, descendant:= true,true 5 | for i:= 0; i < len(tab) - 1; i++{ 6 | if f(tab[i],tab[i+1]) < 0 { 7 | descendant = false 8 | } 9 | } 10 | 11 | for i:=0; i < len(tab) - 1; i++ { 12 | if f(tab[i],tab[i+1]) > 0 { 13 | ascendant = false 14 | } 15 | } 16 | 17 | return ascendant || descendant 18 | } 19 | -------------------------------------------------------------------------------- /btreeisbinary.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func BTreeIsBinary(root *TreeNode) bool { 4 | if root == nil { 5 | return true 6 | } 7 | if root.Left != nil && root.Left.Data > root.Data { 8 | return false 9 | } 10 | if root.Right != nil && root.Right.Data < root.Data { 11 | return false 12 | } 13 | if !BTreeIsBinary(root.Left) || !BTreeIsBinary(root.Right) { 14 | return false 15 | } 16 | return true 17 | } 18 | -------------------------------------------------------------------------------- /printcomb.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func PrintComb() { 9 | for i:=0; i<10; i++{ 10 | for j:=i+1; j<10; j++{ 11 | for k:=j+1; k<10; k++{ 12 | if i == 0 && j == 1 && k == 2 { 13 | fmt.Print("") 14 | }else{ 15 | fmt.Print(", ") 16 | } 17 | ch := strconv.Itoa(i) 18 | ch += strconv.Itoa(j) 19 | ch += strconv.Itoa(k) 20 | fmt.Print(ch) 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /listremoveif.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListRemoveIf(l *List, data_ref interface{}) { 4 | if l == nil { 5 | return 6 | } 7 | current := l.Head 8 | var previous *NodeL 9 | 10 | for current != nil { 11 | if current.Data == data_ref { 12 | if previous == nil { 13 | l.Head = current.Next 14 | }else{ 15 | previous.Next = current.Next 16 | current = previous 17 | } 18 | }else{ 19 | previous = current 20 | } 21 | current = current.Next 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /raid1a.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func Raid1a(x, y int) { 6 | for i := 0; i < y; i++ { 7 | for j := 0; j < x; j++ { 8 | if i == 0 || i == y-1 { 9 | if j == 0 || j == x-1 { 10 | fmt.Print("o") 11 | } else { 12 | fmt.Print("-") 13 | } 14 | } else { 15 | if j == 0 || j == x-1 { 16 | fmt.Print("|") 17 | } else { 18 | fmt.Print(" ") 19 | } 20 | } 21 | if j == x-1 { 22 | fmt.Print("\n") 23 | } 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /btreeinsertdata.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | type TreeNode struct { 4 | Left, Right, Parent *TreeNode 5 | Data string 6 | } 7 | 8 | func BTreeInsertData(root *TreeNode, data string) *TreeNode { 9 | if root == nil { 10 | return &TreeNode{Data: data} 11 | } 12 | 13 | if data < root.Data { 14 | root.Left = BTreeInsertData(root.Left, data) 15 | root.Left.Parent = root 16 | } else if data > root.Data { 17 | root.Right = BTreeInsertData(root.Right, data) 18 | root.Right.Parent = root 19 | } 20 | return root 21 | } 22 | -------------------------------------------------------------------------------- /atoibase.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | func AtoiBase(s string, str string) int { 8 | indx:=0 9 | for _,res:= range str { 10 | if string(res) == "-" || string(res) == "+" || strings.Count(str, string(res)) > 1 { 11 | indx = 1 12 | break 13 | } 14 | } 15 | if indx == 1 || len(str) < 2{ 16 | return 0 17 | }else{ 18 | fin := 0 19 | for i,res:= range s { 20 | ind := strings.Index(str,string(res)) 21 | fin += ind* RecursivePower(len(str),len(s)-1 - i) 22 | } 23 | return fin 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /listforeach.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func ListForEach(l *List, f func(a *NodeL)) { 4 | current := l.Head 5 | for current != nil { 6 | f(current) 7 | current = current.Next 8 | } 9 | } 10 | 11 | func Add2_node(node *NodeL) { 12 | switch node.Data.(type) { 13 | case int: 14 | node.Data = node.Data.(int) + 2 15 | case string: 16 | node.Data = node.Data.(string) + "2" 17 | } 18 | } 19 | 20 | func Subtract3_node(node *NodeL) { 21 | switch node.Data.(type) { 22 | case int: 23 | node.Data = node.Data.(int) - 3 24 | case string: 25 | node.Data = node.Data.(string) + "-3" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cat/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "io/ioutil" 7 | ) 8 | 9 | func main(){ 10 | args := os.Args[1:] 11 | if 0 == len(args) { 12 | fmt.Print() 13 | }else{ 14 | for _,s:= range os.Args[1:] { 15 | file, err := os.Open(s) 16 | if err != nil { 17 | fmt.Println(err.Error()) 18 | break 19 | }else{ 20 | data, err := ioutil.ReadAll(file) 21 | if err != nil { 22 | fmt.Println(err.Error()) 23 | break 24 | }else{ 25 | fmt.Printf("%s", data) 26 | } 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /listsort.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | type NodeI struct { 4 | Data int 5 | Next *NodeI 6 | } 7 | 8 | func ListSort(l *NodeI) *NodeI { 9 | cmpt := 0 10 | var first *NodeI 11 | 12 | if l == nil || l.Next == nil { 13 | return l 14 | } 15 | 16 | for l != nil { 17 | next := l.Next 18 | if cmpt == 0 { 19 | first = l 20 | cmpt++ 21 | } 22 | 23 | for next != nil { 24 | if l.Data > next.Data { 25 | l.Data, next.Data = next.Data,l.Data 26 | } 27 | next = next.Next 28 | } 29 | l = l.Next 30 | } 31 | return first 32 | } 33 | -------------------------------------------------------------------------------- /printcombn.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func printi(b, n, a, i int, l string) { 9 | a++ 10 | for j := b + 1; j < 10-n+a; j++ { 11 | if a < n { 12 | printi(j, n, a, i, l+strconv.Itoa(j)) 13 | } else { 14 | fmt.Print(l) 15 | fmt.Print(j) 16 | if i < 10-n { 17 | fmt.Print(", ") 18 | } else { 19 | fmt.Print("\n") 20 | } 21 | } 22 | } 23 | } 24 | 25 | func PrintCombN(n int) { 26 | for i := 0; i < 10; i++ { 27 | if n > 1 { 28 | printi(i, n, 1, i, strconv.Itoa(i)) 29 | } else { 30 | fmt.Print(i) 31 | if i < 10-n { 32 | fmt.Print(", ") 33 | } else { 34 | fmt.Print("\n") 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /raid1c.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func Raid1C(x, y int){ 8 | if x == 1 && y == 1 { 9 | fmt.Print("A\n") 10 | }else{ 11 | for i := 0; i < y; i++ { 12 | for j := 0; j < x; j++ { 13 | if i == 0 || i == y-1 { 14 | if i == 0 && j == 0 || i == 0 && j == x-1 { 15 | fmt.Print("A") 16 | }else if i == y -1 && j == 0 || i == y -1 && j == x-1 { 17 | fmt.Print("C") 18 | } else { 19 | fmt.Print("B") 20 | } 21 | } else { 22 | if j == 0 || j == x-1 { 23 | fmt.Print("B") 24 | } else { 25 | fmt.Print(" ") 26 | } 27 | } 28 | if j == x-1 { 29 | fmt.Print("\n") 30 | } 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /btreedeletenode.go: -------------------------------------------------------------------------------- 1 | 2 | package piscine 3 | 4 | func BTreeDeleteNode(root, node *TreeNode) *TreeNode { 5 | if node == nil { 6 | return root 7 | } 8 | if node.Data < root.Data { 9 | root.Left = BTreeDeleteNode(root.Left, node) 10 | } else if node.Data > root.Data { 11 | root.Right = BTreeDeleteNode(root.Right, node) 12 | } else { 13 | if root.Left == nil { 14 | temp := root.Right 15 | root = nil 16 | return temp 17 | } else if root.Right == nil { 18 | temp := root.Left 19 | root = nil 20 | return temp 21 | }else { 22 | temp := BTreeMin(root.Right) 23 | 24 | root.Data = temp.Data 25 | root.Right = BTreeDeleteNode(root.Right, temp) 26 | } 27 | } 28 | return root 29 | } 30 | -------------------------------------------------------------------------------- /student/raid1c.go: -------------------------------------------------------------------------------- 1 | package student 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func Raid1C(x, y int){ 8 | if x == 1 && y == 1 { 9 | 10 | fmt.Print("A\n") 11 | 12 | }else{ 13 | for i := 0; i < y; i++ { 14 | for j := 0; j < x; j++ { 15 | if i == 0 || i == y-1 { 16 | if i == 0 && j == 0 || i == 0 && j == x-1 { 17 | fmt.Print("A") 18 | }else if i == y -1 && j == 0 || i == y -1 && j == x-1 { 19 | fmt.Print("C") 20 | } else { 21 | fmt.Print("B") 22 | } 23 | } else { 24 | if j == 0 || j == x-1 { 25 | fmt.Print("B") 26 | } else { 27 | fmt.Print(" ") 28 | } 29 | } 30 | if j == x-1 { 31 | fmt.Print("\n") 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /boolean/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "github.com/01-edu/z01" 6 | ) 7 | 8 | func printStr(str string) { 9 | arrayStr := []rune(str) 10 | 11 | for i := 0; i < len(arrayStr); i++ { 12 | z01.PrintRune(arrayStr[i]) 13 | } 14 | z01.PrintRune('\n') 15 | } 16 | 17 | func even(nbr int) bool { 18 | return nbr%2 == 0 19 | } 20 | 21 | func isEven(nbr int) bool { 22 | if even(nbr) { 23 | return true 24 | } else { 25 | return false 26 | } 27 | } 28 | 29 | func main() { 30 | lengthOfArg :=len(os.Args[1:]) 31 | if isEven(lengthOfArg) { 32 | EvenMsg := "I have an even number of arguments" 33 | printStr(EvenMsg) 34 | } else { 35 | OddMsg := "I have an odd number of arguments" 36 | printStr(OddMsg) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /eightqueens.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | const N = 8 6 | 7 | var position = [N]int{} 8 | 9 | func isSafe(queen_number, row_position int) bool { 10 | for i := 0; i < queen_number; i++ { 11 | other_row_pos := position[i] 12 | 13 | if other_row_pos == row_position || other_row_pos == row_position-(queen_number-i) || other_row_pos == row_position+(queen_number-i) { 14 | return false 15 | } 16 | } 17 | return true 18 | } 19 | 20 | func solve(k int) { 21 | if k == N { 22 | for i := 0; i < N; i++ { 23 | fmt.Print(position[i] + 1) 24 | } 25 | fmt.Print("\n") 26 | } else { 27 | for i := 0; i < N; i++ { 28 | if isSafe(k, i) { 29 | position[k] = i 30 | solve(k + 1) 31 | } 32 | } 33 | } 34 | } 35 | 36 | func EightQueens() { 37 | solve(0) 38 | } 39 | -------------------------------------------------------------------------------- /raid1b.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func Raid1b(x, y int){ 6 | if x == 1 && y == 1 { 7 | fmt.Print("/\n") 8 | }else{ 9 | for i := 0; i < y; i++ { 10 | for j := 0; j < x; j++ { 11 | if i == 0 || i == y-1 { 12 | if j == 0 && i==0 || j == x-1 && i == y-1 { 13 | if i == y - 1 && x == 1 || i == 0 && j == x - 1 && y == 1 { 14 | fmt.Print("\\") 15 | }else{ 16 | fmt.Print("/") 17 | } 18 | }else if j == x-1 && i==0 || j == 0 && i == y-1 { 19 | fmt.Print("\\") 20 | } else { 21 | fmt.Print("*") 22 | } 23 | } else { 24 | if j == 0 || j == x-1 { 25 | fmt.Print("*") 26 | } else { 27 | fmt.Print(" ") 28 | } 29 | } 30 | if j == x-1 { 31 | fmt.Print("\n") 32 | } 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /printcomb2.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func PrintComb2() { 9 | for i:=0; i<99; i++{ 10 | for j:=i+1; j<100; j++{ 11 | if i == 0 && j == 1 { 12 | fmt.Print("") 13 | }else{ 14 | fmt.Print(", ") 15 | } 16 | if i < 10 { 17 | ch := strconv.Itoa(0) 18 | ch += strconv.Itoa(i) 19 | fmt.Print(ch," ") 20 | }else{ 21 | fmt.Print(i," ") 22 | } 23 | 24 | if j < 10 { 25 | ch := strconv.Itoa(0) 26 | ch += strconv.Itoa(j) 27 | fmt.Print(ch) 28 | }else{ 29 | fmt.Print(j) 30 | } 31 | if i==98 && j== 99{ 32 | fmt.Print("\n") 33 | } 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /listforeachif.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | func IsPositive_node(node *NodeL) bool { 4 | switch node.Data.(type) { 5 | case int, float32, float64, byte: 6 | return node.Data.(int) > 0 7 | case string, rune: 8 | return false 9 | } 10 | return false 11 | } 12 | 13 | func IsNegative_node(node *NodeL) bool { 14 | switch node.Data.(type) { 15 | case int, float32, float64, byte: 16 | return node.Data.(int) > 0 17 | case string, rune: 18 | return false 19 | } 20 | return false 21 | } 22 | 23 | func IsNotNumeric_node(node *NodeL) bool { 24 | switch node.Data.(type) { 25 | case int, float32, float64, byte: 26 | return false 27 | case string, rune: 28 | return true 29 | } 30 | return true 31 | } 32 | 33 | func ListForEachIf(l *List, f func(*NodeL), cond func(*NodeL) bool) { 34 | current := l.Head 35 | for current != nil { 36 | if cond(current) { 37 | f(current) 38 | } 39 | current = current.Next 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /btreeapplybylevel.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "reflect" 4 | 5 | func printOrderTraversal(root *TreeNode, niveau int, fn interface{}) { 6 | if root == nil { 7 | return 8 | } 9 | if niveau == 1 { 10 | Invoke(fn, root.Data) 11 | }else if niveau > 1 { 12 | printOrderTraversal(root.Left,niveau - 1, fn) 13 | printOrderTraversal(root.Right,niveau - 1, fn) 14 | } 15 | } 16 | 17 | func BTreeApplyByLevel(root *TreeNode, fn interface{}) { 18 | h := BTreeLevelCount(root) 19 | for i := 1; i <= h; i++ { 20 | printOrderTraversal(root, i,fn) 21 | } 22 | } 23 | 24 | func Invoke(fn interface{}, args ...string) { 25 | v := reflect.ValueOf(fn) 26 | rargs := make([]reflect.Value, len(args)) 27 | for i, a := range args { 28 | rargs[i] = reflect.ValueOf(a) 29 | } 30 | v.Call(rargs) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /convertbase.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import ( 4 | "math" 5 | "strings" 6 | ) 7 | 8 | func ConvertBase(nbr, baseFrom, baseTo string) string { 9 | return NbrBase(AtoiBase(nbr, baseFrom), baseTo) 10 | } 11 | 12 | func NbrBase(nbr int, str string) string { 13 | indx := 0 14 | for _,res:= range str { 15 | if string(res) == "-" || string(res) == "+" || strings.Count(str, string(res)) > 1 { 16 | indx = 1 17 | break 18 | } 19 | } 20 | if indx == 1 || len(str) < 2{ 21 | return "0" 22 | }else if math.MaxInt32 nbr{ 23 | return string(nbr) 24 | }else{ 25 | neg := "" 26 | if nbr < 0 { 27 | neg = "-" 28 | nbr *= -1 29 | } 30 | i:=0 31 | nan:= "" 32 | for nbr >= len(str) { 33 | if nbr >= len(str) { 34 | nan +=string(str[nbr % len(str)]) 35 | nbr = nbr/len(str) 36 | i++ 37 | } 38 | } 39 | nan +=string(str[nbr]) 40 | return neg+Reverse(nan) 41 | } 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /ztail/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "io/ioutil" 7 | "strconv" 8 | ) 9 | 10 | func main(){ 11 | args := os.Args[1:] 12 | if 0 == len(args) { 13 | fmt.Println(os.Args[0]) 14 | }else{ 15 | num, err := strconv.Atoi(os.Args[1]) 16 | 17 | if err != nil { 18 | fmt.Println(err.Error()) 19 | }else{ 20 | if 0 == len(os.Args[2:]) { 21 | fmt.Println("File name missing") 22 | }else{ 23 | for _,res:= range os.Args[2:] { 24 | ztail(res, num) 25 | } 26 | } 27 | } 28 | } 29 | } 30 | 31 | func ztail(s string, numBytes int) { 32 | file, err := os.Open(s) 33 | if err != nil { 34 | fmt.Println(err.Error()) 35 | } 36 | 37 | data, err := ioutil.ReadAll(file) 38 | if err != nil { 39 | fmt.Println(err.Error()) 40 | } 41 | 42 | fmt.Printf("%s\n", data[len(data)-numBytes:]) 43 | } 44 | -------------------------------------------------------------------------------- /printnbrbase.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import( 4 | "math" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func Reverse(s string) string { 10 | var reverse string 11 | for i := len(s)-1; i >= 0; i-- { 12 | reverse += string(s[i]) 13 | } 14 | return reverse 15 | } 16 | 17 | func PrintNbrBase(nbr int, str string)(){ 18 | indx := 0 19 | for _,res:= range str { 20 | if string(res) == "-" || string(res) == "+" || strings.Count(str, string(res)) > 1 { 21 | indx = 1 22 | break 23 | } 24 | } 25 | if indx == 1 || len(str) < 2{ 26 | fmt.Print("NV") 27 | }else if math.MaxInt32 nbr{ 28 | fmt.Print(int64(nbr)) 29 | }else{ 30 | if nbr < 0 { 31 | fmt.Print("-") 32 | nbr *= -1 33 | } 34 | i:=0 35 | nan:="" 36 | for nbr >= len(str) { 37 | if nbr >= len(str) { 38 | nan +=string(str[nbr % len(str)]) 39 | nbr = nbr/len(str) 40 | i++ 41 | } 42 | } 43 | nan +=string(str[nbr]) 44 | fmt.Print(Reverse(nan)) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /fixthemain/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | const ( 6 | CLOSE = 0 7 | OPEN = 1 8 | ) 9 | 10 | type Door struct { 11 | State int 12 | } 13 | 14 | func PrintStr(str string) { 15 | arrayRune := []rune(str) 16 | for _, s := range arrayRune { 17 | z01.PrintRune(s) 18 | } 19 | } 20 | 21 | func CloseDoor(ptrDoor *Door) { 22 | PrintStr("Door closing...\n") 23 | ptrDoor.State = CLOSE 24 | } 25 | 26 | func IsDoorOpen(ptrDoor *Door) bool { 27 | PrintStr("Door is open ?\n") 28 | return ptrDoor.State == OPEN 29 | } 30 | 31 | func IsDoorClose(ptrDoor *Door) bool { 32 | PrintStr("Door is close ?\n") 33 | return ptrDoor.State == CLOSE 34 | } 35 | 36 | func OpenDoor(ptrDoor *Door){ 37 | PrintStr("Door Opening...\n") 38 | ptrDoor.State = OPEN 39 | } 40 | 41 | func main() { 42 | var door Door 43 | 44 | OpenDoor(&door) 45 | if IsDoorClose(&door) { 46 | OpenDoor(&door) 47 | } 48 | if IsDoorOpen(&door) { 49 | CloseDoor(&door) 50 | } 51 | if door.State == OPEN { 52 | CloseDoor(&door) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /raid3/raid3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "bufio" 7 | "io" 8 | "os/exec" 9 | ) 10 | 11 | func main(){ 12 | info, err := os.Stdin.Stat() 13 | if err != nil { 14 | fmt.Println(err.Error()) 15 | } 16 | 17 | if info.Mode()&os.ModeCharDevice != 0 || info.Size() <= 0 { 18 | fmt.Println() 19 | return 20 | } 21 | 22 | reader := bufio.NewReader(os.Stdin) 23 | var output []rune 24 | 25 | for { 26 | input, _, err := reader.ReadRune() 27 | if err != nil && err == io.EOF { 28 | break 29 | } 30 | output = append(output, input) 31 | } 32 | 33 | row, col:= getDimension(string(output)) 34 | fmt.Println(IsRaid1a(row, col)) 35 | } 36 | 37 | func IsRaid1a (row, col int) string { 38 | cmd, _ := exec.Command("raid1a", string(row), string(col)).Output() 39 | return string(cmd) 40 | } 41 | 42 | 43 | func getDimension(s string) (int, int) { 44 | col, row:= 0, 0 45 | for _, res := range s { 46 | if row == 0 && res != '\n' { 47 | col++ 48 | } 49 | if res == '\n' { 50 | row++ 51 | } 52 | } 53 | return row, col 54 | } 55 | -------------------------------------------------------------------------------- /doop/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "strconv" 7 | ) 8 | 9 | func validateOperator(test string) bool { 10 | op := []string{"+", "-", "*", "/", "%"} 11 | for _, res:= range op { 12 | if res == test { 13 | return true 14 | } 15 | } 16 | return false 17 | } 18 | 19 | func main(){ 20 | args := os.Args[1:] 21 | if len(args) > 3 || len(args) < 3 { 22 | fmt.Print() 23 | }else{ 24 | if validateOperator(args[1]) == false { 25 | fmt.Println(0) 26 | }else{ 27 | premier, _ := strconv.Atoi(args[0]) 28 | second, _ := strconv.Atoi(args[2]) 29 | 30 | if args[1] == "%" && second == 0 { 31 | fmt.Print("No Modulo by 0\n") 32 | }else if args[1] == "/" && second == 0 { 33 | fmt.Print("No division by 0\n") 34 | }else if args[1] == "+" { 35 | fmt.Println(premier+second) 36 | }else if args[1] == "-" { 37 | fmt.Println(premier-second) 38 | }else if args[1] == "*" { 39 | fmt.Println(premier * second) 40 | }else if args[1] == "/" { 41 | fmt.Println(premier/second) 42 | }else{ 43 | fmt.Println(premier%second) 44 | } 45 | 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /raid1e.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func Raid1e(x,y int) { 6 | for i:=0; i < y; i++ {//boucle pour la longueur 7 | for j:=0; j < x; j++ {//boucle pour la largeur 8 | if i == 0 {//première ligne 9 | if j == 0 || j == x - 1 { 10 | if j == 0{//première cologne 11 | fmt.Print("A") 12 | } 13 | if j == x-1{//dernière cologne 14 | if j!=0{ 15 | fmt.Print("C") 16 | } 17 | 18 | } 19 | }else{//colognes du milieu 20 | fmt.Print("B") 21 | } 22 | }else if i == y - 1{//dernière ligne 23 | if j == 0 || j == x - 1 { 24 | if j == 0{//première cologne 25 | fmt.Print("C") 26 | } 27 | if j == x-1{//dernière cologne 28 | if j!=0{ 29 | fmt.Print("A") 30 | } 31 | } 32 | }else{//colognes du milieu 33 | fmt.Print("B") 34 | } 35 | }else{//lignes du milieu 36 | if j == 0 || j == x - 1 { 37 | fmt.Print("B") 38 | }else{ 39 | fmt.Print(" ") 40 | } 41 | } 42 | if j == x - 1 { 43 | fmt.Print("\n") 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /raid1d.go: -------------------------------------------------------------------------------- 1 | package piscine 2 | 3 | import "fmt" 4 | 5 | func Raid1d(x,y int) { 6 | for i:=0; i < y; i++ {//boucle pour la longueur 7 | for j:=0; j < x; j++ {//boucle pour la largeur 8 | if i == 0 {//première ligne 9 | if j == 0 || j == x - 1 { 10 | if j == 0{//première cologne 11 | fmt.Print("A") 12 | } 13 | if j == x-1{//dernière cologne 14 | if j!=0{ 15 | fmt.Print("C") 16 | } 17 | 18 | } 19 | }else{//colognes du milieu 20 | fmt.Print("B") 21 | } 22 | }else if i == y - 1{//dernière ligne 23 | if j == 0 || j == x - 1 { 24 | if j == 0{//première cologne 25 | fmt.Print("A") 26 | } 27 | if j == x-1{//dernière cologne 28 | if j!=0{ 29 | fmt.Print("C") 30 | } 31 | } 32 | }else{//colognes du milieu 33 | fmt.Print("B") 34 | } 35 | }else{//lignes du milieu 36 | if j == 0 || j == x - 1 { 37 | fmt.Print("B") 38 | }else{ 39 | fmt.Print(" ") 40 | } 41 | } 42 | if j == x - 1 { 43 | fmt.Print("\n") 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /main/raid2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "reflect" 5 | "os" 6 | "fmt" 7 | "strings" 8 | piscine".." 9 | ) 10 | 11 | func IsValideInput(args []string, grille, vertical, block *[][]string) bool { 12 | lon := 0 13 | 14 | if len(args) == 0 || len(args) == 1 || (piscine.Sqrt(len(args)) == 0 && len(args) > 1) { 15 | return false 16 | } 17 | 18 | for i,res:= range args { 19 | if reflect.TypeOf(res) != reflect.TypeOf("a") { 20 | return false 21 | }else{ 22 | if lon == 0 && i == 0 { 23 | lon = len(res) 24 | }else{ 25 | if lon != len(res) { 26 | return false 27 | } 28 | } 29 | } 30 | 31 | for _,item:= range res { 32 | if string(item) != "." && strings.Count(res,string(item)) > 1 { 33 | return false 34 | } 35 | } 36 | (*grille) = append((*grille),[]string{}) 37 | (*grille)[i] = piscine.Split(res,"") 38 | } 39 | 40 | for i:=0; i < lon; i++ { 41 | (*block) = append((*block),[]string{}) 42 | (*vertical) = append((*vertical),[]string{}) 43 | for j:=0; j < lon; j++ { 44 | (*vertical)[j][i] = (*grille)[i][j] 45 | (*block)[3*(i/3)+(j/3)] = append((*block)[3*(i/3)+(j/3)],(*grille)[i][j]) 46 | } 47 | } 48 | 49 | return IsValidGrille(grille, vertical, block, lon) 50 | } 51 | 52 | func printBoard(board [][]string) { 53 | fmt.Println("+-------+-------+-------+") 54 | for row,res:=range board { 55 | fmt.Print("| ") 56 | for col,item := range res{ 57 | if col == 3 || col == 6 { 58 | fmt.Print("| ") 59 | } 60 | fmt.Printf("%s ", string(item)) 61 | if col == 8 { 62 | fmt.Print("|") 63 | } 64 | } 65 | if row == 2 || row == 5 || row == 8 { 66 | fmt.Println("\n+-------+-------+-------+") 67 | } else { 68 | fmt.Println() 69 | } 70 | } 71 | } 72 | 73 | func hasDuplicate(grille *[][]string, n int) bool { 74 | for i:=0; i< n; i++ { 75 | res := "" 76 | for j:=0; j< n; i++ { 77 | res += string((*grille)[i][j]) 78 | } 79 | for _,item:= range res { 80 | if string(item) != "." && strings.Count(res,string(item)) > 1 { 81 | return true 82 | } 83 | } 84 | } 85 | return false 86 | } 87 | 88 | func EmptyCell(grille *[][]string) bool { 89 | count := 0 90 | for i:=0;i < 9; i++ { 91 | for j:= 0; j<9; j++ { 92 | if (*grille)[i][j] == "." { 93 | count++ 94 | } 95 | } 96 | } 97 | return count == 0 98 | } 99 | 100 | func IsValidGrille(grille, vertical, block *[][]string, lon int) bool { 101 | if hasDuplicate(grille, lon) || hasDuplicate(block, lon) || hasDuplicate(vertical, lon) { 102 | return false 103 | } 104 | return true 105 | } 106 | 107 | func Backtracking(grille, vertical, block *[][]string) bool { 108 | if !EmptyCell(grille){ 109 | return true 110 | } 111 | for i:=0; i < 9; i++ { 112 | for j := 0; j < 9; j++ { 113 | if (*grille)[i][j] == string(".") { 114 | for candidate := 9; candidate >= 1; candidate-- { 115 | (*grille)[i][j] = string(candidate) 116 | if IsValidGrille(grille, vertical,block,9) { 117 | if Backtracking(grille, vertical, block) { 118 | return true 119 | } 120 | (*grille)[i][j] = string(0) 121 | } else { 122 | (*grille)[i][j] = string(0) 123 | } 124 | } 125 | return false 126 | } 127 | } 128 | } 129 | return false 130 | } 131 | 132 | func main(){ 133 | args:= os.Args[1:] 134 | var ( 135 | row [][]string 136 | col [][]string 137 | block [][]string 138 | ) 139 | 140 | if len(args) == 0 { 141 | fmt.Println("Error") 142 | }else{ 143 | if IsValideInput(args, &row, &col, &block){ 144 | if Backtracking(&row,&col, &block) { 145 | fmt.Println("Error") 146 | }else{ 147 | printBoard(row) 148 | } 149 | }else{ 150 | fmt.Println("Error") 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /raid2/raid2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | func main() { 12 | 13 | param:=strings.Join(os.Args[1:],"") 14 | 15 | if iscorrectparam(param){ 16 | board := parseInput(param) 17 | if backtrack(&board) { 18 | if isValid(&board) && isBoardValid(&board){ 19 | printBoard(board) 20 | }else { 21 | fmt.Printf("Error") 22 | } 23 | } else { 24 | fmt.Printf("Error") 25 | } 26 | }else{ 27 | fmt.Println("Error") 28 | } 29 | 30 | 31 | } 32 | 33 | func backtrack(board *[9][9]int) bool { 34 | if !hasEmptyCell(board) { 35 | return true 36 | } 37 | for i := 0; i < 9; i++ { 38 | for j := 0; j < 9; j++ { 39 | if board[i][j] == 0 { 40 | for candidate := 9; candidate >= 1; candidate-- { 41 | board[i][j] = candidate 42 | if isBoardValid(board) { 43 | if backtrack(board) { 44 | return true 45 | } 46 | board[i][j] = 0 47 | } else { 48 | board[i][j] = 0 49 | } 50 | } 51 | return false 52 | } 53 | } 54 | } 55 | return false 56 | } 57 | 58 | func hasEmptyCell(board *[9][9]int) bool { 59 | for i := 0; i < 9; i++ { 60 | for j := 0; j < 9; j++ { 61 | if board[i][j] == 0 { 62 | return true 63 | } 64 | } 65 | } 66 | return false 67 | } 68 | 69 | func isBoardValid(board *[9][9]int) bool { 70 | for row := 0; row < 9; row++ { 71 | counter := [10]int{} 72 | for col := 0; col < 9; col++ { 73 | counter[board[row][col]]++ 74 | } 75 | if hasDuplicates(counter) { 76 | return false 77 | } 78 | } 79 | 80 | for row := 0; row < 9; row++ { 81 | counter := [10]int{} 82 | for col := 0; col < 9; col++ { 83 | counter[board[col][row]]++ 84 | } 85 | if hasDuplicates(counter) { 86 | return false 87 | } 88 | } 89 | 90 | for i := 0; i < 9; i += 3 { 91 | for j := 0; j < 9; j += 3 { 92 | counter := [10]int{} 93 | for row := i; row < i+3; row++ { 94 | for col := j; col < j+3; col++ { 95 | counter[board[row][col]]++ 96 | } 97 | if hasDuplicates(counter) { 98 | return false 99 | } 100 | } 101 | } 102 | } 103 | 104 | return true 105 | } 106 | 107 | func isValid(board *[9][9]int) bool { 108 | for row := 0; row < 9; row++ { 109 | counter := 0 110 | for col := 0; col < 9; col++ { 111 | counter+=board[row][col] 112 | } 113 | if 45!= counter { 114 | return false 115 | } 116 | } 117 | 118 | for row := 0; row < 9; row++ { 119 | counter := 0 120 | for col := 0; col < 9; col++ { 121 | counter+=board[col][row] 122 | } 123 | if 45!= counter { 124 | return false 125 | } 126 | } 127 | 128 | for i := 0; i < 9; i += 3 { 129 | for j := 0; j < 9; j += 3 { 130 | counter := 0 131 | for row := i; row < i+3; row++ { 132 | for col := j; col < j+3; col++ { 133 | counter+=board[row][col] 134 | } 135 | } 136 | if 45!= counter { 137 | return false 138 | } 139 | } 140 | } 141 | 142 | return true 143 | } 144 | 145 | func parseInput(input string) [9][9]int { 146 | board := [9][9]int{} 147 | scanner := bufio.NewScanner(strings.NewReader(input)) 148 | 149 | scanner.Split(bufio.ScanRunes) 150 | 151 | for row := 0; row < 9; row++ { 152 | for col := 0; col < 9; col++ { 153 | scanner.Scan() 154 | i1, _ := strconv.Atoi(scanner.Text()) 155 | board[row][col] = i1 156 | } 157 | } 158 | return board 159 | } 160 | 161 | func hasDuplicates(counter [10]int) bool { 162 | for i, count := range counter { 163 | if i == 0 { 164 | continue 165 | } 166 | if count > 1 { 167 | return true 168 | } 169 | } 170 | return false 171 | } 172 | 173 | func printBoard(board [9][9]int) { 174 | for row := 0; row < 9; row++ { 175 | for col := 0; col < 9; col++ { 176 | fmt.Printf("%d", board[row][col]) 177 | if col + 1 < 9 { 178 | fmt.Print(" ") 179 | } 180 | } 181 | fmt.Println() 182 | } 183 | } 184 | 185 | func iscorrectparam(param string) bool{ 186 | board := parseInput(param) 187 | 188 | if len(param)!=81{ 189 | return false 190 | } 191 | 192 | for _,val:= range param{ 193 | if !((48 <= val && val <= 57)||val==46){ 194 | return false 195 | } 196 | } 197 | 198 | return isBoardValid(&board) 199 | } 200 | -------------------------------------------------------------------------------- /done.tar: -------------------------------------------------------------------------------- 1 | 0/0000401000175000017500000000000003607342000011143 5ustar kosinuskosinus10000402000175000017500000000000003756214074011077 0ustar kosinuskosinus20000604000175000017500000000000004213643530011074 0ustar kosinuskosinus30000777000175000017500000000000004566642424011206 20ustar kosinuskosinus40000510000175000017500000000000004703477020011075 0ustar kosinuskosinus50000460000175000017500000000000004715656314011112 0ustar kosinuskosinus60000460000175000017500000000000004754375150011112 0ustar kosinuskosinus70000510000175000017500000000000004765562244011113 0ustar kosinuskosinus80000604000175000017500000000000005567105040011104 0ustar kosinuskosinus90000402000175000017500000000000005576034734011114 0ustar kosinuskosinusA/0000401000175000017500000000000005742201770011176 5ustar kosinuskosinus --------------------------------------------------------------------------------