Advertisement
Guest User

new paste cause im fuckin dumb

a guest
May 22nd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.61 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6.     "bufio"
  7.     "os"
  8.     "strings"
  9. )
  10.  
  11. // T = M B + C
  12. // Co-ordinates should be entered in X, Y format
  13.  
  14. func input() string {
  15.     reader := bufio.NewReader(os.Stdin)
  16.     text, err := reader.ReadString('\n')
  17.     if err != nil {
  18.         fmt.Println("\n[!] Reading input failed, exiting...")
  19.         os.Exit(3)
  20.     }
  21.     return text
  22. }
  23.  
  24. func parseCoords (coords string) [2]float64 {
  25.     splitCoords := strings.Split(coords, ",") // split coords into array
  26.     intCoords := [2]float64{} // create empty int array
  27.     intOne, err := strconv.ParseFloat(strings.TrimSpace(splitCoords[0]), 64) // convert first element of splitCoords to float
  28.     intTwo, err := strconv.ParseFloat(strings.TrimSpace(splitCoords[1]), 64) // same thing but with second element
  29.     if err != nil {
  30.         fmt.Println("[!] Failed to convert one or more co-ordinates to floats, exiting...")
  31.         os.Exit(3)
  32.     }
  33.     intCoords[0] = intOne // add integers to int array
  34.     intCoords[1] = intTwo
  35.     return intCoords // return int array
  36. }
  37.  
  38. func formatFloat(num float64) string {
  39.     formatted := strconv.FormatFloat(num, 'f', -1, 64)
  40.     return formatted
  41. }
  42.  
  43. func main() {
  44.     fmt.Println("[*] Welcome to my (not nerdy) tele-science calculator!") // yeah, it is cool (and NOT nerdy)
  45.    
  46.     fmt.Printf("\n[*] Enter first set of input co-ordinates: ") // this block of code takes the first set of inputs and outputs from the user
  47.     firstInCoords := parseCoords(input())
  48.     fmt.Printf("[*] Enter first set of output co-ordinates: ")
  49.     firstOutCoords := parseCoords(input())
  50.  
  51.     fmt.Printf("[*] Enter second set of output co-ordinates: ")
  52.     secondOutCoords := parseCoords(input())
  53.  
  54.     fmt.Printf("\n[*] Caluclating offsets... ")
  55.     xOffset := secondOutCoords[0]-firstOutCoords[0]
  56.     yOffset := secondOutCoords[1]-firstOutCoords[1]
  57.     fmt.Println("[DONE]")
  58.     fmt.Printf("[*] Offsets: X=%s, Y=%s\n", formatFloat(xOffset), formatFloat(yOffset))
  59.  
  60.     fmt.Printf("\n[*] Caluclating constants... ")
  61.     xConstant := firstOutCoords[0]-(firstInCoords[0]*xOffset)
  62.     yConstant := firstOutCoords[1]-(firstInCoords[1]*yOffset)
  63.     fmt.Println("[DONE]")
  64.     fmt.Printf("[*] Constants: X=%s, Y=%s\n", formatFloat(xConstant), formatFloat(yConstant))
  65.     fmt.Printf("[*] Calculator ready!\n\n")
  66.  
  67.     for {
  68.         fmt.Printf("[*] Enter co-ordinates to reverse calculate: ")
  69.         coords := parseCoords(input())
  70.         fmt.Printf("[*] Running calculations in reverse... ")
  71.         outputCoords := [2]float64{}
  72.         outputCoords[0] = (coords[0]+(xConstant*(-1)))/xOffset
  73.         outputCoords[1] = (coords[1]+(yConstant*(-1)))/yOffset
  74.         fmt.Println("[DONE]")
  75.         fmt.Printf("[*] Results: X=%s, Y=%s\n\n", formatFloat(outputCoords[0]), formatFloat(outputCoords[1]))
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement