Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is this Algorithm?

  1. Mar 20, 2013 #1
    So I decided today I wanted to learn a new programming language (for fun).

    Normally I would ask this on a general purpose programming site, but I figured perhaps this might be a better place for algorithms of this type?

    In the tutorial for Google's "Go" language I came across this, and I am wondering if it's an algorithm for doing something, or if it's just arbitary?

    Code (Text):

    def split (n):
        x = n * 4 // 9  # integer division
        y = n - x
        return x, y

    >>> split (17)
    (7, 10)
    >>> split (56)
    (24, 32)
    (I re-wrote it in Python as the syntax is probably well known here, and very readable. I wasn't sure if he original Go would be as easy for people who haven't seen Go before), but it is here http://tour.golang.org/#9
     
  2. jcsd
  3. Mar 20, 2013 #2
    It seems to be intended for splitting integer numbers into two integer numbers where the first is close to (or exactly) 4/9 (four ninths) of the input of the input number and the second is the close to 5/9, i.e., the complement to 1.0

    ...but you already knew this :smile:
     
  4. Mar 20, 2013 #3
    Yes but I was wondering if it had mathematical sigificance beyond the obvious! ;-)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook