Example #1
0
func main() {
	var n int
	data, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer data.Close()
	scanner := bufio.NewScanner(data)
	for scanner.Scan() {
		t := strings.Split(scanner.Text(), ";")
		u := strings.Split(t[0], ",")
		fmt.Sscan(t[1], &n)
		v, vk := make(map[int]bool, len(u)), make([]int, len(u))
		for i := range u {
			var w int
			fmt.Sscan(u[i], &w)
			v[w], vk = true, append(vk, w)
		}
		f := false
		for _, i := range vk {
			if 2*i < n && v[n-i] {
				if f {
					fmt.Print(";")
				}
				fmt.Print(i, ",", n-i)
				f = true
			}
		}
		if !f {
			fmt.Print("NULL")
		}
		fmt.Println()
	}
}
Example #2
0
func sLane(in string) string {
	var n, t int
	_, err := fmt.Sscan(in, &n, &t)
	if err != nil {
		return ""
	}
	fmt.Printf("n = %d, t = %d\n", n, t)
	w := make([]int, n)
	for i := 0; i < n; i += 2 {
		var f int
		_, err := fmt.Sscan(in[i+3:], &f)
		if err != nil {
			return ""
		}
		w = append(w, f)
	}

	v := make(TestCases, t)
	for z := 0; z < t; z++ {
		var tc TestCase
		_, err := fmt.Sscan(in[z+(n*2)+2:], &tc.Entry, &tc.Exit)
		if err != nil {
			return ""
		}
		v[z] = tc
	}
	fmt.Printf("%#v\n", v)

	for z := 0; z < len(v); z++ {

	}
	return ""
}
Example #3
0
func intersect(s, t string) string {
	var (
		a    int
		x, y []int
		r    []string
	)
	u, v := strings.Split(s, ","), strings.Split(t, ",")
	for _, i := range u {
		fmt.Sscan(i, &a)
		x = append(x, a)
	}
	for _, i := range v {
		fmt.Sscan(i, &a)
		y = append(y, a)
	}
	for i, j := 0, 0; i < len(u) && j < len(v); {
		if x[i] == y[j] {
			r = append(r, fmt.Sprint(x[i]))
			i++
			j++
		} else if x[i] > y[j] {
			j++
		} else {
			i++
		}
	}
	return strings.Join(r, ",")
}
Example #4
0
func main() {
	scanner := bufio.NewScanner(os.Stdin)

	// width: the number of cells on the X axis
	var width int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &width)

	// height: the number of cells on the Y axis
	var height int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &height)

	node := make([][]bool, height) //slice for nodes' rows

	for i := 0; i < height; i++ {
		node[i] = make([]bool, width) //slice - nodes' row
	}

	for i := 0; i < height; i++ { //find nodes
		scanner.Scan()
		line := scanner.Text() // width characters, each either 0 or .
		for j := 0; j < len(line); j++ {
			if string(line[j]) == "0" {
				node[i][j] = true
			}
		}
	}

	for i := 0; i < height; i++ {
		for j := 0; j < width; j++ {
			if node[i][j] { //is there a node?
				res := strconv.Itoa(j) + " " + strconv.Itoa(i) + " " //start of response
				for k := j + 1; k < width; k++ {
					if node[i][k] { //is there a node?
						res += strconv.Itoa(k) + " " + strconv.Itoa(i) + " " //inner response
						break
					}
				}
				if len(res) < 7 { //was node found?
					res += "-1 -1 "
				}
				for k := i + 1; k < height; k++ {
					if node[k][j] { //is there a node?
						res += strconv.Itoa(j) + " " + strconv.Itoa(k) //end response
						break
					}
				}
				if len(res) < 11 { //was node found?
					res += "-1 -1"
				}
				fmt.Println(res) //output response
			}
		}
	}

	// fmt.Fprintln(os.Stderr, "Debug messages...")

	//fmt.Println("0 0 1 0 0 1") // Three coordinates: a node, its right neighbor, its bottom neighbor
}
Example #5
0
func main() {
	B := new(big.Int).Exp(big.NewInt(2), big.NewInt(20), big.NewInt(0))

	p := new(big.Int)
	g := new(big.Int)
	h := new(big.Int)

	_, err := fmt.Sscan("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171", p)
	_, err = fmt.Sscan("11717829880366207009516117596335367088558084999998952205599979459063929499736583746670572176471460312928594829675428279466566527115212748467589894601965568", g)
	_, err = fmt.Sscan("3239475104050450443565264378728065788649097520952449527834792452971981976143292558073856937958553180532878928001494706097394108577585732452307673444020333", h)
	if err != nil {
		fmt.Println(err)
	}

	// Create a map that uses the calculations for x1's as keys
	hashTable := make(map[string]int64, B.Int64())

	var i int64
	for i = 0; i < B.Int64(); i++ {
		hashTable[computeX1(p, g, h, big.NewInt(i)).String()] = i
	}

	// Calculate the x0's and check if they are part of the hash table
	for i = 0; i < B.Int64(); i++ {
		x0Res := computeX0(p, g, B, big.NewInt(i))

		x1, found := hashTable[x0Res.String()]
		if found {
			x := B.Mul(B, big.NewInt(i))
			x.Add(x, big.NewInt(x1))
			fmt.Println("Solution:", x)
			return
		}
	}
}
Example #6
0
func main() {
	data, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer data.Close()
	scanner := bufio.NewScanner(data)
	for scanner.Scan() {
		var n int
		fmt.Sscan(scanner.Text(), &n)
		b := make([]int, n)
		scanner.Scan()
		s := strings.Split(scanner.Text(), ",")
		fmt.Sscan(s[0], &b[0])
		for i := 1; i < n; i++ {
			var v int
			fmt.Sscan(s[i], &v)
			b[i] = b[i-1] + v
		}
		for i := 1; i < n; i++ {
			scanner.Scan()
			s = strings.Split(scanner.Text(), ",")
			var v int
			fmt.Sscan(s[0], &v)
			b[0] += v
			for j := 1; j < n; j++ {
				var v int
				fmt.Sscan(s[j], &v)
				b[j] = min(b[j], b[j-1]) + v
			}
		}
		fmt.Println(b[n-1])
	}
}
Example #7
0
func main() {
	data, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer data.Close()
	scanner := bufio.NewScanner(data)
	for scanner.Scan() {
		s := strings.Split(scanner.Text(), ";")
		t := strings.Fields(s[1])
		var m, n, c int
		fmt.Sscan(s[0], &n)
		u := make([]int, len(t))
		for ix, i := range t {
			fmt.Sscan(i, &u[ix])
		}
		for i := 0; i < n; i++ {
			c += u[i]
		}
		if c > m {
			m = c
		}
		for len(u) > n {
			c = c - u[0] + u[n]
			if c > m {
				m = c
			}
			u = u[1:]
		}
		fmt.Println(m)
	}
}
Example #8
0
// Convert and validate the GOAGAIN_FD, GOAGAIN_NAME, and GOAGAIN_PPID
// environment variables.  If all three are present and in order, this
// is a child process that may pick up where the parent left off.
func GetEnvs() (l *net.TCPListener, ppid int, err error) {
	var fd uintptr
	_, err = fmt.Sscan(os.Getenv("GOAGAIN_FD"), &fd)
	if nil != err {
		return
	}
	var i net.Listener
	i, err = net.FileListener(os.NewFile(fd, os.Getenv("GOAGAIN_NAME")))
	if nil != err {
		return
	}
	l = i.(*net.TCPListener)
	if err = syscall.Close(int(fd)); nil != err {
		return
	}
	_, err = fmt.Sscan(os.Getenv("GOAGAIN_PPID"), &ppid)
	if nil != err {
		return
	}
	if syscall.Getppid() != ppid {
		err = errors.New(fmt.Sprintf(
			"GOAGAIN_PPID is %d but parent is %d\n",
			ppid,
			syscall.Getppid(),
		))
		return
	}
	return
}
Example #9
0
func compareSpamSum(left, right string) int {
	var leftSum, rightSum spamsum.SpamSum
	fmt.Sscan(left, &leftSum)
	fmt.Sscan(right, &rightSum)
	score := leftSum.Compare(rightSum)
	return int(score)
}
Example #10
0
func TestVoteBox(t *testing.T) {
	score := c.NewScore(69)
	server := hm.NewMock(map[string]hm.Responder{
		"/v": hm.FuncResponder(func(c *hm.Context) hm.Response {
			var vote, lastVote int
			// get values from the query parameters
			fmt.Sscan(c.Request.URL.Query().Get("vote"), &vote)
			fmt.Sscan(c.Request.URL.Query().Get("lastvote"), &lastVote)

			score.UserVote(vote, lastVote)

			return hm.NewOKResponse(fmt.Sprint(score.Score))
		}),
	})

	fntest.NewDummyTestApp("/", server)

	votebox := &VoteBoxModel{}
	votebox.VoteUrl = "/v"
	votebox.Vote = score

	// Start testing
	server.Wait(func() { votebox.DoVote(1) }, 1)
	require.Equal(t, votebox.Vote.Score, 70)
	server.Wait(func() { votebox.DoVote(-1) }, 1)
	require.Equal(t, votebox.Vote.Score, 68)
	server.Wait(func() { votebox.DoVote(-1) }, 1)
	require.Equal(t, votebox.Vote.Score, 69)
}
Example #11
0
// Recover from a seamless binary upgrade and use an already
// existing listener to take over the connections
func Recover() (l net.Listener, ppid int, err error) {
	var fd uintptr
	_, err = fmt.Sscan(os.Getenv("OLD_FD"), &fd)
	if err != nil {
		return
	}
	var i net.Listener
	i, err = net.FileListener(os.NewFile(fd, os.Getenv("OLD_NAME")))
	if err != nil {
		return
	}
	switch i.(type) {
	case *net.TCPListener:
		l = i.(*net.TCPListener)
	case *net.UnixListener:
		l = i.(*net.UnixListener)
	default:
		err = errors.New(fmt.Sprintf(
			"file descriptor is %T not *net.TCPListener or *net.UnixListener", i))
		return
	}
	if err = syscall.Close(int(fd)); err != nil {
		return
	}
	_, err = fmt.Sscan(os.Getenv("OLD_PPID"), &ppid)
	if err != nil {
		return
	}
	return
}
Example #12
0
func (this *BoolOptions) Load() {
	file, err := os.Open("settings.txt")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()

	v := reflect.ValueOf(this).Elem()
	var n int

	for err == nil {
		var key, value string
		n, err = fmt.Fscanf(file, "%s %s\n", &key, &value)
		if n == 0 {
			return
		}

		fieldValue := v.FieldByName(key)
		switch fieldValue.Kind() {
		case reflect.Bool:
			var b bool
			fmt.Sscan(value, &b)
			fieldValue.SetBool(b)
		case reflect.Float32, reflect.Float64:
			var f float64
			fmt.Sscan(value, &f)
			fieldValue.SetFloat(f)
		}
	}
}
Example #13
0
func (d *DatasourceDerive) CalculatePdpPrep(newValue string, interval float64) (float64, error) {
	if float64(d.Heartbeat) < interval {
		d.LastValue = Undefined
	}

	rate := math.NaN()
	newPdp := math.NaN()
	if newValue != Undefined && float64(d.Heartbeat) >= interval {
		newInt := new(big.Int)
		_, err := fmt.Sscan(newValue, newInt)
		if err != nil {
			return math.NaN(), errors.Errorf("not a simple signed integer: %s", newValue)
		}
		if d.LastValue != "U" {
			prevInt := new(big.Int)
			_, err := fmt.Sscan(d.LastValue, prevInt)
			if err != nil {
				return math.NaN(), errors.Wrap(err, 0)
			}
			diff := new(big.Int)
			diff.Sub(newInt, prevInt)

			newPdp = float64(diff.Uint64())
			rate = newPdp / interval
		}
	}

	if !d.checkRateBounds(rate) {
		newPdp = math.NaN()
	}

	d.LastValue = newValue

	return newPdp, nil
}
Example #14
0
// Handles the call to get many data points on blocks
func (srv *Server) blockexplorerBlockDataHandler(w http.ResponseWriter, req *http.Request) {
	// Extract the start and end point from the request
	var start, finish types.BlockHeight
	_, err := fmt.Sscan(req.FormValue("start"), &start)
	if err != nil {
		writeError(w, "Malformed or no start height", http.StatusBadRequest)
		return
	}

	// If a range end is not given, assume the range end to be one
	// greater than the range start, returning one block
	_, err = fmt.Sscan(req.FormValue("finish"), &finish)
	if err != nil {
		finish = start + 1
	}

	// Bounds checking is done inside BlockInfo
	blockSummaries, err := srv.blocke.BlockInfo(start, finish)
	if err != nil {
		writeError(w, err.Error(), http.StatusBadRequest)
		return
	}

	writeJSON(w, blockSummaries)
}
Example #15
0
func main() {
	sq := make(map[int]bool)
	for i := 0; i < 46341; i++ {
		sq[i*i] = true
	}

	data, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer data.Close()
	scanner := bufio.NewScanner(data)
	scanner.Scan()
	var n int
	fmt.Sscan(scanner.Text(), &n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		var x int
		fmt.Sscan(scanner.Text(), &x)
		num, l, bot, top := 0, make(map[int]bool), sqrt(x/2), sqrt(x)+1
		for j := bot; j < top; j++ {
			t := x - j*j
			if sq[t] && !l[t] {
				l[j*j], num = true, num+1
			}
		}
		fmt.Println(num)
	}
}
Example #16
0
// Convert and validate the GOAGAIN_FD and GOAGAIN_PPID environment
// variables.  If both are present and in order, this is a child process
// that may pick up where the parent left off.
func GetEnvs() (*net.TCPListener, int, error) {
	envFd := os.Getenv("GOAGAIN_FD")
	if "" == envFd {
		return nil, 0, errors.New("GOAGAIN_FD not set")
	}
	var fd uintptr
	_, err := fmt.Sscan(envFd, &fd)
	if nil != err {
		return nil, 0, err
	}
	tmp, err := net.FileListener(os.NewFile(fd, "listener"))
	if nil != err {
		return nil, 0, err
	}
	l := tmp.(*net.TCPListener)
	envPpid := os.Getenv("GOAGAIN_PPID")
	if "" == envPpid {
		return l, 0, errors.New("GOAGAIN_PPID not set")
	}
	var ppid int
	_, err = fmt.Sscan(envPpid, &ppid)
	if nil != err {
		return l, 0, err
	}
	if syscall.Getppid() != ppid {
		return l, ppid, errors.New(fmt.Sprintf(
			"GOAGAIN_PPID is %d but parent is %d\n", ppid, syscall.Getppid()))
	}
	return l, ppid, nil
}
Example #17
0
func TestDecScan(t *testing.T) {
	tmp := new(inf.Dec)
	for i, test := range decStringTests {
		if test.scale < 0 {
			// SetString only supports scale >= 0
			continue
		}
		// initialize to a non-zero value so that issues with parsing
		// 0 are detected
		tmp.Set(inf.NewDec(1234567890, 123))
		n1, n2 := new(inf.Dec), tmp
		nn1, err1 := fmt.Sscan(test.in, n1)
		nn2, err2 := fmt.Sscan(test.in, n2)
		if !test.scanOk {
			if err1 == nil || err2 == nil {
				t.Errorf("#%d (input '%s') ok incorrect, should be %t", i, test.in, test.scanOk)
			}
			continue
		}
		expected := inf.NewDec(test.val, test.scale)
		if nn1 != 1 || err1 != nil || nn2 != 1 || err2 != nil {
			t.Errorf("#%d (input '%s') error %d %v, %d %v", i, test.in, nn1, err1, nn2, err2)
			continue
		}
		if n1.Cmp(expected) != 0 {
			t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val)
		}
		if n2.Cmp(expected) != 0 {
			t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val)
		}
	}
}
Example #18
0
func (t *Table) readRow(rowNum int, rowValues []*interface{}) error {
	offset := t.RowOffsets[rowNum]
	for i, v := range t.ColumnTypes {
		var size int16
		var rep string
		binary.Read(cursor{&t.Data, offset}, binary.LittleEndian, &size)
		offset = offset + 2
		if size == -1 {
			*(rowValues[i]) = nil
			continue
		} else {
			rep = string(t.Data[offset : offset+int(size)])
			offset = offset + int(size)
		}
		switch v {
		case IntegerDatatype:
			var value int64
			_, err := fmt.Sscan(rep, &value)
			if err != nil {
				return err
			}
			*(rowValues[i]) = value
		case FloatDatatype:
			var value float64
			_, err := fmt.Sscan(rep, &value)
			if err != nil {
				return err
			}
			*(rowValues[i]) = value
		case StringDatatype:
			*(rowValues[i]) = rep
		}
	}
	return nil
}
Example #19
0
func memoryItem(font *Font, offset int, image *xgraphics.Image, window *xwindow.Window) *Item {
	channel := make(chan string, 8)
	go func() {
		file, err := os.Open("/proc/meminfo")
		if err != nil {
			log.Fatal(err)
		}

		for time := range time.NewTicker(time.Second).C {
			_ = time

			text, err := ioutil.ReadAll(file)
			if err != nil {
				log.Fatal(err)
			}
			_, err = file.Seek(0, 0)
			if err != nil {
				log.Fatal(err)
			}

			fields := strings.Fields(string(text))
			var mem_total, mem_free uint64
			fmt.Sscan(fields[1], &mem_total)
			fmt.Sscan(fields[4], &mem_free)

			channel <- fmt.Sprintf("Memory: %3v%%", (100*(mem_total-mem_free))/mem_total)
		}
	}()
	return &Item{Text: channel, Font: font, offset: offset, image: image, window: window}
}
Example #20
0
// Parse human-readable coordinates into a move operation
func parseMoveOp(from, to string) (op bopMovePiece, err error) {
	_, err = fmt.Sscan(from, &op.from)
	if err != nil {
		return
	}
	_, err = fmt.Sscan(to, &op.to)
	return
}
Example #21
0
func Geocode(address string, api string) (*[]GeoData, error) {
	var err error

	uri := getUri(address, api)

	client := &http.Client{}
	resp, err := client.Get(uri)
	if err != nil {
		return nil, err
	}

	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	if len(data) == 0 {
		return nil, errors.New("ZERO lenght response")
	}

	var ya yandexGeocodeResponse
	err = json.Unmarshal(data, &ya)
	if err != nil {
		return nil, err
	}

	cnt, err := strconv.Atoi(ya.Response.GeoObjectCollection.MetaDataProperty.GeocoderResponseMetaData.Found)
	if err != nil {
		return nil, err
	}

	geoData := make([]GeoData, cnt)

	for idx, obj := range ya.Response.GeoObjectCollection.FeatureMember {
		var gd GeoData

		_, err = fmt.Sscan(obj.GeoObject.Point.Pos, &gd.pos.lng, &gd.pos.lat)
		if err != nil {
			return nil, err
		}
		_, err = fmt.Sscan(obj.GeoObject.BoundedBy.Envelope.LowerCorner, &gd.lowerCorner.lng, &gd.lowerCorner.lat)
		if err != nil {
			return nil, err
		}
		_, err = fmt.Sscan(obj.GeoObject.BoundedBy.Envelope.UpperCorner, &gd.upperCorner.lng, &gd.upperCorner.lat)
		if err != nil {
			return nil, err
		}
		gd.address = obj.GeoObject.MetaDataProperty.GeocoderMetaData.AddressDetails.Country.AddressLine
		gd.city = obj.GeoObject.MetaDataProperty.GeocoderMetaData.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName
		gd.country = obj.GeoObject.MetaDataProperty.GeocoderMetaData.AddressDetails.Country.CountryName
		gd.countryCode = obj.GeoObject.MetaDataProperty.GeocoderMetaData.AddressDetails.Country.CountryNameCode
		gd.precision = obj.GeoObject.MetaDataProperty.GeocoderMetaData.Precision
		geoData[idx] = gd
	}

	return &geoData, nil
}
func MakeGraph(ac *AlgCfg) (err error) {
	g := new(FactorGraph)
	for i := uint8(0); i < ac.VarNodes; i++ {

		g.AddVertex(0)
		g.Vertices[i].StdOut = make(chan VariableOut, 4)
	}

	for i := 0; i < len(ac.StateNodes); i++ {

		g.AddVertexState(1, int(ac.StateNodes[i]))

	}
	for i := uint8(0); i < ac.FuncNodes; i++ {

		g.AddVertex(2)

	}
	awgn := RandomAWGNGenerator(ac.Rate, ac.Eb, ac.No)
	for i := 0; i < len(ac.FuncSpecs); i++ {
		fs := strings.Split(ac.FuncSpecs[i], "]")
		input := strings.Split(fs[0][1:], ",")
		separator := ""
		if ac.AlgType == "B" {
			separator += ","
		}

		output := strings.Split(fs[1], separator)
		array := make([]float64, len(output))
		G := false
		for j := 0; j < len(output); j++ {
			if output[j] == "G" {
				G = true
				array = awgn()
				break
			}
			fmt.Sscan(output[j], &array[j])
		}
		node_offset := len(ac.StateNodes) + int(ac.VarNodes)
		g.Vertices[i+node_offset].Output = array
		g.Vertices[i+node_offset].G = G

		for j := 0; j < len(input); j++ {
			vn := 0

			fmt.Sscan(input[j], &vn)

			err = g.AddUndirectedEdge(&g.Vertices[i+node_offset], &g.Vertices[vn])
			if err != nil {
				return
			}
		}
	}
	ac.Graph = g
	return
}
Example #23
0
func prefix(q string) int {
	var r, v float32
	s := strings.Fields(q)
	n := len(s)
	fmt.Sscan(s[n/2], &r)
	for i := 1; i <= n/2; i++ {
		fmt.Sscan(s[n/2+i], &v)
		r = pol(s[n/2-i][0], r, v)
	}
	return int(r + 0.001)
}
Example #24
0
func main() {

	// Challenge #1
	N := new(big.Int)
	fmt.Sscan("179769313486231590772930519078902473361797697894230657273430081157732675805505620686985379449212982959585501387537164015710139858647833778606925583497541085196591615128057575940752635007475935288710823649949940771895617054361149474865046711015101563940680527540071584560878577663743040086340742855278549092581", N)

	A := mathutil.SqrtBig(N)
	A = A.Add(A, big.NewInt(1))

	q, p := factor(A, N)

	if checkFactors(p, q, N) {
		fmt.Println("Challenge #1 Solution")
		fmt.Println("q:", q)
		fmt.Println("p:", p)
	}

	// Challenge #2
	N2 := new(big.Int)
	fmt.Sscan("648455842808071669662824265346772278726343720706976263060439070378797308618081116462714015276061417569195587321840254520655424906719892428844841839353281972988531310511738648965962582821502504990264452100885281673303711142296421027840289307657458645233683357077834689715838646088239640236866252211790085787877", N2)

	A2 := mathutil.SqrtBig(N2)

	for i := A2; i.Cmp(N2) <= 0; i.Add(i, big.NewInt(1)) {
		q2, p2 := factor(A2, N2)
		if checkFactors(p2, q2, N2) {
			fmt.Println("Challenge #2 Solution")
			fmt.Println("q:", q2)
			fmt.Println("p:", p2)
			break
		}
	}

	// Challenge #4
	cipher := new(big.Int)
	fmt.Sscan("22096451867410381776306561134883418017410069787892831071731839143676135600120538004282329650473509424343946219751512256465839967942889460764542040581564748988013734864120452325229320176487916666402997509188729971690526083222067771600019329260870009579993724077458967773697817571267229951148662959627934791540", cipher)
	e := big.NewInt(65537)
	phi := big.NewInt(1)
	phi = phi.Mul(p.Sub(p, big.NewInt(1)), q.Sub(q, big.NewInt(1)))

	d := big.NewInt(0)
	d.ModInverse(e, phi)

	cipher.Exp(cipher, d, N)
	hexEncoded := fmt.Sprintf("%x", cipher)

	ind := strings.Index(hexEncoded, "00")
	if ind != -1 {
		fmt.Println("Challenge #4 Solution")
		res, _ := hex.DecodeString(hexEncoded[ind+2:])
		fmt.Println(string(res))
	}

}
Example #25
0
func main() {
	mySentence := "2 4"
	var two, four int
	fmt.Sscan(mySentence, &two, &four)
	fmt.Println(two, four)
	mySentence = "This is a 2nd attempt"
	var myWords []string
	num, err := fmt.Sscan(mySentence, myWords...)
	fmt.Println(num, err)
	fmt.Println(myWords)
}
func multiplyLists(q string) string {
	var u, v int
	s := strings.Split(q, " | ")
	x, y := strings.Fields(s[0]), strings.Fields(s[1])
	r := make([]string, len(x))
	for i := range x {
		fmt.Sscan(x[i], &u)
		fmt.Sscan(y[i], &v)
		r[i] = fmt.Sprint(u * v)
	}
	return strings.Join(r, " ")
}
func main() {
	someSentence := "3 4"
	var three, four int
	fmt.Sscan(someSentence, &three, &four)
	fmt.Println(three, four)

	someSentence = "again"
	var someWords []string
	num, err := fmt.Sscan(someSentence, someWords...)
	fmt.Println(num, err)
	fmt.Println(someWords)
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var LON string
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &LON)

	var LAT string
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &LAT)

	var N int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &N)

	// Fix Longitude and Latitude values
	LON = strings.Replace(LON, ",", ".", -1)
	LAT = strings.Replace(LAT, ",", ".", -1)

	LONINT, _ := strconv.ParseFloat(LON, 64)
	LATINT, _ := strconv.ParseFloat(LAT, 64)

	//var lines []string

	// Variable to hold closest location
	var closeLocation float64 = 10000

	// Variable to hold name of closest
	var Name string

	// If only single value, use it
	// otherwise figure out which is the closest
	if N == 1 {
		scanner.Scan()
		ucl := GetInfo(scanner.Text())
		Name = ucl.Name
	} else {
		for i := 0; i < N; i++ {
			scanner.Scan()
			ucl := GetInfo(scanner.Text())
			if location(LONINT, LATINT, ucl) < closeLocation {
				closeLocation = location(LONINT, LATINT, ucl)
				Name = ucl.Name
			}
		}
	}

	// fmt.Fprintln(os.Stderr, "Debug messages...")

	fmt.Println(Name)
	//fmt.Println(LAT)
}
Example #29
0
File: msg.go Project: nictuku/bitz
func init() {
	// Flip the byte order for BitMessage, which is different than BitCoin.
	encVarint.ByteOrder = binary.BigEndian

	n2to64 = new(big.Int)
	if _, err := fmt.Sscan("18446744073709551617", n2to64); err != nil {
		log.Panicf("error scanning math.Big value n2to64:", err)
	}
	initialTrial = new(big.Int)
	if _, err := fmt.Sscan("99999999999999999999", initialTrial); err != nil {
		log.Panicf("error scanning math.Big value initialTrial:", err)
	}
}
Example #30
0
// Kill process specified in the environment with the signal specified in the
// environment; default to SIGQUIT.
func killParentAfterRestart() error {
	var pid int
	_, err := fmt.Sscan(os.Getenv("RESTART_PID"), &pid)
	if io.EOF == err {
		_, err = fmt.Sscan(os.Getenv("RESTART_PPID"), &pid)
	}
	if nil != err {
		return err
	}

	log.Infoln("Sending parent GRAIN (pid: ", pid, ") QUIT signal")
	return syscall.Kill(pid, syscall.SIGQUIT)
}