# minimum insertions to form a palindrome

Brute-force approach Here I present a few approaches to deduce “minimum insertions” required to convert a string into a palindrome.
The basic brute force approach is quite simple, given a string with length L, start comparing, the first character from left and the last character while scanning inwards.
Here is a basic test for a palindrome.
L = len(s) for i in range(L): if s[i] != s[L - i - 1]: return False,i,L-i -1 return True,0,0 The above code returns True if the string is a palindrome or returns False with mismatching indices.

# Inverse weighted distance interpolation in golang

Inverse distance weighting (IDW) is a type of deterministic method for multivariate interpolation with a known scattered set of points. The assigned values to unknown points are calculated with a weighted average of the values available at the known points.
This technique, explicitly makes the assumption that things that are close to one another are more alike than those that are farther apart. To predict a value for any unmeasured location, IDW uses the measured values surrounding the prediction location.

# basic sorting algorithms implemented in golang

This post includes go-lang based implementation of some of the classic sorting algorithms.
This article primarily, has been written, as an academic exercise, to not forget the basic principles of sorting.
Bubble Sort wiki Bubble sort is perhaps the simplest of all sorting algorithms, the basic principle is to bubble up the largest (or the smallest) and then the second largest and then the third largest and so on. Each bubble takes the full sweep of the list, hence best-case, average-case as well as the worst-case performance are all O(n2)

# reading and writing binary files in go lang

Reading and writing binary files can often be a fast and very efficient alternatives to csv. They obviously have their challenges, however in this post I intent to present a very basic example of saving models (struct) into binary file and later reading it.
package main import ( "log" "os" "encoding/binary" "bytes" "fmt" "math/rand" "time" ) //this type represnts a record with three fields type payload struct { One float32 Two float64 Three uint32 } func main() { writeFile() readFile() } func readFile() { file, err := os.

# Create linear color gradient in go

Go doesn't have any builtin gradient functions to paint/fill the background of a raster, however it has all the required primitives one needs to create a very basic linear gradient.
Here is a basic code which defines a 256 x 256 image, then calculates the value of each pixel in the raster based on a linear interpolation formula.
import ( "image" "image/color" "image/png" "log" "os" "os/exec" ) var( colorB = [3]float64{248, 54, 0} colorA = [3]float64{254, 140, 0} ) var( width = 256 height = 256 max = float64(width) ) func linearGradient(x, y float64) (uint8, uint8, uint8) { d := x/max r := colorA[0] + d * (colorB[0] - colorA[0]) g := colorA[1] + d * (colorB[1] - colorA[1]) b := colorA[2] + d * (colorB[2] - colorA[2]) return uint8(r), uint8(g), uint8(b) } func main() { var w, h int = width, height dst := image.