Created
          April 5, 2020 11:34 
        
      - 
      
- 
        Save HirbodBehnam/2eade4ef6f15410d1186565f4719e0ec to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "bufio" | |
| "fmt" | |
| "github.com/yourbasic/graph" | |
| "log" | |
| "os" | |
| "strconv" | |
| "strings" | |
| ) | |
| func main() { | |
| gC := make([][]int64,0) | |
| file, err := os.Open("g2.txt") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer file.Close() | |
| scanner := bufio.NewScanner(file) | |
| for scanner.Scan() { | |
| split := strings.Split(scanner.Text()," ") | |
| c := make([]int64,len(split)) | |
| for k,v := range split{ | |
| c[k] ,_ = strconv.ParseInt(v,10,64) | |
| } | |
| gC = append(gC,c) | |
| } | |
| if err := scanner.Err(); err != nil { | |
| log.Fatal(err) | |
| } | |
| g := graph.New(len(gC) * (len(gC) + 1) / 2 + 1) | |
| counter := 0 | |
| firstOfNextRow := 0 | |
| for i := range gC{ | |
| firstOfNextRow += i + 1 | |
| for j := range gC[i]{ | |
| if i == len(gC) - 1{ | |
| g.AddCost(counter, firstOfNextRow, 100 - gC[i][j]) | |
| }else { | |
| g.AddCost(counter, firstOfNextRow+j, 100 - gC[i][j]) | |
| g.AddCost(counter, firstOfNextRow+j + 1, 100 - gC[i][j]) | |
| } | |
| counter++ | |
| } | |
| } | |
| _,s := graph.ShortestPath(g,0,len(gC) * (len(gC) + 1) / 2) | |
| fmt.Println(int64(len(gC)) * 100 - s) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment