Compare commits
1 Commits
04bbac8559
...
hackerrank
| Author | SHA1 | Date | |
|---|---|---|---|
|
a5ebbe25d0
|
@@ -1,11 +0,0 @@
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#...#..
|
||||
....#.#....
|
||||
.##..S####.
|
||||
.##..#...#.
|
||||
.......##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
@@ -1,131 +0,0 @@
|
||||
...................................................................................................................................
|
||||
.#.......#..#...#.......#......#....#..#...#...#....#.#..........................................#...............#..........#......
|
||||
.............##..................#......#.#....#.......................##..#........................#......#..........#............
|
||||
......#..........................#....#.....#.............#................##....#.#.............#.........#.##...........#........
|
||||
.#................#............................#...........................#..##.....#..................#..##..#.#.........##......
|
||||
.....#.............#.....##.............##..........#...........#.............#.....#...........#.#.......#....#......#..........#.
|
||||
........#....................#....#.#.#......##........#...........#...........#..........#...#..........#......................#..
|
||||
.........#.#...#.......#........#........##...#...#..##........................................##...#.#........................#...
|
||||
......#.....#..#..#.#..#..............#...#..#.....#...........#.....#........#.#...........#...........#.#...............#.....#..
|
||||
...........#.......####..#.#..............##................#.#.#.....................##.....................#...#..............#..
|
||||
......###...#......#................##...#...#....#...........#...#..............#.........#..#..................................#.
|
||||
...............#..##..........#...........................##......#.##.........................#..#.#...........#.#...........#....
|
||||
...##........#...#...#...##...##...........#..#...................#...................#.#..#.........#.......#..#...........##...#.
|
||||
................#.....#..##......#.....#.....##............#..#..........##...........................#.#.......##.....#.....#.....
|
||||
.#..#.......#.#...#..##.....#............................#......#...#....#................#.#..#.....#.......##................#...
|
||||
...............#.....#........................#..........#.....#..............................................#..................#.
|
||||
.....#......#..........................................#....................................#..#.......#.#..#......#.#....#..##....
|
||||
............##............#.......###.......................#..#....#......................................#..#.........#..........
|
||||
..#...............#.....#...#...#......................#...#.#..............................#.#..#.#.....#.#.#..#....#.....#...##..
|
||||
.#.............................##.................#.......#.......##....#....................#.....#.#........#.....#........#.....
|
||||
.#....##...................##.....#.#..............#.#....#....#..#....#......#..........#.....##............#....#.............##.
|
||||
.........#....#.....#..#.........#....#.#..........#...#...#.......#....#..##.......................#.#..#........#..#....#..#.#...
|
||||
..#..................#.......#..#.#..............##.......#........#..............#.........#..#....#......#..#..........#.........
|
||||
........#.....#......#.....#......#...#.......#....#.......#.#..#................#....................##.............#.......#.....
|
||||
..#.................#..............#...........................................#.....#..................#...#.#..................#.
|
||||
.......#......#.....#...........................#.....#..................#.....................#.....#.#......#........#.#.......#.
|
||||
..#.#.#...................#...#..#................#....#.......#......................#...............#.........##...#.#.....###...
|
||||
.....#...#....##....#........####...........#.................#...#...........................................#..............##....
|
||||
..##.#..#.#..........#.#.#..#................................#..#.............#..#......#...........................#.##...........
|
||||
..............#.............................##........#..##........................#.............................#........#........
|
||||
........#.........#........#..#........#..#........#...#.#........#...........#.........................#.#..........#...#......#..
|
||||
.........##.....#........#.....................#..#.............#.....#........#....................#....#.#.#......#.....#........
|
||||
......................#...................####..#.........#....#.........#...........#..................#..#.................#.....
|
||||
..#.........#...#.....##................##.##....#.....#....#..............................#..#.............#..#...................
|
||||
..........##......#..#..............#.#....#......#................#.....#....#..............#..................#..................
|
||||
.#.#..####...#....................#.#.#.....#...#...................#....#.#.....#.#.......#.#...........#......#.#................
|
||||
.......#.........#..#.#..............###.......#....#.........................#.......#.###...#............#....#.#..#....###.#....
|
||||
........#....#...#......#.................#..........................#.........................#...........##.............#.#......
|
||||
.#..............#.....................#......#.............##............#..#..........#...................#...#....#..............
|
||||
......#..#..#.#...............#........###.......#.#...........#...........#.#.........#..#.....................#......#..#.#......
|
||||
.....#...............#.........#....#..........#.......#.......#......#...#..##.....#.....#........#.#.......#.......#..#...#......
|
||||
..#............#.....................#...#.......#....###...........#.....#.#.................#................#.........#..##.#...
|
||||
..............................#.....#..................................#.....##...............#.......#.........#.....#....##......
|
||||
..#...##...#...#..............#.................##..#......#.................#....#......#...#...#......#..........................
|
||||
.........#....#..............#........#..#...............#....#...#.....#..#......#.........#.......#.#..#........#...........#....
|
||||
........#..#....................#.........#...##.#.#..............#......#.#..........##...##....#......................#..........
|
||||
.##..#....#....#.......##......#............#..#......#.....##..................#####..#...#......#.#...#..........#.#.....#..#....
|
||||
..#...........#....................#.......#......#.........#...............#......#........##........#.................#.....#.#..
|
||||
..#....#.#...............#.#.........................#.............####..............................##................###.........
|
||||
.....#.......................................#....#...##...#.......#.......#.....#.##..##.................#.....................##.
|
||||
.........#...........#..#..##.#..........#..#.........#..#.....#...................................##....#...............#..#.#....
|
||||
.....#..#...........##............#........#..................#............#..........#..........#..#...........#..................
|
||||
............................#.........#...............#..................#.#....#.#..#........#.....#...........#...........#......
|
||||
................#...##.#....#..##..........#.#........##.#..#..#.....................#....#.................#.#...............#....
|
||||
.#.....#..............#.#..........#..#........#...............#..#.#..##..#.#.#.........................#.................#.......
|
||||
....#..............#................#.....#..#.......#..#.#.........#..........#..........#.....#..........##.....#............#...
|
||||
..............##...........#.......#......#..................#.......#.....#.#...#...............#.#........#......#............#..
|
||||
................#.....#....#........#....#.......#.#.##.....#...#..#.##...#................#.#.....#....#.............#............
|
||||
...........#.#.##..####.....#....#.#...#.#...........#...#.......................#.#....#.....#..#................###..............
|
||||
...................#....#..........#.#..##.....#..#..#......###............#..#...........#....#......#............................
|
||||
...........................................#.......#..............#.##.......##.......#...#.....#.#..#.....#..###..................
|
||||
............###........#.......#.#....#.....#....#..#........#.........##....#.....#..........#......#............#..#.#...........
|
||||
............#..........#................##.#..............#.....#................#....................................#..#.........
|
||||
...........#.....#.....................#...#.....#.......#..........#....#.....###.....##.#.##.#.....#......#......#.......#.......
|
||||
.....................#..#.....#...##.....#..#...........#....#....##............##.................##............##................
|
||||
.................................................................S.................................................................
|
||||
........#.#........#..........#.....#......#........#.#............#.#.........##...#............#...#.....#...........#.....#.....
|
||||
..................##.......#......#..#..................#..##......#.........#...#.........#............#....#...........##........
|
||||
..................#...........#.##.......#..............#....................#.#....#...##...#.....#.......#..#.....##.............
|
||||
...........#....#....##...#................................#.........#.................#....#.......................#...#..........
|
||||
.............#.#.#.....#.#...#.......#.#...........#....#.#.........#........##......#.......#.......##...#..........#.##..........
|
||||
...........##.#....#....#..#.....#...............#......................#...........#.....#...........#.#.......#..................
|
||||
.#.......................#.#...##.#....#.#...........#.#....##.##......#........................##....#.#....#.....................
|
||||
...#..................#.#...........##....###.................#....................##......#.....#............#.##....#.......##...
|
||||
.#..................####...#.#..#.##.#...####...#......#....................#..........................#....#......................
|
||||
.....#..........#.....#.#...............#.........##...#......#.#.....#...........#.....#............##......#.....#...............
|
||||
......#........#....#..#............................###.#...##........#........#.................#..#........#...............##....
|
||||
......................#.........................##....#...#..............#..#............#.#....#......##.#......#.........##......
|
||||
..................#....#...#.#.......#..............#..#..#...#.......#...#.....#.....#...............#.#.#...............#........
|
||||
...#...##......................##..##...........#......#.............#............#...........##.......#....#......................
|
||||
.............................##...........##...#...#.....#....#.......#.#..#.....##...............#..#.#......#..............##....
|
||||
...#..#.#...#.......#..................#............#....#.#.##.#.........#......#........#..#..........#....##...........#....#...
|
||||
.....#.............................#......#.#.....#.##.#.................#.........#..#..#.#.#........................#.#.......#..
|
||||
....#........#........#....#.#.#.....#.##............###.#..........#...##......#........##...#.........#.............#........#...
|
||||
..#..............................#.............................#......#...................#...#......#.............#...............
|
||||
.......#...#...............#.................##....................#....##.......#....##....##...#..................#..............
|
||||
.........................#...#..#.....##.............#...##.......#.....#...#..............#.....#.#.#..#........................#.
|
||||
......#.......##.#.............#....................#...#...........#...#..##....#.....#............#...........#........#.........
|
||||
...#....#...#......#........................#.....#.........#......#........#.....#.#...........#.#..............#......#....#.....
|
||||
........#..........#...................#...........##.#..#...#................#....##.............#................#....#..........
|
||||
........#.......#....#.............#..........#...................#.#....#.#........#..#..............................#..........#.
|
||||
............#........#....................#.#.........#......#.............#................#...#.............#....#...............
|
||||
..#..............................#..#....##.....#......................##...#..#.........#......#......................#...#...#.#.
|
||||
.##....#.............#...........##..................#...#..............#.......#................................#.........#.......
|
||||
.....#......#.#.....##...........#.....#.......#..........##..#.............#.#.........#.#.#.............##........#......#..#....
|
||||
.......#.......#.#.#..#......................#....#............##....#...........#.........................#......#................
|
||||
.........##.........#..............#.#.#....#...#.......#.................................#..##..................##.###.##...#.....
|
||||
......................#...#.#.......#..#.#..........#........#.......#.................#..................................#........
|
||||
....##........#.........#.........................#................#......#...#.....#..................................#..#.#......
|
||||
...##..............#..................#...#......#........###..#.......#..........#..............................#......#..........
|
||||
.#.#.#....#..........#......#.#.........#.....#...............................#.....#.#............#....#........#.............#...
|
||||
........#.........#.........#......................#..#......##.....#..#..........................#......##....#......##.##.....#..
|
||||
.##...#.......#.#....#..#.#...................#.........#....#...........#.....#.........#............##......#............#.......
|
||||
.##..#.........#..........#.#.................................#.#.#...............................#............#......##...#.#.....
|
||||
......#........#..#...#............#..............#............#......##.....#.................................#......#.#.....#....
|
||||
..........#........#...........#....................................#.....#...............................#............##....#.##..
|
||||
........#.............#..#......##..................#.............#..#...#.#.....#...#...............#........................#....
|
||||
....#...............#..........#....#...........................#....##.##...................#.#.......#...#.##....#........##..#..
|
||||
......#.....#..#..........###...#.................####.###..........#...........#..........#......#............................#...
|
||||
.#...#......#........#..#............##...............#.##......#...#.....#....................#.........#............#...#........
|
||||
................##...................#.##..............#...#..#.......#.......###........#..#..#........#...##.....................
|
||||
..............#....#..#..#.............##..............#................................#.....#..#....###.##..............#........
|
||||
..#..............#........................................#..........#.....#..................#............#..#....................
|
||||
.........#...#.....#...#...##...........#.###............##...#........#......................##......#....#.......#...............
|
||||
....#....#.....#.......#......................................#.#.#....#..#..#..........#...................#........#...#.........
|
||||
..#..#..................#..............#...#..#.........#......#....#.#................##..........#..#................#...........
|
||||
...#...................#...........#....#...#.............##...#.......#.#..........#..#...............#....#....#.............#...
|
||||
.......................##.#.#..##........#....#.........#.#.#.....##..............#.......#.......##.#..........#.#................
|
||||
.....#..#..................#..##....#.......#.............#...#.....#.............#.............#.#...............#.....##......##.
|
||||
...#.#.....#..........#.#............#..#..........................##.............#....#.......#.#...#...#....................#.#..
|
||||
............##.#............#....#....#....#..##...#...............................#...#...#.........#.......................##.##.
|
||||
....#.#...............#...#.......#............#..#...........................#..............#..........#....#...#...#..#...#....#.
|
||||
.......#..#..#.#..#......#..........................#...............#.........#...........#................#..#...#................
|
||||
...#..#...#.....#.#.......#....................................................#........#..........#.#...#......#..........#.......
|
||||
..#...#.......#..#..............#.#...#.....#...#....#............#..........##...#.........##.............#.......................
|
||||
...#.............#...#....#...#.....#.#.#..............#..........#........#........##...........#..#.#......................#.....
|
||||
.#.......#.................#...............#..........#.....................#.....#............#......##....#.....#...#....###.....
|
||||
...##...........#..........#.#........#............#..#.#........................#.....##............#...##.#.......#.##....#......
|
||||
...........#........#...........#.......#......#...#.....#............................#........#..#................#...#....##.....
|
||||
...##.##.........#.####..#............#..#.....#.......................#......#..........#.#..#.#....##........#....#.....#..#..##.
|
||||
...................................................................................................................................
|
||||
@@ -1,30 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
aoc "go.sour.is/advent-of-code"
|
||||
)
|
||||
|
||||
// var log = aoc.Log
|
||||
|
||||
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||
|
||||
type result struct {
|
||||
valuePT1 int
|
||||
valuePT2 int
|
||||
}
|
||||
|
||||
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||
|
||||
func run(scan *bufio.Scanner) (*result, error) {
|
||||
|
||||
for scan.Scan() {
|
||||
_ = scan.Text()
|
||||
|
||||
}
|
||||
|
||||
return &result{}, nil
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed example.txt
|
||||
var example []byte
|
||||
|
||||
//go:embed input.txt
|
||||
var input []byte
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(example))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 0)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
||||
|
||||
func TestSolution(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(input))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 0)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
aoc "go.sour.is/advent-of-code"
|
||||
)
|
||||
|
||||
// var log = aoc.Log
|
||||
|
||||
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||
|
||||
type result struct {
|
||||
valuePT1 int
|
||||
valuePT2 int
|
||||
}
|
||||
|
||||
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||
|
||||
func run(scan *bufio.Scanner) (*result, error) {
|
||||
|
||||
for scan.Scan() {
|
||||
_ = scan.Text()
|
||||
|
||||
}
|
||||
|
||||
return &result{}, nil
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed example.txt
|
||||
var example []byte
|
||||
|
||||
//go:embed input.txt
|
||||
var input []byte
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(example))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 0)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
||||
|
||||
func TestSolution(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(input))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 0)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module go.sour.is/advent-of-code
|
||||
|
||||
go 1.23.2
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/matryer/is v1.4.1
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"bufio"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
func main() {
|
||||
//Enter your code here. Read input from STDIN. Print output to STDOUT
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
var nodes int
|
||||
var tree *node
|
||||
var target [2]int
|
||||
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
if nodes == 0 {
|
||||
nodes, _ = strconv.Atoi(text)
|
||||
continue
|
||||
}
|
||||
|
||||
if tree == nil {
|
||||
for _, s := range strings.Fields(text) {
|
||||
v, _ := strconv.Atoi(s)
|
||||
tree = insertNode(tree, &node{value:v})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
for i, s := range strings.Fields(text) {
|
||||
v, _ := strconv.Atoi(s)
|
||||
target[i] = v
|
||||
}
|
||||
}
|
||||
if target[0]>target[1] {
|
||||
target[0], target[1] = target[1], target[0]
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, tree)
|
||||
if n := lsa(tree, target); n != nil {
|
||||
fmt.Println(n.value)
|
||||
return
|
||||
}
|
||||
fmt.Println("nil")
|
||||
}
|
||||
|
||||
type node struct{
|
||||
value int
|
||||
left *node
|
||||
right *node
|
||||
}
|
||||
func insertNode(root, n *node) *node {
|
||||
if root == nil {
|
||||
return n
|
||||
}
|
||||
if root.value > n.value {
|
||||
root.left = insertNode(root.left, n)
|
||||
return root
|
||||
}
|
||||
root.right = insertNode(root.right, n)
|
||||
return root
|
||||
}
|
||||
|
||||
func (n *node) String() string {
|
||||
if n == nil { return "nil" }
|
||||
return fmt.Sprintf("%v (%v %v)", n.value, n.left, n.right)
|
||||
}
|
||||
|
||||
func lsa(tree *node, target [2]int) *node {
|
||||
if tree == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if target[0]>tree.value {
|
||||
return lsa(tree.right, target)
|
||||
}
|
||||
|
||||
if target[1]<tree.value {
|
||||
return lsa(tree.left, target)
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
* Complete the 'countingSort' function below.
|
||||
*
|
||||
* The function is expected to return an INTEGER_ARRAY.
|
||||
* The function accepts INTEGER_ARRAY arr as parameter.
|
||||
*/
|
||||
|
||||
func countingSort(arr []int32) []int32 {
|
||||
freq := make([]int32, 100)
|
||||
for _, i := range arr {
|
||||
freq[i]++
|
||||
}
|
||||
return freq
|
||||
}
|
||||
|
||||
func main() {
|
||||
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||||
|
||||
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||||
checkError(err)
|
||||
|
||||
defer stdout.Close()
|
||||
|
||||
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||||
|
||||
nTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||
checkError(err)
|
||||
n := int32(nTemp)
|
||||
|
||||
arrTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
||||
|
||||
var arr []int32
|
||||
|
||||
for i := 0; i < int(n); i++ {
|
||||
arrItemTemp, err := strconv.ParseInt(arrTemp[i], 10, 64)
|
||||
checkError(err)
|
||||
arrItem := int32(arrItemTemp)
|
||||
arr = append(arr, arrItem)
|
||||
}
|
||||
|
||||
result := countingSort(arr)
|
||||
|
||||
for i, resultItem := range result {
|
||||
fmt.Fprintf(writer, "%d", resultItem)
|
||||
|
||||
if i != len(result) - 1 {
|
||||
fmt.Fprintf(writer, " ")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "\n")
|
||||
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func readLine(reader *bufio.Reader) string {
|
||||
str, _, err := reader.ReadLine()
|
||||
if err == io.EOF {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimRight(string(str), "\r\n")
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
* Complete the 'diagonalDifference' function below.
|
||||
*
|
||||
* The function is expected to return an INTEGER.
|
||||
* The function accepts 2D_INTEGER_ARRAY arr as parameter.
|
||||
*/
|
||||
|
||||
func diagonalDifference(arr [][]int32) int32 {
|
||||
var sum int32
|
||||
for i, row := range arr {
|
||||
sum += row[i] - row[len(row)-i-1]
|
||||
}
|
||||
if sum < 0 {
|
||||
sum *= -1
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
func main() {
|
||||
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||||
|
||||
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||||
checkError(err)
|
||||
|
||||
defer stdout.Close()
|
||||
|
||||
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||||
|
||||
nTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||
checkError(err)
|
||||
n := int32(nTemp)
|
||||
|
||||
var arr [][]int32
|
||||
for i := 0; i < int(n); i++ {
|
||||
arrRowTemp := strings.Split(strings.TrimRight(readLine(reader)," \t\r\n"), " ")
|
||||
|
||||
var arrRow []int32
|
||||
for _, arrRowItem := range arrRowTemp {
|
||||
arrItemTemp, err := strconv.ParseInt(arrRowItem, 10, 64)
|
||||
checkError(err)
|
||||
arrItem := int32(arrItemTemp)
|
||||
arrRow = append(arrRow, arrItem)
|
||||
}
|
||||
|
||||
if len(arrRow) != int(n) {
|
||||
panic("Bad input")
|
||||
}
|
||||
|
||||
arr = append(arr, arrRow)
|
||||
}
|
||||
|
||||
result := diagonalDifference(arr)
|
||||
|
||||
fmt.Fprintf(writer, "%d\n", result)
|
||||
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func readLine(reader *bufio.Reader) string {
|
||||
str, _, err := reader.ReadLine()
|
||||
if err == io.EOF {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimRight(string(str), "\r\n")
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
* Complete the 'flippingBits' function below.
|
||||
*
|
||||
* The function is expected to return a LONG_INTEGER.
|
||||
* The function accepts LONG_INTEGER n as parameter.
|
||||
*/
|
||||
|
||||
func flippingBits(n int64) int64 {
|
||||
// Write your code here
|
||||
max := int64(^uint32(0))
|
||||
return n ^ max
|
||||
}
|
||||
|
||||
func main() {
|
||||
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||||
|
||||
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||||
checkError(err)
|
||||
|
||||
defer stdout.Close()
|
||||
|
||||
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||||
|
||||
qTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||
checkError(err)
|
||||
q := int32(qTemp)
|
||||
|
||||
for qItr := 0; qItr < int(q); qItr++ {
|
||||
n, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||
checkError(err)
|
||||
|
||||
result := flippingBits(n)
|
||||
|
||||
fmt.Fprintf(writer, "%d\n", result)
|
||||
}
|
||||
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func readLine(reader *bufio.Reader) string {
|
||||
str, _, err := reader.ReadLine()
|
||||
if err == io.EOF {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimRight(string(str), "\r\n")
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
* Complete the 'lonelyinteger' function below.
|
||||
*
|
||||
* The function is expected to return an INTEGER.
|
||||
* The function accepts INTEGER_ARRAY a as parameter.
|
||||
*/
|
||||
|
||||
func lonelyinteger(a []int32) int32 {
|
||||
m := make(map[int32]int8, len(a)/2+1)
|
||||
for _, i := range a {
|
||||
m[i] = m[i]+1
|
||||
}
|
||||
for k,v := range m {
|
||||
if v == 1 {
|
||||
return k
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {
|
||||
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||||
|
||||
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
|
||||
checkError(err)
|
||||
|
||||
defer stdout.Close()
|
||||
|
||||
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
|
||||
|
||||
nTemp, err := strconv.ParseInt(strings.TrimSpace(readLine(reader)), 10, 64)
|
||||
checkError(err)
|
||||
n := int32(nTemp)
|
||||
|
||||
aTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
||||
|
||||
var a []int32
|
||||
|
||||
for i := 0; i < int(n); i++ {
|
||||
aItemTemp, err := strconv.ParseInt(aTemp[i], 10, 64)
|
||||
checkError(err)
|
||||
aItem := int32(aItemTemp)
|
||||
a = append(a, aItem)
|
||||
}
|
||||
|
||||
result := lonelyinteger(a)
|
||||
|
||||
fmt.Fprintf(writer, "%d\n", result)
|
||||
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func readLine(reader *bufio.Reader) string {
|
||||
str, _, err := reader.ReadLine()
|
||||
if err == io.EOF {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimRight(string(str), "\r\n")
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user