Skip to content

Instantly share code, notes, and snippets.

View dimonomid's full-sized avatar

Dmitry Frank dimonomid

View GitHub Profile
func main() {
srcSlice := []int{1, 2, 3}
anotherSlice := srcSlice[:3]
for i := 0; i < 3; i++ {
srcSlice[i] += 10
}
fmt.Println(srcSlice)
fmt.Println(anotherSlice)
}
func main() {
s := []int{1, 2, 3}
p := s[:3]
for i := 0; i < 3; i++ {
s[i] += 10
}
fmt.Println(s)
fmt.Println(p)
}
@dimonomid
dimonomid / orgs.rb
Created May 31, 2017 23:32
Organization IPs
input = [
[1, 0, 0, 0, 256, "AU-8a888ca7567d"],
[1, 0, 1, 0, 256, "CN-8173da22ea8b"],
[1, 0, 2, 0, 512, "CN-8173da22ea8b"],
[1, 0, 4, 0, 1024, "AU-4d44a4952b26"],
[1, 0, 8, 0, 2048, "CN-cc1064bf6999"],
[1, 0, 16, 0, 4096, "JP-9413fa3d189a"],
[1, 0, 32, 0, 8192, "CN-cc1064bf6999"]
]
@dimonomid
dimonomid / cars.go
Last active May 3, 2017 13:53
Get required cars number
func getRequiredCarsNum2(busCap, carCap int, stations []int) int {
cars := 0
busUsed := false
resortFullBus := -1
resortHalfBus := -1
halfBusMax := 0
for i, p := range stations {
// Don't care about empty stations
if p == 0 {
@dimonomid
dimonomid / flatten.go
Created March 28, 2017 21:29
Flatten array of integers
// Flatten integers array
//
// This simple utility flattens an arbitrarily nested array of integers.
// Example: [[1,2,[3]],4] -> [1,2,3,4]
//
// Example usage:
// $ ./flatten '[1,2,[4,5,[6],12],14]'
// [1 2 4 5 6 12 14]
//
// If no argument is provided, an example data is used: [[1,2,[3]],4]