What Does the 'Split' Function Do in Google's Go Language Tutorial?

  • Thread starter Thread starter d3mm
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion centers around a Python implementation of a function called `split`, which divides an integer input into two parts: one that is approximately 4/9 of the input and another that is the remainder, approximately 5/9. The function is presented as a way to explore the Go programming language, with the user expressing curiosity about the mathematical significance of this specific division. While the function's purpose is clear in terms of splitting numbers, the user seeks to understand if there are deeper mathematical implications or applications beyond its straightforward functionality.
d3mm
Messages
140
Reaction score
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:
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
 
Technology news on Phys.org
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:
 
Yes but I was wondering if it had mathematical sigificance beyond the obvious! ;-)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top