Giter Club home page Giter Club logo

martian-robots's Introduction

bin/martian_robots.rb --load ./docs/sample_input.txt

Mars Robots Technical Tests

Thank you for providing a interesting technical test. I understand that a technical test gives an opportunity to demonstrate that I can construct an object hierarchy, encapsulating discrete behaviour within each object. I considered an approach like this

class L; end; class R; end; class F; end; ...

However given the requirement for a Keep It Simple Stupid approach, I have instead used an approach based on vectors and polar coordinates to provide this behaviour:

def projected_pos(magnitude=1)
  p2 = {
    x: (magnitude * Math.sin(@current_orientation * Math::PI)).to_i,
    y: (magnitude * Math.cos(@current_orientation * Math::PI)).to_i
  }
  return {
    x: current_pos[:x] + p2[:x],
    y: current_pos[:y] + p2[:y]
  }
end

Using the above method provides the option:

  1. Magnitude of any positive or negative number of forward movement not just 1.
  2. Using any direction 0 to 360 degrees instead of just North South East West.

Errata

I have found a typo in the Sample Output. The provided sample input and output indicates that a starting position of '0 3 W' and a movement sequence of 'LLFFFLFLFL' results in a final position of '2 3 S'. however, if you plot it out

0 3 W 
0 3 S
0 3 E
1 3 E
2 3 E
3 3 E
3 3 N
3 3 N LOST

This must be a typo, if the starting position was '0 2 W' then the plot would be

0 2 W
0 2 S
0 2 E
1 2 E
2 2 E
3 2 E
3 2 N
3 3 N
3 3 W
2 3 W
2 3 S
2 3 S

Therefore I am replacing '0 3 W' with '0 2 W' in the Sample Input, docs/sample_input.txt

martian-robots's People

Contributors

leo-ajc avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.