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! ;-)
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top