diff --git a/README.md b/README.md index fae392a..3d50675 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -# Instructions +# Completed Go Language Challenge -- All questions/tasks carry 100 points. -- Submit via creating a new folder in Submissions/yourusername/task name/ -- For eg: if user name in annon. Create a new folder named annon in Submissions folder. And suppose you are doing task 5. Create a new folder named task5. Save all the files realted to task5 in that folder and send a Pull request. +## Contact Details + NAME: M.Benhur Rodriguez -- + PHONE: +91-9843184815 -- + EMAIL: benhurrodriguez98@gmail.com diff --git a/Submissions/noname/task1 b/Submissions/noname/task1 new file mode 100644 index 0000000..659be7a --- /dev/null +++ b/Submissions/noname/task1 @@ -0,0 +1,23 @@ +//MADE BY M.BENHUR +//phone : +91-9843184815 +//email : benhurrodriguez98@gmail.com + +//denotes main package in which go runs +package main + +//import libraries here +import ( "fmt" ) + +//main function executes first +func main() { + +//Println(input) <- input displays on cmd screen +fmt.Println("Hello World !") + +//Println(input) <-input displays on cmd screen +//[INFO] +fmt.Println("Press to exit") + +//Scanln() <- Waits for raw enter [ Halts the output screen ] +fmt.Scanln() +} diff --git a/Submissions/noname/task2 b/Submissions/noname/task2 new file mode 100644 index 0000000..376e059 --- /dev/null +++ b/Submissions/noname/task2 @@ -0,0 +1,56 @@ +//MADE BY M.BENHUR +//phone : +91-9843184815 +//email : benhurrodriguez98@gmail.com + +//denotes package main +package main + +//imports necessary libraries +//fmt -> fast alternative IO operations +//strconv -> numeric convertions from string to int +import ( + "fmt" + "strconv" +) + +//function named thr +//INPUTS <- integer array named b , integer named x +//acts as thread handler +//outputs the sum of 5 integer inputs +func thr(b []int,x int){ +//for loop implementation to loop 5 times in a row + for i:=0;i<5;i++ + { + x = x + b[i] + } + //prints sum in o/p stream + fmt.Println("The sum is - ",x) + +} + +//main function - program entry point +//variables in scope +////-integer array - b +////-integer - x +func main() { +var b []int +x:=0 + +//info update in print +fmt.Println("-- Enter 5 numbers --") +//This logic loops for 5 turns , fetches input as string from standare input stream, +//converts string to integer and appends to a slice(a list) +for i := 1;i<6;i++ { + fmt.Println("Enter ",i,"number :") + var input string + fmt.Scanln(&input) + in,_:= strconv.Atoi(input) + b=append(b,in) +} +//starts a go threaded subroutine to perform addtion process in background +go thr(b,x) +//info update +fmt.Println("Thread Started") +//halts output screen to exit +fmt.Scanln() +} diff --git a/Submissions/noname/task3 b/Submissions/noname/task3 new file mode 100644 index 0000000..5392d6e --- /dev/null +++ b/Submissions/noname/task3 @@ -0,0 +1,53 @@ +//MADE BY M.BENHUR +//phone : +91-9843184815 +//email : benhurrodriguez98@gmail.com + +//refers main package to work on +package main +//import necessary libraries here +import ( +//io <- basic IO primitives + "io" +//net/http <- http client and server implementations + "net/http" +//standard I/O routines + "fmt" + ) + +//callback function +//input http response w.r.t client , request socket pathway +func resp(a http.ResponseWriter, b *http.Request){ + io.WriteString(a,"

Welcome

") + } + +//callback function +//input http response w.r.t client , request socket pathway +func resp_2(a http.ResponseWriter, b *http.Request){ + io.WriteString(a,"

Welcome to home page

") + } + +//function thread for {/} path +//waits for connection at port 8000 +func thr(){ + http.HandleFunc("/",resp) + http.ListenAndServe(":8000",nil) + } + +//function thread for {/home} path +//waits for connection at port 8000 +func thr_2(){ + http.HandleFunc("/home",resp_2) + http.ListenAndServe(":8000",nil) + } + +//main function - go program entry point +func main(){ + //start go subroutine in path "/" + go thr() + //start go subroutine in path "/home" + go thr_2() + //info update + fmt.Println("Press to exit..") + //halts output screen + fmt.Scanln() +} diff --git a/Submissions/noname/task4 b/Submissions/noname/task4 new file mode 100644 index 0000000..3046b48 --- /dev/null +++ b/Submissions/noname/task4 @@ -0,0 +1,81 @@ +//MADE BY M.BENHUR +//phone : +91-9843184815 +//email : benhurrodriguez98@gmail.com + +//main package definition +package main + +//importing libraries +//fmt <- [Standard I/O routines] +//strings <- [in-built string manipulation functions] +import ( + "fmt" + "strings" + ) + +//check_heading(input) - input <- string of input/line in text to parse and check +////output - returns identifier string +func check_heading(m string) string{ + + //method to check Heading 1 + if strings.HasPrefix(m,"#") { + return "H1" + } + //method to check Heading 2 + if strings.HasPrefix(m,"##"){ + return "H2" + } + //method to check bold faced + if strings.HasPrefix(m,"**"){ + if strings.HasSuffix(m,"**"){ + return "BOLD" + } + } + return "NONE" + } +func chkk(check string){ + if check == "H1" { + fmt.Println("Found Heading H1") + } + + if check == "H2" { + fmt.Println("Found Heading H2") + } + + if check == "BOLD" { + fmt.Println("Found BOLD faced string") + } + if check == "NONE" { + fmt.Println("NONE found..") + } + } + +//main function - ENTRY point of go +func main(){ + //string variable declarations for local working + var x,parser_string,parser_string_2,parser_string_3 string + + //sample input data for H1 + parser_string ="# Heading1" + + //sample input data for H2 + parser_string_2 ="## Heading2" + + //sample input data for bold + parser_string_3 = "**bold_font**" + + //Function call and making output - [START] + x = check_heading(parser_string) + chkk(x) + + x = check_heading(parser_string_2) + chkk(x) + + x = check_heading(parser_string_3) + chkk(x) + // - [END] + + //halts output screen + fmt.Scanln() + + } diff --git a/Submissions/noname/task5 b/Submissions/noname/task5 new file mode 100644 index 0000000..1d4ad9c --- /dev/null +++ b/Submissions/noname/task5 @@ -0,0 +1,49 @@ +//MADE BY M.BENHUR +//phone : +91-9843184815 +//email : benhurrodriguez98@gmail.com + +//main package definition +package main + +//importing libraries +//fmt <- [Standard I/O routines] +//net/http <- making http request and responses +//io/ioutil <- simple I/O utility functions +import ( + "fmt" + "net/http" + "io/ioutil" + ) + +//main function - ENTRY point of go +func main(){ + //make GET request to API + ////returns response and error response if any + response,error:= http.Get("http://ip.jsontest.com/") + + //check for no errors in making HTTP connection + if error != nil { + //info update + fmt.Println("Error in making HTTP request") + } + //wait in bg until the response closes + defer response.Body.Close() + + //read the content of response in bytes + content,_ := ioutil.ReadAll(response.Body) + + //parse the byte response to string of characters + resp_str := string(content) + + //create a runes(slices/list) + runes :=[]rune(resp_str) + + //display the response in string format + fmt.Println("Your IP from API - ",string(runes[8:23])) + + //info update + fmt.Println("Press to continue") + + //halt O/P screen + fmt.Scanln() + }