Skip to content

Commit

Permalink
5/channel - edit - fi. in Go using Stalecucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
nuoxoxo committed Sep 12, 2024
1 parent 6d11d2b commit ebd45c1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
59 changes: 59 additions & 0 deletions 5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"fmt"
"net/http"
"github.com/hydrogen18/stalecucumber"
)

func main() {
resp, err := http.Get("http://www.pythonchallenge.com/pc/def/banner.p")
if err != nil {
fmt.Println("resp/err", err)
}
defer resp.Body.Close()

// some stalecucumber magic
unpickled, err := stalecucumber.Unpickle(resp.Body)
if err != nil {
fmt.Println("stale/err", err)
}
data, ok := unpickled.([]interface{})
if !ok {
fmt.Println("assert/data", "not []interface{}")
}

// loop through line by line
for _, d := range data {
sub, ok := d.([]interface{})
if !ok {
fmt.Println("assert/sub", "not []interface{}")
}

line := ""
for _, pair := range sub {
kv, ok := pair.([]interface{})
if !ok {
fmt.Println("assert/pair", "not []interface{}")
}
if len(kv) != 2 {
fmt.Println("assert/err", "not key-value pair")
}
k, ok := kv[0].(string)
if !ok {
fmt.Println("assert/not string")
}
v, ok := kv[1].(int64)
if !ok {
fmt.Println("assert/not int64 - has to be int64")
}
i := 0
for i < int(v) {
line += k
i++
}
}
fmt.Println("line/ ", line)
}
}

7 changes: 0 additions & 7 deletions 5.py

This file was deleted.

10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module pych
go 1.22.4

require (
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ODAEL/nonogo v0.0.0-20190516210312-a0df0f59311b
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b
github.com/pmezard/go-difflib v1.0.0
)

require (
github.com/hydrogen18/stalecucumber v0.0.0-20180226003526-6de214d141dd // indirect
github.com/stretchr/testify v1.9.0 // indirect
)

0 comments on commit ebd45c1

Please sign in to comment.