How to use NOutOf method of prog Package

Best Syzkaller code snippet using prog.NOutOf

rand.go

Source:rand.go Github

copy

Full Screen

1// Copyright 2015/2016 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package prog4import (5 "bytes"6 "fmt"7 "math"8 "math/rand"9 "path/filepath"10 "strings"11 "github.com/google/syzkaller/pkg/ifuzz"12 _ "github.com/google/syzkaller/pkg/ifuzz/generated" // pull in generated instruction descriptions13)14type randGen struct {15 *rand.Rand16 target *Target17 inCreateResource bool18 recDepth map[string]int19}20func newRand(target *Target, rs rand.Source) *randGen {21 return &randGen{22 Rand: rand.New(rs),23 target: target,24 recDepth: make(map[string]int),25 }26}27func (r *randGen) rand(n int) uint64 {28 return uint64(r.Intn(n))29}30func (r *randGen) randRange(begin, end uint64) uint64 {31 return begin + uint64(r.Intn(int(end-begin+1)))32}33func (r *randGen) bin() bool {34 return r.Intn(2) == 035}36func (r *randGen) oneOf(n int) bool {37 return r.Intn(n) == 038}39func (r *randGen) rand64() uint64 {40 v := uint64(r.Int63())41 if r.bin() {42 v |= 1 << 6343 }44 return v45}46// Some potentially interesting integers.47var specialInts = []uint64{48 0, 1, 31, 32, 63, 64, 127, 128,49 129, 255, 256, 257, 511, 512,50 1023, 1024, 1025, 2047, 2048, 4095, 4096,51 (1 << 15) - 1, (1 << 15), (1 << 15) + 1,52 (1 << 16) - 1, (1 << 16), (1 << 16) + 1,53 (1 << 31) - 1, (1 << 31), (1 << 31) + 1,54 (1 << 32) - 1, (1 << 32), (1 << 32) + 1,55}56func (r *randGen) randInt() uint64 {57 v := r.rand64()58 switch {59 case r.nOutOf(100, 182):60 v %= 1061 case r.nOutOf(50, 82):62 v = specialInts[r.Intn(len(specialInts))]63 case r.nOutOf(10, 32):64 v %= 25665 case r.nOutOf(10, 22):66 v %= 4 << 1067 case r.nOutOf(10, 12):68 v %= 64 << 1069 default:70 v %= 1 << 3171 }72 switch {73 case r.nOutOf(100, 107):74 case r.nOutOf(5, 7):75 v = uint64(-int64(v))76 default:77 v <<= uint(r.Intn(63))78 }79 return v80}81func (r *randGen) randRangeInt(begin uint64, end uint64) uint64 {82 if r.oneOf(100) {83 return r.randInt()84 }85 return begin + (r.Uint64() % (end - begin + 1))86}87// biasedRand returns a random int in range [0..n),88// probability of n-1 is k times higher than probability of 0.89func (r *randGen) biasedRand(n, k int) int {90 nf, kf := float64(n), float64(k)91 rf := nf * (kf/2 + 1) * r.Float64()92 bf := (-1 + math.Sqrt(1+2*kf*rf/nf)) * nf / kf93 return int(bf)94}95func (r *randGen) randArrayLen() uint64 {96 const maxLen = 1097 // biasedRand produces: 10, 9, ..., 1, 0,98 // we want: 1, 2, ..., 9, 10, 099 return uint64(maxLen-r.biasedRand(maxLen+1, 10)+1) % (maxLen + 1)100}101func (r *randGen) randBufLen() (n uint64) {102 switch {103 case r.nOutOf(50, 56):104 n = r.rand(256)105 case r.nOutOf(5, 6):106 n = 4 << 10107 }108 return109}110func (r *randGen) randPageCount() (n uint64) {111 switch {112 case r.nOutOf(100, 106):113 n = r.rand(4) + 1114 case r.nOutOf(5, 6):115 n = r.rand(20) + 1116 default:117 n = (r.rand(3) + 1) * 512118 }119 return120}121func (r *randGen) flags(vv []uint64) (v uint64) {122 switch {123 case r.nOutOf(90, 111):124 for stop := false; !stop; stop = r.bin() {125 v |= vv[r.rand(len(vv))]126 }127 case r.nOutOf(10, 21):128 v = vv[r.rand(len(vv))]129 case r.nOutOf(10, 11):130 v = 0131 default:132 v = r.rand64()133 }134 return135}136func (r *randGen) filename(s *state, typ *BufferType) string {137 fn := r.filenameImpl(s)138 if len(fn) != 0 && fn[len(fn)-1] == 0 {139 panic(fmt.Sprintf("zero-terminated filename: %q", fn))140 }141 if !typ.Varlen() {142 size := typ.Size()143 if uint64(len(fn)) < size {144 fn += string(make([]byte, size-uint64(len(fn))))145 }146 fn = fn[:size]147 } else if !typ.NoZ {148 fn += "\x00"149 }150 return fn151}152var specialFiles = []string{"", "."}153func (r *randGen) filenameImpl(s *state) string {154 if r.oneOf(100) {155 return specialFiles[r.Intn(len(specialFiles))]156 }157 if len(s.files) == 0 || r.oneOf(10) {158 // Generate a new name.159 dir := "."160 if r.oneOf(2) && len(s.files) != 0 {161 files := make([]string, 0, len(s.files))162 for f := range s.files {163 files = append(files, f)164 }165 dir = files[r.Intn(len(files))]166 if len(dir) > 0 && dir[len(dir)-1] == 0 {167 dir = dir[:len(dir)-1]168 }169 if r.oneOf(10) && filepath.Clean(dir)[0] != '.' {170 dir += "/.."171 }172 }173 for i := 0; ; i++ {174 f := fmt.Sprintf("%v/file%v", dir, i)175 if !s.files[f] {176 return f177 }178 }179 }180 files := make([]string, 0, len(s.files))181 for f := range s.files {182 files = append(files, f)183 }184 return files[r.Intn(len(files))]185}186func (r *randGen) randString(s *state, t *BufferType) []byte {187 if len(t.Values) != 0 {188 return []byte(t.Values[r.Intn(len(t.Values))])189 }190 if len(s.strings) != 0 && r.bin() {191 // Return an existing string.192 // TODO(dvyukov): make s.strings indexed by string SubKind.193 strings := make([]string, 0, len(s.strings))194 for s := range s.strings {195 strings = append(strings, s)196 }197 return []byte(strings[r.Intn(len(strings))])198 }199 punct := []byte{'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '\\',200 '/', ':', '.', ',', '-', '\'', '[', ']', '{', '}'}201 buf := new(bytes.Buffer)202 for r.nOutOf(3, 4) {203 switch {204 case r.nOutOf(10, 21):205 dict := r.target.StringDictionary206 if len(dict) != 0 {207 buf.WriteString(dict[r.Intn(len(dict))])208 }209 case r.nOutOf(10, 11):210 buf.Write([]byte{punct[r.Intn(len(punct))]})211 default:212 buf.Write([]byte{byte(r.Intn(256))})213 }214 }215 if r.oneOf(100) == t.NoZ {216 buf.Write([]byte{0})217 }218 return buf.Bytes()219}220func (r *randGen) allocAddr(s *state, typ Type, size uint64, data Arg) *PointerArg {221 return MakePointerArg(typ, s.ma.alloc(r, size), data)222}223func (r *randGen) allocVMA(s *state, typ Type, numPages uint64) *PointerArg {224 page := s.va.alloc(r, numPages)225 return MakeVmaPointerArg(typ, page*r.target.PageSize, numPages*r.target.PageSize)226}227func (r *randGen) createResource(s *state, res *ResourceType) (arg Arg, calls []*Call) {228 if r.inCreateResource {229 special := res.SpecialValues()230 return MakeResultArg(res, nil, special[r.Intn(len(special))]), nil231 }232 r.inCreateResource = true233 defer func() { r.inCreateResource = false }()234 kind := res.Desc.Name235 if r.oneOf(1000) {236 // Spoof resource subkind.237 var all []string238 for kind1 := range r.target.resourceMap {239 if r.target.isCompatibleResource(res.Desc.Kind[0], kind1) {240 all = append(all, kind1)241 }242 }243 kind = all[r.Intn(len(all))]244 }245 // Find calls that produce the necessary resources.246 metas0 := r.target.resourceCtors[kind]247 // TODO: reduce priority of less specialized ctors.248 var metas []*Syscall249 for _, meta := range metas0 {250 if s.ct == nil || s.ct.run[meta.ID] == nil {251 continue252 }253 metas = append(metas, meta)254 }255 if len(metas) == 0 {256 return res.makeDefaultArg(), nil257 }258 // Now we have a set of candidate calls that can create the necessary resource.259 for i := 0; i < 1e3; i++ {260 // Generate one of them.261 meta := metas[r.Intn(len(metas))]262 calls := r.generateParticularCall(s, meta)263 s1 := newState(r.target, s.ct)264 s1.analyze(calls[len(calls)-1])265 // Now see if we have what we want.266 var allres []*ResultArg267 for kind1, res1 := range s1.resources {268 if r.target.isCompatibleResource(kind, kind1) {269 allres = append(allres, res1...)270 }271 }272 if len(allres) != 0 {273 // Bingo!274 arg := MakeResultArg(res, allres[r.Intn(len(allres))], 0)275 return arg, calls276 }277 // Discard unsuccessful calls.278 // Note: s.ma/va have already noted allocations of the new objects279 // in discarded syscalls, ideally we should recreate state280 // by analyzing the program again.281 for _, c := range calls {282 ForeachArg(c, func(arg Arg, _ *ArgCtx) {283 if a, ok := arg.(*ResultArg); ok && a.Res != nil {284 delete(a.Res.uses, a)285 }286 })287 }288 }289 // Generally we can loop several times, e.g. when we choose a call that returns290 // the resource in an array, but then generateArg generated that array of zero length.291 // But we must succeed eventually.292 var ctors []string293 for _, meta := range metas {294 ctors = append(ctors, meta.Name)295 }296 panic(fmt.Sprintf("failed to create a resource %v with %v",297 res.Desc.Kind[0], strings.Join(ctors, ", ")))298}299func (r *randGen) generateText(kind TextKind) []byte {300 switch kind {301 case TextArm64:302 // Just a stub, need something better.303 text := make([]byte, 50)304 for i := range text {305 text[i] = byte(r.Intn(256))306 }307 return text308 default:309 cfg := createIfuzzConfig(kind)310 return ifuzz.Generate(cfg, r.Rand)311 }312}313func (r *randGen) mutateText(kind TextKind, text []byte) []byte {314 switch kind {315 case TextArm64:316 return mutateData(r, text, 40, 60)317 default:318 cfg := createIfuzzConfig(kind)319 return ifuzz.Mutate(cfg, r.Rand, text)320 }321}322func createIfuzzConfig(kind TextKind) *ifuzz.Config {323 cfg := &ifuzz.Config{324 Len: 10,325 Priv: true,326 Exec: true,327 MemRegions: []ifuzz.MemRegion{328 {Start: 0 << 12, Size: 1 << 12},329 {Start: 1 << 12, Size: 1 << 12},330 {Start: 2 << 12, Size: 1 << 12},331 {Start: 3 << 12, Size: 1 << 12},332 {Start: 4 << 12, Size: 1 << 12},333 {Start: 5 << 12, Size: 1 << 12},334 {Start: 6 << 12, Size: 1 << 12},335 {Start: 7 << 12, Size: 1 << 12},336 {Start: 8 << 12, Size: 1 << 12},337 {Start: 9 << 12, Size: 1 << 12},338 {Start: 0xfec00000, Size: 0x100}, // ioapic339 },340 }341 switch kind {342 case TextX86Real:343 cfg.Mode = ifuzz.ModeReal16344 case TextX86bit16:345 cfg.Mode = ifuzz.ModeProt16346 case TextX86bit32:347 cfg.Mode = ifuzz.ModeProt32348 case TextX86bit64:349 cfg.Mode = ifuzz.ModeLong64350 }351 return cfg352}353// nOutOf returns true n out of outOf times.354func (r *randGen) nOutOf(n, outOf int) bool {355 if n <= 0 || n >= outOf {356 panic("bad probability")357 }358 v := r.Intn(outOf)359 return v < n360}361func (r *randGen) generateCall(s *state, p *Prog) []*Call {362 idx := 0363 if s.ct == nil {364 idx = r.Intn(len(r.target.Syscalls))365 } else {366 call := -1367 if len(p.Calls) != 0 {368 call = p.Calls[r.Intn(len(p.Calls))].Meta.ID369 }370 idx = s.ct.Choose(r.Rand, call)371 }372 meta := r.target.Syscalls[idx]373 return r.generateParticularCall(s, meta)374}375func (r *randGen) generateParticularCall(s *state, meta *Syscall) (calls []*Call) {376 c := &Call{377 Meta: meta,378 Ret: MakeReturnArg(meta.Ret),379 }380 c.Args, calls = r.generateArgs(s, meta.Args)381 r.target.assignSizesCall(c)382 calls = append(calls, c)383 for _, c1 := range calls {384 r.target.SanitizeCall(c1)385 }386 return calls387}388// GenerateAllSyzProg generates a program that contains all pseudo syz_ calls for testing.389func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog {390 p := &Prog{391 Target: target,392 }393 r := newRand(target, rs)394 s := newState(target, nil)395 handled := make(map[string]bool)396 for _, meta := range target.Syscalls {397 if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] {398 continue399 }400 handled[meta.CallName] = true401 calls := r.generateParticularCall(s, meta)402 for _, c := range calls {403 s.analyze(c)404 p.Calls = append(p.Calls, c)405 }406 }407 if err := p.validate(); err != nil {408 panic(err)409 }410 return p411}412// GenerateSimpleProg generates the simplest non-empty program for testing413// (e.g. containing a single mmap).414func (target *Target) GenerateSimpleProg() *Prog {415 return &Prog{416 Target: target,417 Calls: []*Call{target.MakeMmap(0, target.PageSize)},418 }419}420func (target *Target) GenerateUberMmapProg() *Prog {421 return &Prog{422 Target: target,423 Calls: []*Call{target.MakeMmap(0, target.NumPages*target.PageSize)},424 }425}426func (r *randGen) generateArgs(s *state, types []Type) ([]Arg, []*Call) {427 var calls []*Call428 args := make([]Arg, len(types))429 // Generate all args. Size args have the default value 0 for now.430 for i, typ := range types {431 arg, calls1 := r.generateArg(s, typ)432 if arg == nil {433 panic(fmt.Sprintf("generated arg is nil for type '%v', types: %+v", typ.Name(), types))434 }435 args[i] = arg436 calls = append(calls, calls1...)437 }438 return args, calls439}440func (r *randGen) generateArg(s *state, typ Type) (arg Arg, calls []*Call) {441 return r.generateArgImpl(s, typ, false)442}443func (r *randGen) generateArgImpl(s *state, typ Type, ignoreSpecial bool) (arg Arg, calls []*Call) {444 if typ.Dir() == DirOut {445 // No need to generate something interesting for output scalar arguments.446 // But we still need to generate the argument itself so that it can be referenced447 // in subsequent calls. For the same reason we do generate pointer/array/struct448 // output arguments (their elements can be referenced in subsequent calls).449 switch typ.(type) {450 case *IntType, *FlagsType, *ConstType, *ProcType,451 *VmaType, *ResourceType:452 return typ.makeDefaultArg(), nil453 }454 }455 if typ.Optional() && r.oneOf(5) {456 if res, ok := typ.(*ResourceType); ok {457 v := res.Desc.Values[r.Intn(len(res.Desc.Values))]458 return MakeResultArg(typ, nil, v), nil459 }460 return typ.makeDefaultArg(), nil461 }462 // Allow infinite recursion for optional pointers.463 if pt, ok := typ.(*PtrType); ok && typ.Optional() {464 switch pt.Type.(type) {465 case *StructType, *ArrayType, *UnionType:466 name := pt.Type.Name()467 r.recDepth[name]++468 defer func() {469 r.recDepth[name]--470 if r.recDepth[name] == 0 {471 delete(r.recDepth, name)472 }473 }()474 if r.recDepth[name] >= 3 {475 return MakeNullPointerArg(typ), nil476 }477 }478 }479 if !ignoreSpecial && typ.Dir() != DirOut {480 switch typ.(type) {481 case *StructType, *UnionType:482 if gen := r.target.SpecialTypes[typ.Name()]; gen != nil {483 return gen(&Gen{r, s}, typ, nil)484 }485 }486 }487 return typ.generate(r, s)488}489func (a *ResourceType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {490 switch {491 case r.nOutOf(1000, 1011):492 // Get an existing resource.493 var allres []*ResultArg494 for name1, res1 := range s.resources {495 if r.target.isCompatibleResource(a.Desc.Name, name1) ||496 r.oneOf(20) && r.target.isCompatibleResource(a.Desc.Kind[0], name1) {497 allres = append(allres, res1...)498 }499 }500 if len(allres) != 0 {501 arg = MakeResultArg(a, allres[r.Intn(len(allres))], 0)502 } else {503 arg, calls = r.createResource(s, a)504 }505 case r.nOutOf(10, 11):506 // Create a new resource.507 arg, calls = r.createResource(s, a)508 default:509 special := a.SpecialValues()510 arg = MakeResultArg(a, nil, special[r.Intn(len(special))])511 }512 return arg, calls513}514func (a *BufferType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {515 switch a.Kind {516 case BufferBlobRand, BufferBlobRange:517 sz := r.randBufLen()518 if a.Kind == BufferBlobRange {519 sz = r.randRange(a.RangeBegin, a.RangeEnd)520 }521 if a.Dir() == DirOut {522 return MakeOutDataArg(a, sz), nil523 }524 data := make([]byte, sz)525 for i := range data {526 data[i] = byte(r.Intn(256))527 }528 return MakeDataArg(a, data), nil529 case BufferString:530 data := r.randString(s, a)531 if a.Dir() == DirOut {532 return MakeOutDataArg(a, uint64(len(data))), nil533 }534 return MakeDataArg(a, data), nil535 case BufferFilename:536 if a.Dir() == DirOut {537 var sz uint64538 switch {539 case !a.Varlen():540 sz = a.Size()541 case r.nOutOf(1, 3):542 sz = r.rand(100)543 case r.nOutOf(1, 2):544 sz = 108 // UNIX_PATH_MAX545 default:546 sz = 4096 // PATH_MAX547 }548 return MakeOutDataArg(a, sz), nil549 }550 return MakeDataArg(a, []byte(r.filename(s, a))), nil551 case BufferText:552 if a.Dir() == DirOut {553 return MakeOutDataArg(a, uint64(r.Intn(100))), nil554 }555 return MakeDataArg(a, r.generateText(a.Text)), nil556 default:557 panic("unknown buffer kind")558 }559}560func (a *VmaType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {561 npages := r.randPageCount()562 if a.RangeBegin != 0 || a.RangeEnd != 0 {563 npages = a.RangeBegin + uint64(r.Intn(int(a.RangeEnd-a.RangeBegin+1)))564 }565 return r.allocVMA(s, a, npages), nil566}567func (a *FlagsType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {568 return MakeConstArg(a, r.flags(a.Vals)), nil569}570func (a *ConstType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {571 return MakeConstArg(a, a.Val), nil572}573func (a *IntType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {574 v := r.randInt()575 switch a.Kind {576 case IntFileoff:577 switch {578 case r.nOutOf(90, 101):579 v = 0580 case r.nOutOf(10, 11):581 v = r.rand(100)582 default:583 v = r.randInt()584 }585 case IntRange:586 v = r.randRangeInt(a.RangeBegin, a.RangeEnd)587 }588 return MakeConstArg(a, v), nil589}590func (a *ProcType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {591 return MakeConstArg(a, r.rand(int(a.ValuesPerProc))), nil592}593func (a *ArrayType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {594 var count uint64595 switch a.Kind {596 case ArrayRandLen:597 count = r.randArrayLen()598 case ArrayRangeLen:599 count = r.randRange(a.RangeBegin, a.RangeEnd)600 }601 var inner []Arg602 for i := uint64(0); i < count; i++ {603 arg1, calls1 := r.generateArg(s, a.Type)604 inner = append(inner, arg1)605 calls = append(calls, calls1...)606 }607 return MakeGroupArg(a, inner), calls608}609func (a *StructType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {610 args, calls := r.generateArgs(s, a.Fields)611 group := MakeGroupArg(a, args)612 return group, calls613}614func (a *UnionType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {615 optType := a.Fields[r.Intn(len(a.Fields))]616 opt, calls := r.generateArg(s, optType)617 return MakeUnionArg(a, opt), calls618}619func (a *PtrType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {620 inner, calls := r.generateArg(s, a.Type)621 arg = r.allocAddr(s, a, inner.Size(), inner)622 return arg, calls623}624func (a *LenType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {625 // Updated later in assignSizesCall.626 return MakeConstArg(a, 0), nil627}628func (a *CsumType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {629 // Filled at runtime by executor.630 return MakeConstArg(a, 0), nil631}...

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(p.NOutOf(2, 5))4}5type Prog struct{}6func (p Prog) NOutOf

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/AllenDowney/CompProbSol/go/prog"3func main() {4 fmt.Println(prog.NOutOf(6, 3, 1))5 fmt.Println(prog.NOutOf(6, 3, 2))6 fmt.Println(prog.NOutOf(6, 3, 3))7 fmt.Println(prog.NOutOf(6, 3, 4))8 fmt.Println(prog.NOutOf(6, 3, 5))9 fmt.Println(prog.NOutOf(6, 3, 6))10 fmt.Println(prog.NOutOf(6, 3, 7))11 fmt.Println(prog.NOutOf(6, 3, 8))12}13import "math"14func NOutOf(n, k, j int) float32 {15 for i := 0; i <= j; i++ {16 prob += float32(math.Pow(float64(k)/float64(n), float64(i))) *17 float32(math.Pow(float64(1-k)/float64(n), float64(j-i))) *18 float32(math.Comb(float64(j), float64(i)))19 }20}

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(gol.NOutOf(2, 10, 5))4}5import (6func main() {7 fmt.Println(gol.NOutOf(2, 10, 5))8}9import (10func main() {11 fmt.Println(gol.NOutOf(2, 10, 5))12}13import (14func main() {15 fmt.Println(gol.NOutOf(2, 10, 5))16}17import (18func main() {19 fmt.Println(gol.NOutOf(2, 10, 5))20}21import (22func main() {23 fmt.Println(gol.NOutOf(2, 10, 5))24}25import (26func main() {27 fmt.Println(gol.NOutOf(2, 10, 5))28}29import (30func main() {31 fmt.Println(gol.NOutOf(2, 10, 5))32}33import (

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.NOutOf(5, 2))4}5func NOutOf(n int, k int) int {6 if n < 1 {7 }8 if k == 1 {9 }10 if k == n {11 }12 return NOutOf(n-1, k) + NOutOf(n-1, k-1)13}14import (15func main() {16 fmt.Println(prog.NOutOf(5, 2))17}18func NOutOf(n int, k int) int {19 if n < 1 {20 }21 if k == 1 {22 }23 if k == n {24 }25 return NOutOf(n-1, k) + NOutOf(n-1, k-1)26}27import (28func main() {29 fmt.Println(prog.NOutOf(5, 2))30}31func NOutOf(n int, k int) int {32 if n < 1 {33 }34 if k == 1 {35 }36 if k == n {37 }38 return NOutOf(n-1, k) + NOutOf(n-1, k-1)39}40import "fmt"41func main() {42 fmt.Println(nOutOf(5, 2))43}44func nOutOf(n, k int) int {45 if n < 1 {46 }47 if k == 1 {48 }49 if k == n {50 }51 return nOutOf(n-1, k)

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(gol.NOutOf(5, 2))4}5import (6func main() {7 fmt.Println(gol.NOutOf(5, 2))8}9import (10func main() {11 fmt.Println(gol.NOutOf(5, 2))12}13import (14func main() {15 fmt.Println(gol.NOutOf(5, 2))16}17import (18func main() {19 fmt.Println(gol.NOutOf(5, 2))20}21import (22func main() {23 fmt.Println(gol.NOutOf(5,

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p = prog.NewProg(N)4 p.Add(1)5 p.Add(2)6 p.Add(3)7 p.Add(4)8 p.Add(5)9 p.Add(6)10 p.Add(7)11 fmt.Println(p.NOutOf(3))12}

Full Screen

Full Screen

NOutOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := prog.Prog{}4 fmt.Println(p.NOutOf(10, 3))5}6import (7func main() {8 p := prog.Prog{}9 fmt.Println(p.NOutOf(10, 3))10}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful