Initial import

[?]
Dec 30, 2020, 12:18 PM
NJFOEVJ3LLRZY42V3Z4L7BIOSAHIDP4GOEHGZ4UDAAIBJRZYCDTAC

Dependencies

  • [2] 44BSZW7B codingame.com: solve bank-robbers
  • [3] KGSQ3OPP Add yaml-unmarshal examples
  • [4] 2DRAL6A2 Refactoring evaluate_test
  • [5] R6MPEEL2 Refactoring minimax tests
  • [6] HSJSKGY7 Refactoring evaluate functions
  • [7] UWVAMBIJ Fix couple of tests, add more
  • [8] G5KXCVIL tictactoe: initial import
  • [9] ZAZCOSBX Enhance test readability by renaming couple variables
  • [10] TYELLGSA Rename checkDiag to checkDiagLR and add checkDiagRL. Add more tests

Change contents

  • replacement in snippets/tictactoe/minimax_test.go at line 8
    [6.437][6.437:475]()
    "github.com/stretchr/testify/assert"
    [6.437]
    [6.475]
    "github.com/matryer/is"
  • edit in snippets/tictactoe/minimax_test.go at line 12
    [6.511]
    [6.511]
    is := is.NewRelaxed(t)
  • replacement in snippets/tictactoe/minimax_test.go at line 26
    [6.922][5.38:125]()
    assert.Equal(t, tc.expected, tictactoe.Minimax(0, 0, true, tc.scores, int(height)))
    [6.922]
    [6.999]
    is.Equal(tc.expected, tictactoe.Minimax(0, 0, true, tc.scores, int(height)))
  • replacement in snippets/tictactoe/go.mod at line 6
    [3.866][3.866:902]()
    github.com/stretchr/testify v1.6.1
    [3.866]
    [3.902]
    github.com/matryer/is v1.4.0
  • replacement in snippets/tictactoe/evaluate_test.go at line 7
    [6.2108][6.2108:2146]()
    "github.com/stretchr/testify/assert"
    [6.2108]
    [6.2146]
    "github.com/matryer/is"
  • edit in snippets/tictactoe/evaluate_test.go at line 11
    [6.2183]
    [6.2183]
    is := is.NewRelaxed(t)
  • replacement in snippets/tictactoe/evaluate_test.go at line 50
    [6.2729][4.1268:1321]()
    assert.Equal(t, tc.expected, tc.board.Evaluate())
    [6.2729]
    [6.2781]
    is.Equal(tc.expected, tc.board.Evaluate())
  • file addition: next-growing-number (dxwrx-rx-r)
    [2.16]
  • file addition: ngn_test.go (-xw-x--x--)
    [0.283]
    package ngn_test
    import (
    "ngn"
    "testing"
    "github.com/matryer/is"
    )
    func TestGrowing(t *testing.T) {
    var cases = []struct {
    input string
    expected string
    }{
    {"19", "22"},
    {"99", "111"},
    {"2533", "2555"},
    {"123456879", "123456888"},
    {"11123159995399999", "11123333333333333"},
    {"123456788", "123456789"},
    {"1234999", "1235555"},
    }
    for _, tc := range cases {
    is := is.New(t)
    t.Run("Growing"+tc.input, func(t *testing.T) {
    is.Equal(tc.expected, ngn.Growing(tc.input, ngn.Tipping(tc.input)))
    })
    }
    }
  • file addition: ngn.go (-xw-x--x--)
    [0.283]
    package ngn
    import (
    "strconv"
    )
    func Tipping(n string) (tipping int) {
    for i := 0; i < len(n)-1; i++ {
    if n[i] > n[i+1] {
    return i
    }
    }
    return tipping
    }
    func Growing(n string, tipping int) (ret string) {
    //log.Printf("num: %s, tipping: %d", n, tipping)
    if tipping != 0 {
    return tipgrow(n, tipping)
    }
    // there is no tipping poing, input is already a growing number
    for i := len(n) - 1; i >= 0; i-- {
    curr := n[i]
    //log.Printf("curr: %c\t%v, i: %d\n", curr, curr, i)
    if curr != 57 && i == len(n)-1 {
    // its not 9 and it is the last so we do not have to bump the place value
    curr++
    ret = n[:len(n)-1] + string(curr)
    return ret
    }
    if curr == 57 && i == 0 {
    // it is all 9, eg: 99
    // we have to prepend 1 to it
    n = strconv.Itoa(1) + n
    return tipgrow(n, 0)
    }
    if curr != 57 {
    curr++
    //log.Printf("pre: %s, curr: %s, post: %s", n[:i], string(curr), n[i+1:])
    n = n[:i] + string(curr) + n[i+1:]
    return tipgrow(n, i)
    }
    }
    return ret
    }
    func tipgrow(n string, tipping int) (ret string) {
    for i := 0; i < len(n); i++ {
    if i < tipping {
    ret += string(n[i])
    } else {
    new := n[tipping]
    ret += string(new)
    }
    }
    return ret
    }