Created
February 17, 2015 02:57
-
-
Save thoroc/b8ca88161a676eb52222 to your computer and use it in GitHub Desktop.
codingame - Mars Lander - Level 1
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 ( | |
| "fmt" | |
| "strconv" | |
| //"os" | |
| ) | |
| type Point struct { | |
| X, Y int | |
| } | |
| type Lander struct { | |
| HSpeed int // the horizontal speed (in m/s), can be negative. | |
| VSpeed int // the vertical speed (in m/s), can be negative. | |
| Fuel int // the quantity of remaining fuel in liters. | |
| Angle int // the rotation angle in degrees (-90 to 90). | |
| Thrust int // the thrust power (0 to 4). | |
| Position Point | |
| } | |
| func main() { | |
| // N: the number of points used to draw the surface of Mars. | |
| var N int | |
| fmt.Scan(&N) | |
| Surface := make(map[int]Point) | |
| var X, Y, HS, VS, F, R, P int | |
| //fmt.Scan(&X, &Y, &HS, &VS, &F, &R, &P) | |
| starting_point := Point{X, Y} | |
| mars := Lander{HSpeed: HS,VSpeed: VS, Fuel: F, Angle: R, Thrust: 3, Position: starting_point} | |
| for i := 0; i < N; i++ { | |
| // LAND_X: X coordinate of a surface point. (0 to 6999) | |
| // LAND_Y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. | |
| var LAND_X, LAND_Y int | |
| fmt.Scan(&LAND_X, &LAND_Y) | |
| Surface[i] = Point{X: LAND_X, Y: LAND_Y} | |
| } | |
| for { | |
| fmt.Scan(&X, &Y, &HS, &VS, &F, &R, &P) | |
| p := Point{X, Y} | |
| mars.Position = p | |
| mars.HSpeed = HS | |
| mars.VSpeed = VS | |
| mars.Fuel = F | |
| mars.Angle = R | |
| if P < 4 { | |
| P++ | |
| } else { | |
| P = 2 | |
| } | |
| mars.Thrust = P | |
| fmt.Println(strconv.Itoa(mars.Angle) + " " + strconv.Itoa(mars.Thrust)) | |
| // fmt.Fprintln(os.Stderr, "Debug messages...") | |
| //fmt.Println("0 3") // R P. R is the desired rotation angle. P is the desired thrust power. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment