Last active
March 23, 2022 07:53
-
-
Save arehmandev/cd9b368d1447b98527636eba3ad563b2 to your computer and use it in GitHub Desktop.
Helping reddit question: https://www.reddit.com/r/golang/comments/dqztt5/need_help_with_a_script/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
intslice := [][]int{[]int{1}, []int{2}} | |
// Grow | |
for index, value := range intslice { | |
value = append(value, 0) | |
intslice[index] = value | |
} | |
insertion := []int{} | |
for index := 0; index < len(intslice)+1; index++ { | |
insertion = append(insertion, 0) | |
} | |
intslice = append(intslice, insertion) | |
fmt.Println(intslice) | |
// Shrink | |
for index, value := range intslice { | |
if len(value) == 0 { | |
fmt.Println("Cant shrink below 0") | |
continue | |
} | |
value = value[:len(value)-1] | |
intslice[index] = value | |
if index == len(intslice)-1 { | |
intslice = intslice[:len(intslice)-1] | |
} | |
} | |
fmt.Println(intslice) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# grows the list by list[len(list[n])+1][len(list[n][n])+1] | |
pythonlist = [[1], [2]] | |
for index, i in enumerate(pythonlist): | |
pythonlist[index].append(0) | |
pythonlist.append([]) | |
for i in range(len(pythonlist)): | |
pythonlist[-1].append(0) | |
# Shrink | |
print(pythonlist) | |
# shrinks the list by list[len(list[n])-1][len(list[n][n])-1] | |
for index, i in enumerate(pythonlist): | |
pythonlist[index].pop() | |
pythonlist.pop() | |
print(pythonlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment