pin: implemented generating pins of less length than max.

This commit is contained in:
k1574 2022-05-06 21:26:28 +05:00
parent 07aae4b10b
commit 972bf91023

View file

@ -5,9 +5,12 @@ import(
"fmt" "fmt"
"strconv" "strconv"
"log" "log"
"flag"
) )
var( var(
Lflag bool
lval int
arg0 string arg0 string
delim rune = '\n' delim rune = '\n'
status int = 0 status int = 0
@ -50,18 +53,37 @@ printPins(s []rune, l int) {
func func
Run(args []string) int { Run(args []string) int {
arg0 = args[0] arg0 = args[0]
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
if len(args) < 3 { flagSet.IntVar(&lval, "l", 0,
"Add combinations with less number of chars starting with arg.")
flagSet.BoolVar(&Lflag, "L", false,
"Set less number to 1. Overrides l flag.")
flagSet.Parse(args[1:])
args = flagSet.Args()
if len(args) < 2 {
usage() usage()
} }
chrs := []rune(args[1]) chrs := []rune(args[0])
n, err := strconv.Atoi(args[2]) n, err := strconv.Atoi(args[1])
if err!=nil { if err!=nil {
log.Fatal(err) log.Fatal(err)
} }
printPins(chrs, n) if Lflag {
lval = 1
}
if lval != 0 {
if lval > n {
usage()
}
for i := lval ; i<=n ; i++ {
printPins(chrs, i)
}
} else {
printPins(chrs, n)
}
return status return status
} }