ima/2025-10-08: variation fallliste
crispy-caesus crispy@crispy-caesus.eu
Thu, 09 Oct 2025 01:29:29 +0200
2 files changed,
95 insertions(+),
0 deletions(-)
A
ima/2025-10-08/binaerzaehler.go
@@ -0,0 +1,41 @@
+package main + +import ( + "fmt" + "strconv" +) +func binaer(decimal int) string { + n := int64(decimal) + return strconv.FormatInt(n, 2) +} + +func countUp(end int) []string { + var rows []string + for i := range end { + rows = append(rows, binaer(i)) + } + return rows +} + +func countOnes(rows []string, k int) { + for _, try := range rows { + ones := 0 + for _, digit := range try { + if digit == '1' { + ones++ + } + } + if ones == k { + fmt.Println(try) + } + } +} + +func main() { + k := 3 + n := 4 + + rows := countUp(1 << n) + fmt.Println(rows) + countOnes(rows, k) +}
A
ima/2025-10-08/binaerzaehler2.go
@@ -0,0 +1,54 @@
+package main + +import ( + "fmt" +) + +func createArr(nptr *int) *[][]bool { + arr := make([][]bool, (1 << *nptr)) + for i := range arr { + arr[i] = make([]bool, *nptr) + } + + for row := 1; row < len(arr); row++ { + copy(arr[row], arr[row-1]) + column: + for column := range arr[row]{ + if arr[row][column] == false { + arr[row][column] = true + break column + } else { + arr[row][column] = false + } + } + } + return &arr +} + +func readArr(arrptr *[][]bool, kpttr *int) *[][]bool { + var validRows [][]bool + counter := 0 + for row := range *arrptr { + counter = 0 + for column := range (*arrptr)[row] { + if (*arrptr)[row][column] == true { + counter++ + } + } + if counter == *kpttr { + validRows = append(validRows, (*arrptr)[row]) + } + } + return &validRows +} + +func main() { + n := 4 + k := 3 + + arrptr := createArr(&n) + fmt.Println(*arrptr) + + validRowpttr := readArr(arrptr, &k) + fmt.Println(*validRowpttr) +}