Code Snippet Bytecode VM Implemented in Golang
The GitHub Repo is [here](https://github.com/apkrieg/foovm). This was part of a contest with someone I met on Omegle. The goal was to see who's VM could run a set of example app the fastest, the catch: We had about 24 hours to implement the solution. My language of choice was Golang, his was C. I won the contest as he could not get his VM working correctly even after I gave him an extra 48 hours. There is a VERY basic bytecode manual on the GitHub README. The example apps we ran were: * Hello World (a very complex version) * …
|+0 forum 0|
Code Snippet Some number tricks (golang)
Just a couple of number tricks to check Go's mathematical abilities. If you have more, let's show them here.
|+2 forum 1|
Code Snippet Grains of rice on a chessboard (golang)
The story has it that a few hundred years ago the ruler of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then doubling it for every remaining square. The ruler acted surprised by the humble request, had his helpers bring a bag of rice and started to fill the squares. Did the creator of the chess game get a decent reward? Let's check it with some Go code. Note: I printed out …
|+2 forum 5|
Code Snippet Using a map for minimum bills or coins (golang)
Again, calculate the minimum number of bills or coins required for a given amount of money (change). This time we will use a Go map instead of a csv string converted to a structure.
|+0 forum 0|
Code Snippet Minimum number of bills or coins in change (golang)
This Go snippet calculates the minimum number of bills or coins needed for a given amount of money (change) requested. The program also gives the denomination and number. US curency is used in this example, but can be changed to another currency.
|+1 forum 0|
Code Snippet A slice of prime numbers (golang)
Another translation of one of my Python snippets. This function will return a slice of consecutive prime numbers from 2 to a given value limit. In Go the 'int' type (int32) will go as high as 2147483647, but you can replace 'int' with 'uint64' and go as high as 18446744073709551615.
|+1 forum 0|
Code Snippet Creating a generator (golang)
Generators are rather familiar objects in Python. Generators supply data on demand. Using Go you can create a generator with a goroutine and a channel. Here the goroutine is an anonymous function within a function, simple to implement.
|+0 forum 1|
Code Snippet A slice of structures (golang)
Another little adventure into Go coding. This time a slice (a Go open ended array) of structures is used as a record for some data processing. For those who miss the ; at the end of a line of code, you can use them, but the lexer of the compiler will put them in for you. Go slices are simpler to work with and faster than traditional arrays, even though they use arrays as a backbone. Go was written for efficiency and speed of compilation in mind, it is intolerant of unused imports and unused variables. The reason you will …
|+1 forum 3|
Code Snippet Grading scores example (golang)
This time just a simple example of grading scores (0 - 100) with letters (A - F). Two approaches are presented, one using switch/case in an "on the fly" function, and the other uses the score as an index to a string of letters F through A.
|+1 forum 1|
Code Snippet Get the content of a web page (golang)
Reading the content of a web page with a given URL is pretty simple with Go. Here we defer the closing of the response body (at an early point, so we won't later forget) until the program exits.
|+0 forum 0|
Code Snippet Denary number to roman numerals (golang)
Use Google's modern Go language (aka. golang) to convert a denary number (base 10) to a roman numeral. Just a good exercise to explore Go's map, slice, sort and for loop features. Note that in Go the **:=** is shorthand for assigning a type (by inference) and a value to a variable. A slice is like an array that can grow, and a map is a key indexed list. Go has only the for loop, but the syntax is very flexible and can accomplish all the usual loop duties.
|+2 forum 0|
Just wanted to know if anyone on DaniWeb is using or at least experimenting with Go.
|+0 forum 11|