30 days of code in Go: Day 7 - Arrays

Hi there! A couple days ago I wrote a post about a simple array sum in Go and I said I didn’t need an array in memory to do the sum, but just an integer that would store the inputs the user gave the program. This time, I will really need an array. The goal is to read an array $A$ of $N$ elements and print $A$ elements in reverse order....

September 13, 2016 · 2 min

30 days of code in Go: Day 6 - Let's review

Some challenges require us to review basic concepts to make them work. This one is no different, but the main purpose of it is to be a review! The goal is to separate the characters of a string. The even-indexed characters will form a string and the odd-indexed characters will form another. These two strings must be printed to the screen with a space between them. Not hard, but an important review....

September 12, 2016 · 2 min

30 days of code in Go: Day 5 - Loops

Hi there! Welcome to Day 5 of 30 days of code in Go! One interesting thing about loops in Go is that there is only one looping construct: for. This challenge will receive an integer input $N$ and it will print results of the form $N\times i = \mathrm{result}$, where $1 \le i \le 10$. By the way, there was a loop on the last day of code, but it was actually part of the given code....

September 11, 2016 · 1 min

30 days of code in Go: Day 4 - Class vs Instance

Here I am again for the 30 Days of Code in Go. This is Saturday, but that doesn’t mean I will not code =). First of all, before starting to code I was thinking about the theme: classes. I was wondering if Go had support for it and I found some interesting material to read. First I read Why Go’s structs are superior to class-based inheritance and I found out the the inheritance model of Go is different from that of Java....

September 10, 2016 · 2 min

Simple Array Sum in Go

Hello again! I saw a problem in HackerRank to sum an array of elements. I have done this before in a couple of languages, but never in Go, so I was not sure exactly what to do. I coded the solution and it is: package main import "fmt" func main() { var n uint32 fmt.Scanf("%d\n", &n) sum := 0 current := 0 for n > 0 { fmt.Scanf("%d", ¤t) sum += current n-- } fmt....

September 9, 2016 · 1 min

30 days of code in Go: Day 3 - Conditional Statements

The HackerRank challenge of today was a problem with conditionals. Given an integer $n$, the goal was to perform the following actions: If $n$ is odd, print Weird If $n$ is even and in the range $[2, 5]$, print Not Weird If $n$ is even and in the range $[6, 20]$, print Weird If $n$ is even and greater than $20$, print Weird The input to the program is simply the number $n$ and the result is a single line saying that the number is weird or not....

September 9, 2016 · 1 min

30 days of code in Go: Day 2 - computing the total cost of a meal

Hi there! Today is the day 2 challenge. The goal is to compute the total cost of a meal given the meal price, tip percent and tax percent. Usually when I go to a restaurant in Brazil I only care about the first two, as taxes are already included in the meal price. Again: this is pretty basic, but as I am used to other languages syntax this simple tutorial from HackerRank is being quite useful to keep me training everyday and learn Go, so it is awesome!...

September 8, 2016 · 2 min

30 days of code in Go: Day 1 - summing numbers and concatenating strings

The goal of this second day is the following: Declare 3 variables: an int, a double and a string. Read 3 lines from stdin and save them in the variables you just defined Do some operations with the pre-defined $i$, $d$ and $s$ variables Print the sum of the integer $i$ with your integer variable Print the sum of the float $d$ with your double variable with one decimal place Concatenate $s$ with your string and print the result My solution was the following...

September 7, 2016 · 1 min

30 days of code in Go: Day 0 - Reading from stdin

Today I am starting the 30 days of code challenge on Hackerrank. You will be able to see my progress at my profile. The language I chose is Go. I do not have experience in Go and I am pretty excited. I think the challenge is basic, but it will probably be fun, so bear with me. Later on I may take better challenges, when I get more experience with Hackerrank....

September 6, 2016 · 2 min