├── Dockerfile ├── README.md ├── entrypoint.sh ├── go.mod ├── go.sum ├── lib ├── base │ └── base.go ├── challenge │ └── challenge.go ├── chars │ └── chars.go ├── is │ └── is.go └── random │ └── random.go ├── raid-testing.md ├── solutions ├── abort.go ├── activebits.go ├── addfront.go ├── addifpositive.go ├── addprimesum │ └── main.go ├── alphacount.go ├── alphamirror │ └── main.go ├── alphaposition.go ├── any.go ├── appendrange.go ├── argrot1 │ └── main.go ├── argrotn │ └── main.go ├── argsort │ └── main.go ├── atoi.go ├── atoibase.go ├── balancedstring │ └── main.go ├── basicatoi.go ├── basicatoi2.go ├── basicjoin.go ├── betweenus.go ├── bezero.go ├── binarryaddition.go ├── binarycheck.go ├── boolean │ └── main.go ├── brackets │ └── main.go ├── brainfuck │ └── main.go ├── btree.go ├── buzzinga.go ├── byebyefirst.go ├── cameltosnakecase.go ├── canjump.go ├── canyoucount │ └── main.go ├── capitalize.go ├── cat │ └── main.go ├── challenge.go ├── checknumber.go ├── chunk.go ├── cleanstr │ └── main.go ├── collatzcountdown.go ├── comcheck │ └── main.go ├── compare.go ├── concat.go ├── concat2args │ └── main.go ├── concatalternate.go ├── concatenate │ └── main.go ├── concatparams.go ├── concatslice.go ├── convertbase.go ├── count-character.go ├── countalpha.go ├── countdown │ └── main.go ├── countif.go ├── countnegative.go ├── countstars.go ├── dealapackofcards.go ├── delete.go ├── descendappendrange.go ├── descendcomb.go ├── digitlen.go ├── displaya │ └── main.go ├── displayalpham │ └── main.go ├── displayalrevm │ └── main.go ├── displayfile │ └── main.go ├── displayfirstparam │ └── main.go ├── displaylastparam │ └── main.go ├── displayp │ └── main.go ├── displays │ └── main.go ├── displayz │ └── main.go ├── divisors.go ├── doop │ └── main.go ├── eightqueens.go ├── evenlength.go ├── expandstr │ └── main.go ├── fibonacci.go ├── fifthandskip.go ├── findmissingnumber.go ├── findnextprime.go ├── findpairs │ └── main.go ├── findprevprime.go ├── firstrune.go ├── firstword.go ├── fishandchips.go ├── fixthemain │ └── main.go ├── flags │ └── main.go ├── foldint.go ├── fooddeliverytime.go ├── foreach.go ├── fprime │ └── main.go ├── fromto.go ├── frontback │ └── main.go ├── gcd.go ├── getalpha │ └── main.go ├── getarea │ └── getarea.go ├── getascii │ └── main.go ├── grouping │ └── main.go ├── halfslice.go ├── hashcode.go ├── hello │ └── main.go ├── hiddenp │ └── main.go ├── index.go ├── inter │ └── main.go ├── isalpha.go ├── iscapitalized.go ├── islower.go ├── ismultiple.go ├── isnegative.go ├── isnumeric.go ├── ispowerof2 │ └── main.go ├── isprime.go ├── isprintable.go ├── issamestring.go ├── issorted.go ├── issquare.go ├── isupper.go ├── iterativefactorial.go ├── iterativepower.go ├── itoa.go ├── itoabase.go ├── join.go ├── jumpover.go ├── lastrune.go ├── lastword.go ├── lcm.go ├── leapyear.go ├── listat.go ├── listclear.go ├── listfind.go ├── listforeach.go ├── listforeachif.go ├── listlast.go ├── listmerge.go ├── listpushback.go ├── listpushfront.go ├── listremoveif.go ├── listreverse.go ├── listsize.go ├── listsort.go ├── loafofbread.go ├── makerange.go ├── map.go ├── max.go ├── maxwordcountn.go ├── multorsum.go ├── nbrconvertalpha │ └── main.go ├── notdecimal.go ├── nrune.go ├── numofdigits.go ├── oddlength.go ├── only1 │ └── main.go ├── onlya │ └── main.go ├── onlyb │ └── main.go ├── onlyf │ └── main.go ├── onlyz │ └── main.go ├── options │ └── main.go ├── paramcount │ └── main.go ├── paramrange │ └── main.go ├── piglatin │ └── main.go ├── pilot │ └── main.go ├── pingpong │ └── main.go ├── podiumposition.go ├── point │ └── main.go ├── popint.go ├── printalphabet │ └── main.go ├── printalphabetalt │ └── main.go ├── printalphabetalt2 │ └── main.go ├── printalphabetg │ └── main.go ├── printalt │ └── main.go ├── printalt2 │ └── main.go ├── printaltu │ └── main.go ├── printaltu2 │ └── main.go ├── printascii │ └── main.go ├── printbits │ └── main.go ├── printcomb.go ├── printcomb2.go ├── printcombn.go ├── printdigits │ └── main.go ├── printevenarguments │ └── main.go ├── printhex │ └── main.go ├── printif.go ├── printifnot.go ├── printmemory.go ├── printmiddle │ └── main.go ├── printnbr.go ├── printnbrbase.go ├── printnbrinorder.go ├── printparams │ └── main.go ├── printrange.go ├── printrevcomb │ └── main.go ├── printreversealphabet │ └── main.go ├── printreversealphabetalt │ └── main.go ├── printreversealphabetalt2 │ └── main.go ├── printreversealphabetg │ └── main.go ├── printrot │ └── main.go ├── printstr.go ├── printwordstables.go ├── quad.go ├── quadchecker │ └── main.go ├── quarterofayear.go ├── range │ └── main.go ├── rectangle │ └── main.go ├── rectperimeter.go ├── recursivefactorial.go ├── recursivepower.go ├── reduceint.go ├── removeduplicate.go ├── removeodd.go ├── repeatalpha.go ├── replaceeven │ └── main.go ├── retainfirsthalf.go ├── returna │ └── main.go ├── revargs │ └── main.go ├── revconcatalternate.go ├── reversemenuindex.go ├── reverserange │ └── main.go ├── reversesecondhalf.go ├── reversestrcap │ └── main.go ├── reversestrings.go ├── revparams │ └── main.go ├── revwstr │ └── main.go ├── rockandroll.go ├── romannumbers │ └── main.go ├── rostring │ └── main.go ├── rot13 │ └── main.go ├── rot14.go ├── rotatevowels │ └── main.go ├── rpncalc │ └── main.go ├── samecase │ └── main.go ├── saveandmiss.go ├── searchreplace │ └── main.go ├── secondhalf.go ├── setspace.go ├── shoppinglistsort.go ├── shoppingsummarycounter.go ├── slice.go ├── sliceadd.go ├── sliceremove.go ├── sortedlistmerge.go ├── sortlistinsert.go ├── sortparams │ └── main.go ├── split.go ├── splitwhitespaces.go ├── sqrt.go ├── squareroot.go ├── stringtobool.go ├── stringtointslice.go ├── strisnegative.go ├── strlen.go ├── strrev.go ├── sudoku │ └── main.go ├── sum.go ├── sumarray.go ├── sumascii │ └── main.go ├── sumthemall │ └── main.go ├── swapargs │ └── main.go ├── swapfirst.go ├── swaplast.go ├── switchcase │ └── main.go ├── tabmult │ └── main.go ├── tetrisoptimizer │ ├── board.go │ ├── main.go │ ├── samples │ │ ├── bad00.txt │ │ ├── bad01.txt │ │ ├── bad02.txt │ │ ├── bad03.txt │ │ ├── bad04.txt │ │ ├── badFormat.txt │ │ ├── good_01-1-2-0.00.txt │ │ ├── good_02-1-4-0.00.txt │ │ ├── good_03-2-4-0.00.txt │ │ ├── good_04-6-6-0.00.txt │ │ ├── good_05-21-10-0.00.txt │ │ ├── good_06-22-10-0.00.txt │ │ ├── good_07-26-11-0.00.txt │ │ ├── good_08-24-10-0.03.txt │ │ ├── good_09-11-7-0.07.txt │ │ ├── good_10-12-7-0.52.txt │ │ ├── good_11-12-8-0.83.txt │ │ ├── good_12-19-9-3.40.txt │ │ ├── good_13-23-10-4.72.txt │ │ ├── good_14-15-8-7.34.txt │ │ └── good_15-26-11-72.22.txt │ ├── solver.go │ ├── tetrimino.go │ └── validation.go ├── thirdtimeisacharm.go ├── tolower.go ├── toupper.go ├── trimatoi.go ├── twosum.go ├── union │ └── main.go ├── unmatch.go ├── unzipstring.go ├── vowelsindex.go ├── wdmatch │ └── main.go ├── weareunique.go ├── wordflip.go ├── zipstring.go └── ztail │ └── main.go ├── test_all.sh ├── test_one.sh ├── test_with_docker.sh └── tests ├── abort_test └── main.go ├── activebits_test └── main.go ├── addfront_test └── main.go ├── addifpositive_test └── main.go ├── addprimesum_test └── main.go ├── advancedsortwordarr_test └── main.go ├── alphacount_test └── main.go ├── alphamirror_test └── main.go ├── alphaposition_test └── main.go ├── any_test └── main.go ├── appendrange_test └── main.go ├── argrot1_test └── main.go ├── argrotn_test └── main.go ├── argsort_test └── main.go ├── atoi_test └── main.go ├── atoibase_test └── main.go ├── balancedstring_test └── main.go ├── basicatoi2_test └── main.go ├── basicatoi_test └── main.go ├── basicjoin_test └── main.go ├── betweenus_test └── main.go ├── bezero_test └── main.go ├── binaryaddition_test └── main.go ├── binarycheck_test └── main.go ├── boolean_test └── main.go ├── brackets_test └── main.go ├── brainfuck_test └── main.go ├── btreeapplybylevel_test └── main.go ├── btreeapplyinorder_test └── main.go ├── btreeapplypostorder_test └── main.go ├── btreeapplypreorder_test └── main.go ├── btreedeletenode_test └── main.go ├── btreeinsertdata_test └── main.go ├── btreeisbinary_test └── main.go ├── btreelevelcount_test └── main.go ├── btreemax_test └── main.go ├── btreemin_test └── main.go ├── btreesearchitem_test └── main.go ├── btreetransplant_test └── main.go ├── buzzinga_test └── main.go ├── byebyefirst_test └── main.go ├── cameltosnakecase_test └── main.go ├── canjump_test └── main.go ├── canyoucount_test └── main.go ├── capitalize_test └── main.go ├── cat_test └── main.go ├── checknumber_test └── main.go ├── chunk_test └── main.go ├── cleanstr_test └── main.go ├── collatzcountdown_test └── main.go ├── comcheck_test └── main.go ├── compact_test └── main.go ├── compare_test └── main.go ├── concat2args_test └── main.go ├── concat_test └── main.go ├── concatalternate_test └── main.go ├── concatenate_test └── main.go ├── concatparams_test └── main.go ├── concatslice_test └── main.go ├── convertbase_test └── main.go ├── count-character_test └── main.go ├── countalpha_test └── main.go ├── countcharacter_test └── main.go ├── countdown_test └── main.go ├── countif_test └── main.go ├── countnegative_test └── main.go ├── countstars_test └── main.go ├── dealapackofcards_test └── main.go ├── delete_test └── main.go ├── descendappendrange_test └── main.go ├── descendcomb_test └── main.go ├── digitlen_test └── main.go ├── displaya_test └── main.go ├── displayalpham_test └── main.go ├── displayalrevm_test └── main.go ├── displayfile_test └── main.go ├── displayfirstparam_test └── main.go ├── displaylastparam_test └── main.go ├── displayp_test └── main.go ├── displays_test └── main.go ├── displayz_test └── main.go ├── divisors_test └── main.go ├── divmod_test └── main.go ├── doop_test └── main.go ├── eightqueens_test └── main.go ├── enigma_test └── main.go ├── evenlength_test └── main.go ├── expandstr_test └── main.go ├── fibonacci_test └── main.go ├── fifthandskip_test └── main.go ├── findmissingnumber_test └── main.go ├── findnextprime_test └── main.go ├── findpairs_test └── main.go ├── findprevprime_test └── main.go ├── firstrune_test └── main.go ├── firstword_test └── main.go ├── fishandchips_test └── main.go ├── fixthemain_test └── main.go ├── flags_test └── main.go ├── foldint_test └── main.go ├── fooddeliverytime_test └── main.go ├── foreach_test └── main.go ├── fprime_test └── main.go ├── fromto_test └── main.go ├── frontback_test └── main.go ├── gcd_test └── main.go ├── getalpha_test └── main.go ├── getarea_test └── main.go ├── getascii_test └── main.go ├── grouping_test └── main.go ├── halfslice_test └── main.go ├── hashcode_test └── main.go ├── hello_test └── main.go ├── hiddenp_test └── main.go ├── index_test └── main.go ├── inter_test └── main.go ├── isalpha_test └── main.go ├── iscapitalized_test └── main.go ├── islower_test └── main.go ├── ismultiple_test └── main.go ├── isnegative_test └── main.go ├── isnumeric_test └── main.go ├── ispowerof2_test └── main.go ├── isprime_test └── main.go ├── isprintable_test └── main.go ├── issamestring_test └── main.go ├── issorted_test └── main.go ├── issquare_test └── main.go ├── isupper_test └── main.go ├── iterativefactorial_test └── main.go ├── iterativepower_test └── main.go ├── itoa_test └── main.go ├── itoabase_test └── main.go ├── join_test └── main.go ├── jumpover_test └── main.go ├── lastrune_test └── main.go ├── lastword_test └── main.go ├── lcm_test └── main.go ├── leapyear_test └── main.go ├── listat_test └── main.go ├── listclear_test └── main.go ├── listfind_test └── main.go ├── listforeach_test └── main.go ├── listforeachif_test └── main.go ├── listlast_test └── main.go ├── listmerge_test └── main.go ├── listpushback_test └── main.go ├── listpushfront_test └── main.go ├── listremoveif_test └── main.go ├── listreverse_test └── main.go ├── listsize_test └── main.go ├── listsort_test └── main.go ├── loafofbread_test └── main.go ├── makerange_test └── main.go ├── map_test └── main.go ├── max_test └── main.go ├── maxwordcountn_test └── main.go ├── multorsum_test └── main.go ├── nbrconvertalpha_test └── main.go ├── notdecimal_test └── main.go ├── nrune_test └── main.go ├── numofdigits_test └── main.go ├── oddlength_test └── main.go ├── only1_test └── main.go ├── onlya_test └── main.go ├── onlyb_test └── main.go ├── onlyf_test └── main.go ├── onlyz_test └── main.go ├── options_test └── main.go ├── paramcount_test └── main.go ├── paramrange_test └── main.go ├── piglatin_test └── main.go ├── pilot_test └── main.go ├── pingpong_test └── main.go ├── podiumposition_test └── main.go ├── point_test └── main.go ├── pointone_test └── main.go ├── popint_test └── main.go ├── printalphabet_test └── main.go ├── printalphabetalt2_test └── main.go ├── printalphabetalt_test └── main.go ├── printalphabetg_test └── main.go ├── printalt2_test └── main.go ├── printalt_test └── main.go ├── printaltu2_test └── main.go ├── printaltu_test └── main.go ├── printascii_test └── main.go ├── printbits_test └── main.go ├── printcomb2_test └── main.go ├── printcomb_test └── main.go ├── printcombn_test └── main.go ├── printdigits_test └── main.go ├── printevenarguments_test └── main.go ├── printhex_test └── main.go ├── printif_test └── main.go ├── printifnot_test └── main.go ├── printmemory_test └── main.go ├── printmiddle_test └── main.go ├── printnbr_test └── main.go ├── printnbrbase_test └── main.go ├── printnbrinorder_test └── main.go ├── printparams_test └── main.go ├── printprogramname_test └── main.go ├── printrange_test └── main.go ├── printrevcomb_test └── main.go ├── printreversealphabet_test └── main.go ├── printreversealphabetalt2_test └── main.go ├── printreversealphabetalt_test └── main.go ├── printreversealphabetg_test └── main.go ├── printrot_test └── main.go ├── printstr_test └── main.go ├── printwordstables_test └── main.go ├── quad_test └── main.go ├── quadchecker_test └── main.go ├── quarterofayear_test └── main.go ├── range_test └── main.go ├── rectangle_test └── main.go ├── rectperimeter_test └── main.go ├── recursivefactorial_test └── main.go ├── recursivepower_test └── main.go ├── reduceint_test └── main.go ├── removeduplicate_test └── main.go ├── removeodd └── main.go ├── repeatalpha_test └── main.go ├── replaceeven_test └── main.go ├── retainfirsthalf_test └── main.go ├── returna_test └── main.go ├── revargs_test └── main.go ├── revconcatalternate_test └── main.go ├── reversebits_test └── main.go ├── reversemenuindex_test └── main.go ├── reverserange_test └── main.go ├── reversesecondhalf_test └── main.go ├── reversestrcap_test └── main.go ├── reversestrings_test └── main.go ├── revparams_test └── main.go ├── revwstr_test └── main.go ├── rockandroll_test └── main.go ├── romannumbers_test └── main.go ├── rostring_test └── main.go ├── rot13_test └── main.go ├── rot14_test └── main.go ├── rotatevowels_test └── main.go ├── rpncalc_test └── main.go ├── samecase_test └── main.go ├── saveandmiss_test └── main.go ├── searchreplace_test └── main.go ├── secondhalf_test └── main.go ├── setspace_test └── main.go ├── shoppinglistsort_test └── main.go ├── shoppingsummarycounter_test └── main.go ├── slice_test └── main.go ├── sliceadd_test └── main.go ├── sliceremove_test └── main.go ├── sortedlistmerge_test └── main.go ├── sortintegertable_test └── main.go ├── sortlistinsert_test └── main.go ├── sortparams_test └── main.go ├── sortwordarr_test └── main.go ├── split_test └── main.go ├── splitwhitespaces_test └── main.go ├── sqrt_test └── main.go ├── squareroot_test └── main.go ├── stringtobool_test └── main.go ├── stringtointslice_test └── main.go ├── strisnegative_test └── main.go ├── strlen_test └── main.go ├── strrev_test └── main.go ├── sudoku_test └── main.go ├── sum_test └── main.go ├── sumarray_test └── main.go ├── sumascii_test └── main.go ├── sumthemall_test └── main.go ├── swap_test └── main.go ├── swapargs_test └── main.go ├── swapbits_test └── main.go ├── swapfirst_test └── main.go ├── swaplast_test └── main.go ├── switchcase_test └── main.go ├── tabmult_test └── main.go ├── tetrisoptimizer_test └── main.go ├── thirdtimeisacharm_test └── main.go ├── tolower_test └── main.go ├── toupper_test └── main.go ├── trimatoi_test └── main.go ├── twosum_test └── main.go ├── ultimatedivmod_test └── main.go ├── ultimatepointone_test └── main.go ├── union_test └── main.go ├── unmatch_test └── main.go ├── unzipstring_test └── main.go ├── vowelsindex_test └── main.go ├── wdmatch_test └── main.go ├── weareunique_test └── main.go ├── wordflip_test └── main.go ├── zipstring_test └── main.go └── ztail_test └── main.go /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.01-edu.org/golang:1.18.0-alpine3.15 2 | 3 | ENV GIT_TERMINAL_PROMPT=0 4 | RUN apk add --no-cache git 5 | 6 | RUN go install mvdan.cc/gofumpt@v0.1.1 7 | RUN go install github.com/01-edu/rc@v0.1.0 8 | 9 | WORKDIR /piscine-go 10 | RUN go mod init piscine-go 11 | RUN go get github.com/01-edu/z01@v0.1.0 12 | 13 | WORKDIR /go-tests 14 | COPY go.* ./ 15 | RUN go mod download 16 | COPY lib lib 17 | COPY solutions solutions 18 | COPY tests tests 19 | RUN go install $(grep -rl 'challenge.Program' ./tests | rev | cut -d/ -f2- | rev) 20 | 21 | RUN rm -rf /piscine-go 22 | 23 | COPY entrypoint.sh /usr/local/bin 24 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 25 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/weightygroc/go-tests 2 | 3 | go 1.18 4 | 5 | require student v0.0.0 6 | 7 | require github.com/01-edu/z01 v0.1.0 // indirect 8 | 9 | replace student => ../piscine-go 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/01-edu/z01 v0.1.0 h1:Rr1p92CKYXUgVFw872iGDABXpdkuKf2jmS+KV6r1034= 2 | github.com/01-edu/z01 v0.1.0/go.mod h1:BH7t35JaNFuP83rTJDc5nkSfgmC/HYVcJsUcdFqYZNo= 3 | -------------------------------------------------------------------------------- /lib/is/is.go: -------------------------------------------------------------------------------- 1 | package is 2 | 3 | import ( 4 | "math/big" 5 | "unicode" 6 | ) 7 | 8 | func Digit(s string) bool { 9 | for _, r := range s { 10 | if !unicode.IsDigit(r) { 11 | return false 12 | } 13 | } 14 | return true 15 | } 16 | 17 | func Lower(s string) bool { 18 | for _, r := range s { 19 | if !unicode.IsLower(r) { 20 | return false 21 | } 22 | } 23 | return true 24 | } 25 | 26 | func Upper(s string) bool { 27 | for _, r := range s { 28 | if !unicode.IsUpper(r) { 29 | return false 30 | } 31 | } 32 | return true 33 | } 34 | 35 | func Prime(i int) bool { 36 | return big.NewInt(int64(i)).ProbablyPrime(0) 37 | } 38 | -------------------------------------------------------------------------------- /solutions/abort.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "sort" 4 | 5 | // Receives 5 ints and returns the number in the middle 6 | func Abort(a, b, c, d, e int) int { 7 | arg := []int{a, b, c, d, e} 8 | sort.Ints(arg) 9 | return arg[2] 10 | } 11 | -------------------------------------------------------------------------------- /solutions/activebits.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // Function that return the number of active bits in the number passed as the argument 4 | func ActiveBits(n int) (total int) { 5 | for ; n > 1; n /= 2 { 6 | total += n % 2 7 | } 8 | total += n 9 | return 10 | } 11 | -------------------------------------------------------------------------------- /solutions/addfront.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func AddFront(str string, slice []string) []string { 4 | if len(str) == 0 { 5 | return slice 6 | } 7 | return append([]string{str}, slice...) 8 | } 9 | -------------------------------------------------------------------------------- /solutions/addifpositive.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func AddIfPositive(a, b int) int { 4 | if a > 0 && b > 0 { 5 | return a + b 6 | } 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /solutions/addprimesum/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | 8 | "github.com/weightygroc/go-tests/lib/is" 9 | ) 10 | 11 | func main() { 12 | if len(os.Args) != 2 { 13 | fmt.Println("0") 14 | } else { 15 | argument, _ := strconv.Atoi(os.Args[1]) 16 | 17 | if argument < 0 { 18 | fmt.Println("0") 19 | } else { 20 | result := 0 21 | for ; argument >= 0; argument-- { 22 | if is.Prime(argument) { 23 | result += argument 24 | } 25 | } 26 | fmt.Println(result) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solutions/alphacount.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "unicode" 4 | 5 | func AlphaCount(s string) (i int) { 6 | for _, r := range s { 7 | if unicode.IsLetter(r) { 8 | i++ 9 | } 10 | } 11 | return i 12 | } 13 | -------------------------------------------------------------------------------- /solutions/alphamirror/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) == 2 { 10 | arg := []rune(os.Args[1]) 11 | for i, ch := range arg { 12 | if ch >= 'a' && ch <= 'z' { 13 | arg[i] = 'z' - ch + 'a' 14 | } else if ch >= 'A' && ch <= 'Z' { 15 | arg[i] = 'Z' - ch + 'A' 16 | } 17 | } 18 | fmt.Print(string(arg)) 19 | } 20 | 21 | fmt.Println() 22 | } 23 | -------------------------------------------------------------------------------- /solutions/alphaposition.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func AlphaPosition(c rune) int { 4 | if c >= 'a' && c <= 'z' { 5 | return int(c - 'a' + 1) 6 | } else if c >= 'A' && c <= 'Z' { 7 | return int(c - 'A' + 1) 8 | } 9 | return -1 10 | } 11 | -------------------------------------------------------------------------------- /solutions/any.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Any(f func(string) bool, a []string) bool { 4 | for _, el := range a { 5 | if f(el) { 6 | return true 7 | } 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /solutions/appendrange.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func AppendRange(min, max int) []int { 4 | size := max - min 5 | answer := []int{} 6 | if size <= 0 { 7 | return nil 8 | } 9 | for i := min; i < max; i++ { 10 | answer = append(answer, i) 11 | } 12 | return answer 13 | } 14 | -------------------------------------------------------------------------------- /solutions/argrot1/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) < 3 { 10 | fmt.Println() 11 | return 12 | } 13 | for i := 1; i < len(os.Args); i++ { 14 | if i != len(os.Args)-1 { 15 | fmt.Print(os.Args[i+1]) 16 | fmt.Print(" ") 17 | } else { 18 | fmt.Print(os.Args[1]) 19 | } 20 | } 21 | fmt.Println() 22 | } 23 | -------------------------------------------------------------------------------- /solutions/argrotn/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "os" 5 | import "strconv" 6 | 7 | func main() { 8 | if len(os.Args) < 3 { 9 | fmt.Println("") 10 | return 11 | } 12 | 13 | args := os.Args[2:] 14 | 15 | n, err := strconv.Atoi(os.Args[1]) 16 | if err != nil || n < 0 { 17 | fmt.Println("Error") 18 | return 19 | } 20 | 21 | for i := 0; i < len(args); i++ { 22 | fmt.Print(string(args[(i+n)%len(args)])) 23 | if i < len(args)-1 { 24 | fmt.Print(" ") 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /solutions/argsort/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/01-edu/z01" 7 | ) 8 | 9 | func main() { 10 | argument := os.Args[1:] 11 | if len(argument) == 1 && len(argument[0]) >= 1 { 12 | for i := 0; i < len(argument[0]); i++ { 13 | j := i + 1 14 | if j < len(argument[0]) { 15 | if argument[0][i] > argument[0][j] { 16 | z01.PrintRune('F') 17 | z01.PrintRune('\n') 18 | return 19 | } 20 | } 21 | } 22 | z01.PrintRune('T') 23 | z01.PrintRune('\n') 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/atoi.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | func Atoi(s string) int { 6 | n, _ := strconv.Atoi(s) 7 | return n 8 | } 9 | -------------------------------------------------------------------------------- /solutions/atoibase.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/base" 4 | 5 | var AtoiBase = base.Atoi 6 | -------------------------------------------------------------------------------- /solutions/balancedstring/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func solve(s string) int { 9 | var count, countC, countD int 10 | for _, r := range s { 11 | if r == 'C' { 12 | countC++ 13 | } else if r == 'D' { 14 | countD++ 15 | } 16 | if countC == countD { 17 | count++ 18 | countC = 0 19 | countD = 0 20 | } 21 | } 22 | return count 23 | } 24 | 25 | func main() { 26 | args := os.Args[1:] 27 | if len(args) == 1 { 28 | result := solve(args[0]) 29 | fmt.Println(result) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /solutions/basicatoi.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | func BasicAtoi(s string) int { 6 | n, _ := strconv.Atoi(s) 7 | return n 8 | } 9 | -------------------------------------------------------------------------------- /solutions/basicatoi2.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | func BasicAtoi2(s string) int { 6 | n, _ := strconv.Atoi(s) 7 | return n 8 | } 9 | -------------------------------------------------------------------------------- /solutions/basicjoin.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func BasicJoin(elems []string) string { 6 | return strings.Join(elems, "") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/betweenus.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func BetweenUs(n, min, max int) bool { 4 | if n < min || n > max { 5 | return false 6 | } 7 | return true 8 | } 9 | -------------------------------------------------------------------------------- /solutions/bezero.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func BeZero(slice []int) []int { 4 | dst := make([]int, len(slice)) 5 | copy(dst, slice) 6 | 7 | for i := 0; i < len(dst); i++ { 8 | dst[i] = 0 9 | } 10 | return dst 11 | } 12 | -------------------------------------------------------------------------------- /solutions/binarryaddition.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func BinaryAddition(a, b int) []int { 4 | var result []int 5 | var carry int = 0 6 | for a > 0 || b > 0 { 7 | var sum int 8 | if a > 0 { 9 | sum = a % 2 10 | a = a / 2 11 | } 12 | if b > 0 { 13 | sum += b % 2 14 | b = b / 2 15 | } 16 | sum += carry 17 | carry = sum / 2 18 | result = append(result, sum%2) 19 | } 20 | if carry > 0 { 21 | result = append(result, carry) 22 | } 23 | for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 { 24 | result[i], result[j] = result[j], result[i] 25 | } 26 | return result 27 | } 28 | -------------------------------------------------------------------------------- /solutions/binarycheck.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func BinaryCheck(nbr int32) int { 4 | if nbr%2 == 0 { 5 | return 1 6 | } 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /solutions/boolean/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args[1:])%2 == 0 { 10 | fmt.Println("I have an even number of arguments") 11 | } else { 12 | fmt.Println("I have an odd number of arguments") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /solutions/buzzinga.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func BuzZinga(n int32) { 6 | var i int32 = 0 7 | if n == 0 { 8 | fmt.Println("Buzzinga") 9 | } 10 | if n < 0 { 11 | fmt.Println("*") 12 | } 13 | for i = 1; i <= n; i++ { 14 | if i%3 == 0 && i%5 == 0 { 15 | fmt.Println("Buzzinga") 16 | } else if i%3 == 0 { 17 | fmt.Println("Buz") 18 | } else if i%5 == 0 { 19 | fmt.Println("zinga") 20 | } else { 21 | fmt.Println("*") 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /solutions/byebyefirst.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ByeByeFirst(strings []string) []string { 4 | if len(strings) <= 1 { 5 | return []string{} 6 | } 7 | return strings[1:] 8 | } 9 | -------------------------------------------------------------------------------- /solutions/canjump.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CanJump(steps []uint) bool { 4 | if len(steps) == 0 { 5 | return false 6 | } 7 | 8 | maxReach := 0 9 | for i := 0; i < len(steps); i++ { 10 | if i > maxReach { 11 | return false 12 | } 13 | maxReach = max(maxReach, i+int(steps[i])) 14 | if maxReach == len(steps)-1 || len(steps) == 1 { 15 | return true 16 | } 17 | } 18 | return false 19 | } 20 | 21 | func max(a, b int) int { 22 | if a > b { 23 | return a 24 | } 25 | return b 26 | } 27 | -------------------------------------------------------------------------------- /solutions/canyoucount/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) < 2 { 10 | fmt.Println(0) 11 | return 12 | } 13 | count := 0 14 | for _, arg := range os.Args[1:] { 15 | count += len(arg) 16 | } 17 | fmt.Println(count) 18 | } 19 | -------------------------------------------------------------------------------- /solutions/capitalize.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "strings" 5 | "unicode" 6 | ) 7 | 8 | func Capitalize(s string) string { 9 | r := []rune(strings.ToLower(s)) 10 | 11 | if unicode.Is(unicode.Latin, r[0]) { 12 | r[0] = unicode.ToUpper(r[0]) 13 | } 14 | 15 | for i := 1; i < len(r); i++ { 16 | if !unicode.IsDigit(r[i-1]) && !unicode.Is(unicode.Latin, r[i-1]) { 17 | r[i] = unicode.ToUpper(r[i]) 18 | } 19 | } 20 | return string(r) 21 | } 22 | -------------------------------------------------------------------------------- /solutions/cat/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | "os" 7 | 8 | "github.com/weightygroc/go-tests/lib/challenge" 9 | ) 10 | 11 | func main() { 12 | if len(os.Args) == 1 { 13 | if _, err := io.Copy(os.Stdout, os.Stdin); err != nil { 14 | panic(err) 15 | } 16 | } else { 17 | for _, arg := range os.Args[1:] { 18 | b, err := ioutil.ReadFile(arg) 19 | if err != nil { 20 | challenge.Fatalln("ERROR:", err) 21 | } 22 | os.Stdout.Write(b) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/checknumber.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CheckNumber(str string) bool { 4 | for _, c := range str { 5 | if c >= '0' && c <= '9' { 6 | return true 7 | } 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /solutions/chunk.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func Chunk(a []int, ch int) { 6 | var slice []int 7 | if ch <= 0 { 8 | fmt.Println() 9 | return 10 | } 11 | result := make([][]int, 0, len(a)/ch+1) 12 | for len(a) >= ch { 13 | slice, a = a[:ch], a[ch:] 14 | result = append(result, slice) 15 | } 16 | if len(a) > 0 { 17 | result = append(result, a[:]) 18 | } 19 | fmt.Println(result) 20 | } 21 | -------------------------------------------------------------------------------- /solutions/cleanstr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "regexp" 7 | "strings" 8 | ) 9 | 10 | func main() { 11 | if len(os.Args) == 2 { 12 | re := regexp.MustCompile(`( +)`) 13 | fmt.Print(re.ReplaceAllString(strings.Trim(os.Args[1], " "), " ")) 14 | } 15 | fmt.Println() 16 | } 17 | -------------------------------------------------------------------------------- /solutions/collatzcountdown.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CollatzCountdown(start int) int { 4 | if start <= 0 { 5 | return -1 6 | } 7 | steps := 0 8 | for start != 1 { 9 | if start%2 == 0 { 10 | start = start / 2 11 | } else { 12 | start = 3*start + 1 13 | } 14 | steps++ 15 | } 16 | return steps 17 | } 18 | -------------------------------------------------------------------------------- /solutions/comcheck/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | safeWords := []string{"01", "galaxy", "galaxy 01"} 10 | count := 0 11 | for _, arg := range os.Args[1:] { 12 | for _, s := range safeWords { 13 | if s == arg { 14 | count++ 15 | } 16 | } 17 | } 18 | if count == 1 || count == 2 { 19 | fmt.Println("Alert!!!") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solutions/compare.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var Compare = strings.Compare 6 | -------------------------------------------------------------------------------- /solutions/concat.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Concat(s1 string, s2 string) string { 4 | return s1 + s2 5 | } 6 | -------------------------------------------------------------------------------- /solutions/concat2args/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/01-edu/z01" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | args := os.Args[1:] 10 | if len(args) != 2 { 11 | z01.PrintRune('\n') 12 | return 13 | } 14 | str := "" 15 | for i := 0; i < len(args); i++ { 16 | for _, v := range args[i] { 17 | str += string(v) 18 | } 19 | } 20 | if len(str) > 0 { 21 | for _, v := range str { 22 | z01.PrintRune(v) 23 | } 24 | } 25 | z01.PrintRune('\n') 26 | } 27 | -------------------------------------------------------------------------------- /solutions/concatalternate.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ConcatAlternate(slice1, slice2 []int) []int { 4 | var result []int 5 | 6 | if len(slice1) < len(slice2) { 7 | slice1, slice2 = slice2, slice1 8 | } 9 | for i, v := range slice1 { 10 | result = append(result, v) 11 | if i < len(slice2) { 12 | result = append(result, slice2[i]) 13 | } 14 | } 15 | return result 16 | } 17 | -------------------------------------------------------------------------------- /solutions/concatenate/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) < 2 { 10 | fmt.Println() 11 | return 12 | } 13 | result := "" 14 | for _, arg := range os.Args[1:] { 15 | result += arg 16 | } 17 | fmt.Println(result) 18 | } 19 | -------------------------------------------------------------------------------- /solutions/concatparams.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func ConcatParams(args []string) string { 6 | return strings.Join(args, "\n") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/concatslice.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ConcatSlice(slice1, slice2 []int) []int { 4 | var result []int 5 | for _, v := range slice1 { 6 | result = append(result, v) 7 | } 8 | for _, v := range slice2 { 9 | result = append(result, v) 10 | } 11 | return result 12 | } 13 | -------------------------------------------------------------------------------- /solutions/convertbase.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/base" 4 | 5 | func convertNbrBase(n int, base string) string { 6 | var result string 7 | length := len(base) 8 | 9 | for n >= length { 10 | result = string(base[(n%length)]) + result 11 | n /= length 12 | } 13 | result = string(base[n]) + result 14 | 15 | return result 16 | } 17 | 18 | func ConvertBase(nbr, baseFrom, baseTo string) string { 19 | resultIntermediary := base.Atoi(nbr, baseFrom) 20 | 21 | resultFinal := convertNbrBase(resultIntermediary, baseTo) 22 | 23 | return resultFinal 24 | } 25 | -------------------------------------------------------------------------------- /solutions/count-character.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CountChar(str string, c rune) int { 4 | var count int 5 | for _, v := range str { 6 | if rune(v) == c { 7 | count++ 8 | } 9 | } 10 | return count 11 | } 12 | -------------------------------------------------------------------------------- /solutions/countalpha.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CountAlpha(s string) int { 4 | count := 0 5 | for _, c := range s { 6 | if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' { 7 | count++ 8 | } 9 | } 10 | return count 11 | } 12 | -------------------------------------------------------------------------------- /solutions/countdown/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println(9876543210) 7 | } 8 | -------------------------------------------------------------------------------- /solutions/countif.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CountIf(f func(string) bool, a []string) int { 4 | counter := 0 5 | for _, el := range a { 6 | if f(el) { 7 | counter++ 8 | } 9 | } 10 | 11 | return counter 12 | } 13 | -------------------------------------------------------------------------------- /solutions/countnegative.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func CountNegative(numbers []int) int { 4 | count := 0 5 | if len(numbers) == 0 { 6 | return count 7 | } 8 | for _, number := range numbers { 9 | if number < 0 { 10 | count++ 11 | } 12 | } 13 | return count 14 | } 15 | -------------------------------------------------------------------------------- /solutions/countstars.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | func CountStars(num int) string { 6 | res := "" 7 | star := " star" 8 | stars := " stars" 9 | dots := "..." 10 | if num <= 0 { 11 | return "No stars" 12 | } 13 | if num == 1 { 14 | return strconv.Itoa(1) + star 15 | } 16 | for i := 1; i <= num; i++ { 17 | if i == 1 { 18 | res = res + strconv.Itoa(i) + star + dots 19 | } else if i != num { 20 | res = res + strconv.Itoa(i) + stars + dots 21 | } else { 22 | res = res + strconv.Itoa(i) + stars 23 | } 24 | } 25 | return res 26 | } 27 | -------------------------------------------------------------------------------- /solutions/dealapackofcards.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func DealAPackOfCards(deck []int) { 6 | for _, v := range deck { 7 | if v == 1 { 8 | fmt.Printf("Player 1: %v, %v, %v", deck[0], deck[1], deck[2]) 9 | fmt.Println() 10 | } else if v == 3 { 11 | fmt.Printf("Player 2: %v, %v, %v", deck[3], deck[4], deck[5]) 12 | fmt.Println() 13 | } else if v == 6 { 14 | fmt.Printf("Player 3: %v, %v, %v", deck[6], deck[7], deck[8]) 15 | fmt.Println() 16 | } else if v == 9 { 17 | fmt.Printf("Player 4: %v, %v, %v", deck[9], deck[10], deck[11]) 18 | fmt.Println() 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solutions/delete.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Delete(ints []int, position int) []int { 4 | if position > len(ints)-1 { 5 | return ints 6 | } 7 | result := []int{} 8 | for i, integer := range ints { 9 | if i == position-1 { 10 | continue 11 | } 12 | result = append(result, integer) 13 | } 14 | return result 15 | } 16 | -------------------------------------------------------------------------------- /solutions/descendappendrange.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func DescendAppendRange(max, min int) []int { 4 | answer := []int{} 5 | if max <= min { 6 | return []int{} 7 | } else { 8 | for i := max ; i > min; i-- { 9 | answer = append(answer, i) 10 | } 11 | } 12 | return answer 13 | } 14 | -------------------------------------------------------------------------------- /solutions/descendcomb.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func printInteger(a int) { 6 | secondDigits := (a % 10) 7 | firstDigits := (a / 10) 8 | 9 | z01.PrintRune(rune(firstDigits) + 48) 10 | z01.PrintRune(rune(secondDigits) + 48) 11 | } 12 | 13 | func DescendComb() { 14 | for i := 99; i >= 0; i-- { 15 | for j := i - 1; j >= 0; j-- { 16 | printInteger(i) 17 | z01.PrintRune(' ') 18 | printInteger(j) 19 | 20 | if i == 1 && j == 0 { 21 | break 22 | } 23 | z01.PrintRune(',') 24 | z01.PrintRune(' ') 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /solutions/digitlen.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func DigitLen(n, base int) int { 4 | 5 | if base < 2 || base > 36 { 6 | return -1 7 | } 8 | 9 | if n < 0 { 10 | n = -n 11 | } 12 | 13 | count := 0 14 | for n > 0 { 15 | n /= base 16 | count++ 17 | } 18 | return count 19 | } 20 | -------------------------------------------------------------------------------- /solutions/displaya/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("a") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/displayalpham/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/displayalrevm/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/displayfile/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) < 2 { 11 | fmt.Println("File name missing") 12 | } else if len(os.Args) > 2 { 13 | fmt.Println("Too many arguments") 14 | } else { 15 | b, err := ioutil.ReadFile(os.Args[1]) 16 | if err != nil { 17 | panic(err) 18 | } 19 | os.Stdout.Write(b) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solutions/displayfirstparam/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) > 1 { 10 | fmt.Println(os.Args[1]) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solutions/displaylastparam/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | size := len(os.Args) 10 | if size > 1 { 11 | fmt.Println(os.Args[size-1]) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /solutions/displayp/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func main() { 6 | z01.PrintRune('P') 7 | z01.PrintRune('\n') 8 | } 9 | -------------------------------------------------------------------------------- /solutions/displays/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("S") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/displayz/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("z") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/divisors.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Divisors(n int) int { 4 | var count int = 0 5 | if n > 0 { 6 | for i := 1; i <= n; i++ { 7 | if n%i == 0 { 8 | count++ 9 | } 10 | } 11 | } 12 | return count 13 | } 14 | -------------------------------------------------------------------------------- /solutions/evenlength.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func EvenLength(strings []string) []string { 4 | var newSlice []string 5 | for _, str := range strings { 6 | if len(str)%2 == 0 { 7 | newSlice = append(newSlice, str) 8 | } 9 | } 10 | return newSlice 11 | } 12 | -------------------------------------------------------------------------------- /solutions/expandstr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func deleteExtraSpaces(a []string) (res []string) { 10 | for _, v := range a { 11 | if v != "" { 12 | res = append(res, v) 13 | } 14 | } 15 | return 16 | } 17 | 18 | func main() { 19 | if len(os.Args) == 2 { 20 | arg := strings.Split(os.Args[1], " ") 21 | arg = deleteExtraSpaces(arg) 22 | fmt.Println(strings.Join(arg, " ")) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /solutions/fibonacci.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Fibonacci(i int) int { 4 | if i < 0 { 5 | return -1 6 | } 7 | if i == 0 { 8 | return 0 9 | } 10 | if i == 1 { 11 | return 1 12 | } 13 | return Fibonacci(i-1) + Fibonacci(i-2) 14 | } 15 | -------------------------------------------------------------------------------- /solutions/fifthandskip.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func FifthAndSkip(str string) string { 6 | if str == "" { 7 | return "\n" 8 | } 9 | if len(str) < 5 { 10 | return "Invalid Input\n" 11 | } 12 | s := strings.ReplaceAll(str, " ", "") 13 | var _str strings.Builder 14 | j := 0 15 | for _, char := range s { 16 | if j == 5 { 17 | _str.WriteRune(rune(' ')) 18 | j = 0 19 | } else { 20 | _str.WriteRune(rune(char)) 21 | j++ 22 | } 23 | } 24 | _str.WriteRune('\n') 25 | return _str.String() 26 | } 27 | -------------------------------------------------------------------------------- /solutions/findmissingnumber.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func FindMissingNumber(nums []int) int { 4 | for i := 0; i < len(nums); i++ { 5 | for j := i + 1; j < len(nums); j++ { 6 | if nums[i] > nums[j] { 7 | nums[i], nums[j] = nums[j], nums[i] 8 | } 9 | } 10 | } 11 | for i := 0; i < len(nums); i++ { 12 | if i+1 < len(nums) && nums[i]+1 != nums[i+1] { 13 | return nums[i] + 1 14 | } 15 | } 16 | return -1 17 | } 18 | -------------------------------------------------------------------------------- /solutions/findnextprime.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | func FindNextPrime(nb int) int { 6 | if is.Prime(nb) { 7 | return nb 8 | } 9 | return FindNextPrime(nb + 1) 10 | } 11 | -------------------------------------------------------------------------------- /solutions/findprevprime.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | func FindPrevPrime(nb int) int { 6 | if nb < 2 { 7 | return 0 8 | } 9 | if is.Prime(nb) { 10 | return nb 11 | } 12 | return FindPrevPrime(nb - 1) 13 | } 14 | -------------------------------------------------------------------------------- /solutions/firstrune.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func FirstRune(s string) rune { 4 | runes := []rune(s) 5 | return runes[0] 6 | } 7 | -------------------------------------------------------------------------------- /solutions/firstword.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func FirstWord(s string) string { 6 | words := strings.Fields(s) 7 | res := "\n" 8 | if len(words) > 0 { 9 | res = words[0] + res 10 | } 11 | return res 12 | } 13 | -------------------------------------------------------------------------------- /solutions/fishandchips.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func FishAndChips(n int) string { 4 | if n < 0 { 5 | return "error: number is negative" 6 | } 7 | 8 | if (n%2 == 0) && (n%3 == 0) { 9 | return "fish and chips" 10 | } 11 | if n%2 == 0 { 12 | return "fish" 13 | } 14 | if n%3 == 0 { 15 | return "chips" 16 | } 17 | return "error: non divisible" 18 | } 19 | -------------------------------------------------------------------------------- /solutions/foldint.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func FoldInt(f func(int, int) int, a []int, n int) { 6 | result := n 7 | for _, v := range a { 8 | result = f(result, v) 9 | } 10 | fmt.Println(result) 11 | } 12 | -------------------------------------------------------------------------------- /solutions/fooddeliverytime.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | type food struct { 4 | preptime int 5 | } 6 | 7 | func FoodDeliveryTime(order string) int { 8 | burger := food{ 9 | preptime: 15, 10 | } 11 | 12 | chips := food{ 13 | preptime: 10, 14 | } 15 | 16 | nuggets := food{ 17 | preptime: 12, 18 | } 19 | 20 | if order == "burger" { 21 | return burger.preptime 22 | } else if order == "chips" { 23 | return chips.preptime 24 | } else if order == "nuggets" { 25 | return nuggets.preptime 26 | } else { 27 | return 404 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solutions/foreach.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ForEach(f func(int), a []int) { 4 | for _, el := range a { 5 | f(el) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/fprime/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func fprime(value int) { 10 | if value == 1 { 11 | return 12 | } 13 | divisionIterator := 2 14 | for value > 1 { 15 | if value%divisionIterator == 0 { 16 | fmt.Print(divisionIterator) 17 | value = value / divisionIterator 18 | 19 | if value > 1 { 20 | fmt.Print("*") 21 | } 22 | divisionIterator-- 23 | } 24 | divisionIterator++ 25 | } 26 | fmt.Println() 27 | } 28 | 29 | func main() { 30 | if len(os.Args) == 2 { 31 | if i, err := strconv.Atoi(os.Args[1]); err == nil { 32 | fprime(i) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solutions/gcd.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Gcd(a, b uint) uint { 4 | for a != b { 5 | if a > b { 6 | a -= b 7 | } else { 8 | b -= a 9 | } 10 | } 11 | return a 12 | } 13 | -------------------------------------------------------------------------------- /solutions/getalpha/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "strconv" 6 | 7 | "github.com/01-edu/z01" 8 | ) 9 | 10 | func main() { 11 | if len(os.Args) == 2 { 12 | i, err := strconv.Atoi(os.Args[1]) 13 | if err == nil && i >= 0 && i <= 127 { 14 | z01.PrintRune(rune(i)) 15 | } 16 | z01.PrintRune('\n') 17 | } else { 18 | z01.PrintRune('\n') 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /solutions/getarea/getarea.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | args := os.Args 11 | if len(args) != 2 { 12 | fmt.Println() 13 | return 14 | } 15 | area, err := strconv.Atoi(args[1]) 16 | if err != nil || area < 0 { 17 | fmt.Println("Error") 18 | return 19 | } 20 | var result int = int(float32(area*area) * float32(3.14)) 21 | fmt.Println(result) 22 | } 23 | -------------------------------------------------------------------------------- /solutions/getascii/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) == 2 && len(os.Args[1]) == 1 && int(os.Args[1][0]) >= 0 && int(os.Args[1][0]) <= 127 { 10 | fmt.Println(int(os.Args[1][0])) 11 | } 12 | fmt.Print("\n") 13 | } 14 | -------------------------------------------------------------------------------- /solutions/halfslice.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func HalfSlice(slice []int) []int { 4 | var result []int 5 | size := len(slice) / 2 6 | 7 | if len(slice)%2 != 0 { 8 | size = len(slice)/2 + 1 9 | } 10 | for i := 0; i < size; i++ { 11 | result = append(result, slice[i]) 12 | } 13 | return result 14 | } 15 | -------------------------------------------------------------------------------- /solutions/hashcode.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func HashCode(dec string) string { 4 | size := len(dec) 5 | hashed := "" 6 | for _, char := range dec { 7 | hash := (int(char) + size) % 127 8 | if hash < 32 || hash > 126 { 9 | hash += 33 10 | } 11 | hashed += string(hash) 12 | } 13 | return hashed 14 | } 15 | -------------------------------------------------------------------------------- /solutions/hello/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello World!") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/hiddenp/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | var i int 11 | if len(os.Args) != 3 { 12 | return 13 | } 14 | for _, r := range os.Args[1] { 15 | j := strings.Index(os.Args[2][i:], string(r)) 16 | if j == -1 { 17 | fmt.Println("0") 18 | return 19 | } 20 | i += j + 1 21 | } 22 | fmt.Println("1") 23 | } 24 | -------------------------------------------------------------------------------- /solutions/index.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var Index = strings.Index 6 | -------------------------------------------------------------------------------- /solutions/inter/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func result(s1 string, s2 string) string { 10 | var rest []rune 11 | for _, a := range s1 { 12 | for _, b := range s2 { 13 | if a == b && !strings.ContainsRune(string(rest), a) { 14 | rest = append(rest, a) 15 | } 16 | } 17 | } 18 | return string(rest) 19 | } 20 | 21 | func main() { 22 | if len(os.Args) == 3 { 23 | fmt.Println(result(os.Args[1], os.Args[2])) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/isalpha.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "unicode" 4 | 5 | func IsAlpha(s string) bool { 6 | for _, r := range s { 7 | if !unicode.IsDigit(r) && !unicode.Is(unicode.Latin, r) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /solutions/iscapitalized.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func IsCapitalized(s string) bool { 4 | if len(s) == 0 { 5 | return false 6 | } 7 | 8 | for i := 0; i < len(s); i++ { 9 | if s[i] >= 'a' && s[i] <= 'z' && i != 0 && s[i-1] == ' ' { 10 | return false 11 | } 12 | } 13 | return !(s[0] >= 'a' && s[0] <= 'z') 14 | } 15 | -------------------------------------------------------------------------------- /solutions/islower.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | var IsLower = is.Lower 6 | -------------------------------------------------------------------------------- /solutions/ismultiple.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func IsMultiple(num int) bool { 4 | if num > 0 && (num%3 == 0 || num%7 == 0) { 5 | return true 6 | } 7 | return false 8 | } 9 | -------------------------------------------------------------------------------- /solutions/isnegative.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func IsNegative(n int) { 6 | if n < 0 { 7 | fmt.Println("T") 8 | } else { 9 | fmt.Println("F") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /solutions/isnumeric.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | var IsNumeric = is.Digit 6 | -------------------------------------------------------------------------------- /solutions/ispowerof2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | // computes the logical bitwise AND of its operands. 10 | func isPowerOf2(n int) bool { 11 | return n != 0 && ((n & (n - 1)) == 0) 12 | } 13 | 14 | func main() { 15 | if len(os.Args) == 2 { 16 | nbr, _ := strconv.Atoi(os.Args[1]) 17 | fmt.Println(isPowerOf2(nbr)) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /solutions/isprime.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | var IsPrime = is.Prime 6 | -------------------------------------------------------------------------------- /solutions/isprintable.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "unicode" 4 | 5 | func IsPrintable(s string) bool { 6 | for _, r := range s { 7 | if !unicode.IsPrint(r) { 8 | return false 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /solutions/issorted.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func IsSorted(f func(int, int) int, a []int) bool { 4 | ascendingOrdered := true 5 | descendingOrdered := true 6 | 7 | for i := 1; i < len(a); i++ { 8 | if f(a[i-1], a[i]) < 0 { 9 | ascendingOrdered = false 10 | } 11 | } 12 | 13 | for i := 1; i < len(a); i++ { 14 | if f(a[i-1], a[i]) > 0 { 15 | descendingOrdered = false 16 | } 17 | } 18 | 19 | return ascendingOrdered || descendingOrdered 20 | } 21 | -------------------------------------------------------------------------------- /solutions/issquare.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func IsSquare(number int, square int) bool { 4 | if number < 0 || square < 0 { 5 | return false 6 | } 7 | return number*number == square 8 | } 9 | -------------------------------------------------------------------------------- /solutions/isupper.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/weightygroc/go-tests/lib/is" 4 | 5 | var IsUpper = is.Upper 6 | -------------------------------------------------------------------------------- /solutions/iterativefactorial.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func IterativeFactorial(nb int) int { 4 | limit := 20 5 | if nb < 0 || nb > limit { 6 | return 0 7 | } 8 | if nb == 0 { 9 | return 1 10 | } 11 | return nb * IterativeFactorial(nb-1) 12 | } 13 | -------------------------------------------------------------------------------- /solutions/iterativepower.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "math" 4 | 5 | func IterativePower(nb int, power int) int { 6 | if power < 0 { 7 | return 0 8 | } 9 | result := math.Pow(float64(nb), float64(power)) 10 | return int(result) 11 | } 12 | -------------------------------------------------------------------------------- /solutions/itoa.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | var Itoa = strconv.Itoa 6 | -------------------------------------------------------------------------------- /solutions/itoabase.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | func ItoaBase(value, base int) string { 9 | if base < 2 || base > 16 { 10 | return "" 11 | } 12 | 13 | return strings.ToUpper(strconv.FormatInt(int64(value), base)) 14 | } 15 | -------------------------------------------------------------------------------- /solutions/join.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var Join = strings.Join 6 | -------------------------------------------------------------------------------- /solutions/jumpover.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func JumpOver(arg string) string { 6 | if arg == "" || len(arg) < 3 { 7 | return "\n" 8 | } 9 | var str strings.Builder 10 | for i := 0; i < len(arg); i++ { 11 | if i != 0 { 12 | j := i + 1 13 | if j%3 == 0 { 14 | str.WriteRune(rune(arg[i])) 15 | } 16 | } 17 | } 18 | str.WriteRune(rune('\n')) 19 | return (str.String()) 20 | } 21 | -------------------------------------------------------------------------------- /solutions/lastrune.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func LastRune(s string) rune { 4 | runes := []rune(s) 5 | index := len(runes) - 1 6 | return runes[index] 7 | } 8 | -------------------------------------------------------------------------------- /solutions/lastword.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | func LastWord(s string) string { 8 | words := strings.Fields(s) 9 | if len(words) > 0 { 10 | return words[len(words)-1] + "\n" 11 | } 12 | return "\n" 13 | } 14 | -------------------------------------------------------------------------------- /solutions/lcm.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func gcd(first, second int) int { 4 | if second == 0 { 5 | return first 6 | } 7 | return gcd(second, first%second) 8 | } 9 | 10 | func Lcm(first, second int) int { 11 | return first / gcd(second, first%second) * second 12 | } 13 | -------------------------------------------------------------------------------- /solutions/leapyear.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func LeapYear(year int) bool { 4 | if year <= 0 { 5 | return false 6 | } 7 | if year%4 == 0 { 8 | if year%100 == 0 { 9 | return year%400 == 0 10 | } 11 | return true 12 | } 13 | return false 14 | } 15 | -------------------------------------------------------------------------------- /solutions/listat.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // returs the node in a given position 4 | func ListAt(l *NodeL, nbr int) *NodeL { 5 | index := 0 6 | count := 0 7 | head := l 8 | 9 | for head != nil { 10 | index++ 11 | head = head.Next 12 | } 13 | if nbr <= index { 14 | for l != nil { 15 | if count == nbr { 16 | return l 17 | } 18 | count++ 19 | l = l.Next 20 | } 21 | } 22 | return nil 23 | } 24 | -------------------------------------------------------------------------------- /solutions/listclear.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ListClear(l *List) { 4 | temp := l.Head 5 | var next *NodeL 6 | for temp != nil { 7 | next = temp.Next 8 | temp = nil 9 | temp = next 10 | } 11 | 12 | l.Head = nil 13 | } 14 | -------------------------------------------------------------------------------- /solutions/listfind.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // finds the element and returns the first data from the node that is a string 4 | func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} { 5 | iterator := l.Head 6 | for iterator != nil { 7 | if comp(iterator.Data, ref) { 8 | return &iterator.Data 9 | } 10 | 11 | iterator = iterator.Next 12 | } 13 | return nil 14 | } 15 | 16 | // defines for two elements the equality criteria 17 | func CompStr(a, b interface{}) bool { 18 | return a == b 19 | } 20 | -------------------------------------------------------------------------------- /solutions/listforeach.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // applies a function in argument to each element of the linked list 4 | func ListForEach(l *List, f func(*NodeL)) { 5 | it := l.Head 6 | for it != nil { 7 | f(it) 8 | it = it.Next 9 | } 10 | } 11 | 12 | func Add2_node(node *NodeL) { 13 | switch node.Data.(type) { 14 | case int: 15 | node.Data = node.Data.(int) + 2 16 | case string: 17 | node.Data = node.Data.(string) + "2" 18 | } 19 | } 20 | 21 | func Subtract3_node(node *NodeL) { 22 | switch node.Data.(type) { 23 | case int: 24 | node.Data = node.Data.(int) - 3 25 | case string: 26 | node.Data = node.Data.(string) + "-3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solutions/listlast.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // gives the last element of the list 4 | func ListLast(l *List) interface{} { 5 | if l.Head == nil { 6 | return nil 7 | } 8 | for l.Head != nil { 9 | if l.Head.Next == nil { 10 | return l.Head.Data 11 | } 12 | l.Head = l.Head.Next 13 | } 14 | return l.Head.Data 15 | } 16 | -------------------------------------------------------------------------------- /solutions/listmerge.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // merges the 2 lists in one (in the end of the first list) 4 | func ListMerge(l1 *List, l2 *List) { 5 | if l1.Head == nil { 6 | l1.Head, l1.Tail = l2.Head, l2.Tail 7 | return 8 | } 9 | l1.Tail.Next = l2.Head 10 | } 11 | -------------------------------------------------------------------------------- /solutions/listpushback.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | type NodeL struct { 4 | Data interface{} 5 | Next *NodeL 6 | } 7 | 8 | type List struct { 9 | Head *NodeL 10 | Tail *NodeL 11 | } 12 | 13 | func ListPushBack(l *List, data interface{}) { 14 | n := &NodeL{Data: data} 15 | 16 | if l.Head == nil { 17 | l.Head = n 18 | } else { 19 | l.Tail.Next = n 20 | } 21 | l.Tail = n 22 | } 23 | -------------------------------------------------------------------------------- /solutions/listpushfront.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // inserts node on the first position of the list 4 | func ListPushFront(l *List, data interface{}) { 5 | n := &NodeL{Data: data} 6 | 7 | if l.Head == nil { 8 | l.Head = n 9 | return 10 | } 11 | 12 | n.Next = l.Head 13 | l.Head = n 14 | } 15 | -------------------------------------------------------------------------------- /solutions/listremoveif.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // removes all elements that are equal to the data_ref 4 | func ListRemoveIf(l *List, data_ref interface{}) { 5 | temp := l.Head 6 | prev := l.Head 7 | 8 | for temp != nil && temp.Data == data_ref { 9 | l.Head = temp.Next 10 | temp = l.Head 11 | } 12 | for temp != nil { 13 | if temp.Data != data_ref { 14 | prev = temp 15 | } 16 | prev.Next = temp.Next 17 | temp = prev.Next 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /solutions/listreverse.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ListReverse(l *List) { 4 | current := l.Head 5 | var prev *NodeL 6 | prev = nil 7 | 8 | for current != nil { 9 | next := current.Next 10 | current.Next = prev 11 | prev = current 12 | current = next 13 | } 14 | l.Head = prev 15 | } 16 | -------------------------------------------------------------------------------- /solutions/listsize.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ListSize(l *List) int { 4 | count := 0 5 | iterator := l.Head 6 | for iterator != nil { 7 | count++ 8 | iterator = iterator.Next 9 | } 10 | return count 11 | } 12 | -------------------------------------------------------------------------------- /solutions/listsort.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ListSort(l *NodeI) *NodeI { 4 | head := l 5 | if head == nil { 6 | return nil 7 | } 8 | head.Next = ListSort(head.Next) 9 | 10 | if head.Next != nil && head.Data > head.Next.Data { 11 | head = move(head) 12 | } 13 | return head 14 | } 15 | 16 | func move(l *NodeI) *NodeI { 17 | p := l 18 | n := l.Next 19 | ret := n 20 | 21 | for n != nil && l.Data > n.Data { 22 | p = n 23 | n = n.Next 24 | } 25 | p.Next = l 26 | l.Next = n 27 | return ret 28 | } 29 | -------------------------------------------------------------------------------- /solutions/makerange.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func MakeRange(min, max int) []int { 4 | size := max - min 5 | 6 | if size <= 0 { 7 | return nil 8 | } 9 | answer := make([]int, size) 10 | for i := range answer { 11 | answer[i] = min 12 | min++ 13 | } 14 | return answer 15 | } 16 | -------------------------------------------------------------------------------- /solutions/map.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Map(f func(int) bool, a []int) (result []bool) { 4 | for _, el := range a { 5 | result = append(result, f(el)) 6 | } 7 | return 8 | } 9 | -------------------------------------------------------------------------------- /solutions/max.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "sort" 4 | 5 | func Max(a []int) int { 6 | if len(a) == 0 { 7 | return 0 8 | } 9 | sort.Ints(a) 10 | return a[len(a)-1] 11 | } 12 | -------------------------------------------------------------------------------- /solutions/multorsum.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func MultOrSum(ints []int, init int) int { 4 | if len(ints) == 0 { 5 | return 0 6 | } 7 | result := init 8 | for _, num := range ints { 9 | if num%2 == 0 { 10 | result += num 11 | continue 12 | } 13 | result *= num 14 | } 15 | return result 16 | } 17 | -------------------------------------------------------------------------------- /solutions/nbrconvertalpha/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | args := os.Args[1:] 11 | if len(args) == 0 { 12 | return 13 | } 14 | var upper bool 15 | if args[0] == "--upper" { 16 | upper = true 17 | args = args[1:] 18 | } 19 | for _, arg := range args { 20 | if nb, err := strconv.Atoi(arg); err != nil || nb < 1 || nb > 26 { 21 | fmt.Print(" ") 22 | } else { 23 | if upper { 24 | nb += 'A' - 1 25 | } else { 26 | nb += 'a' - 1 27 | } 28 | fmt.Printf("%c", rune(nb)) 29 | } 30 | } 31 | fmt.Println() 32 | } 33 | -------------------------------------------------------------------------------- /solutions/notdecimal.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "math" 5 | "strconv" 6 | ) 7 | 8 | func NotDecimal(dec string) string { 9 | j := -1 10 | n := 0 11 | if len(dec) == 0 { 12 | return "\n" 13 | } 14 | for i := 0; i < len(dec); i++ { 15 | if j == -1 && dec[i] == '.' { 16 | j++ 17 | } else if j == 0 { 18 | n++ 19 | } 20 | } 21 | s, err := strconv.ParseFloat(dec, 64) 22 | if err == nil { 23 | return strconv.Itoa(int(s*math.Pow(10, float64(n)))) + "\n" 24 | } 25 | return (dec + "\n") 26 | } 27 | -------------------------------------------------------------------------------- /solutions/nrune.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func NRune(s string, n int) rune { 4 | if n > len(s) || n < 1 { 5 | return 0 6 | } 7 | runes := []rune(s) 8 | return runes[n-1] 9 | } 10 | -------------------------------------------------------------------------------- /solutions/numofdigits.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Numofdigits(n int) int { 4 | var count int = 0 5 | for n > 0 { 6 | n = n / 10 7 | count++ 8 | } 9 | return count 10 | } 11 | -------------------------------------------------------------------------------- /solutions/oddlength.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Oddlength(strings []string) []string { 4 | var newSlice []string 5 | for _, str := range strings { 6 | if len(str)%2 == 1 { 7 | newSlice = append(newSlice, str) 8 | } 9 | } 10 | return newSlice 11 | } 12 | -------------------------------------------------------------------------------- /solutions/only1/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func main() { 6 | z01.PrintRune('1') 7 | } 8 | -------------------------------------------------------------------------------- /solutions/onlya/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Print("a") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/onlyb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func main() { 6 | z01.PrintRune('B') 7 | } 8 | -------------------------------------------------------------------------------- /solutions/onlyf/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func main() { 6 | z01.PrintRune('f') 7 | } 8 | -------------------------------------------------------------------------------- /solutions/onlyz/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Print("z") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/paramcount/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(len(os.Args) - 1) 10 | } 11 | -------------------------------------------------------------------------------- /solutions/paramrange/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "strconv" 5 | import "os" 6 | 7 | func main() { 8 | if len(os.Args) < 3 { 9 | fmt.Println() 10 | return 11 | } 12 | i, err := strconv.Atoi(os.Args[1]) 13 | if err != nil { 14 | fmt.Println("Error") 15 | return 16 | } 17 | var max int = i 18 | var min int = i 19 | for _, arg := range os.Args[1:] { 20 | i, err := strconv.Atoi(arg) 21 | if err != nil { 22 | fmt.Println("Error") 23 | return 24 | } 25 | if i > max { 26 | max = i 27 | } 28 | if i < min { 29 | min = i 30 | } 31 | } 32 | fmt.Println(min, max) 33 | } 34 | -------------------------------------------------------------------------------- /solutions/piglatin/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 2 || os.Args[1] == "" { 11 | return 12 | } 13 | s := os.Args[1] 14 | vowel := strings.IndexAny(s, "aeiouAEIOU") 15 | if vowel == -1 { 16 | fmt.Println("No vowels") 17 | } else { 18 | fmt.Println(string(s[vowel:]) + string(s[:vowel]) + "ay") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /solutions/pilot/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Pilot struct { 6 | Name string 7 | Life float32 8 | Age int 9 | Aircraft int 10 | } 11 | 12 | const Aircraft1 = 1 13 | 14 | func main() { 15 | donnie := Pilot{ 16 | Name: "Donnie", 17 | Life: 100.0, 18 | Age: 24, 19 | Aircraft: Aircraft1, 20 | } 21 | fmt.Println(donnie) 22 | } 23 | -------------------------------------------------------------------------------- /solutions/pingpong/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 2 { 11 | return 12 | } 13 | num, err := strconv.Atoi(os.Args[1]) 14 | if err != nil { 15 | fmt.Println(err.Error()) 16 | return 17 | } 18 | 19 | for i := 0; i < num; i++ { 20 | if i%2 == 0 { 21 | fmt.Println(strconv.Itoa(i) + " ping") 22 | continue 23 | } 24 | fmt.Println(strconv.Itoa(i) + " pong") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /solutions/podiumposition.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func PodiumPosition(podium [][]string) [][]string { 4 | for i, j := 0, len(podium) - 1; i < j; i, j = i + 1, j - 1 { 5 | podium[i], podium[j] = podium[j], podium[i] 6 | } 7 | return podium 8 | } 9 | -------------------------------------------------------------------------------- /solutions/point/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type point struct { 6 | x int 7 | y int 8 | } 9 | 10 | func setPoint(ptr *point) { 11 | ptr.x = 42 12 | ptr.y = 21 13 | } 14 | 15 | func main() { 16 | points := &point{} 17 | 18 | setPoint(points) 19 | 20 | fmt.Printf("x = %d, y = %d", points.x, points.y) 21 | fmt.Println() 22 | } 23 | -------------------------------------------------------------------------------- /solutions/popint.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func PopInt(ints []int) []int { 4 | if len(ints) == 0 { 5 | return ints 6 | } 7 | return ints[:len(ints)-1] 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printalphabet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("abcdefghijklmnopqrstuvwxyz") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printalphabetalt/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") 7 | fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printalphabetalt2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("AbCdEfGhIjKlMnOpQrStUvWxYz") 7 | fmt.Println("ZyXwVuTsRqPoNmLkJiHgFeDcBa") 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printalphabetg/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("abcdefg") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printalt/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("azbycxdwevfugthsirjqkplomn") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printalt2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("zaybxcwdveuftgshriqjpkolnm") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printaltu/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("AZBYCXDWEVFUGTHSIRJQKPLOMN") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printaltu2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("ZAYBXCWDVEUFTGSHRIQJPKOLNM") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printascii/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "os" 5 | 6 | func main() { 7 | args := os.Args 8 | if len(args) != 2 || len(args[1]) != 1 { 9 | return 10 | } 11 | ascii := int(args[1][0]) 12 | if ascii >= 65 && ascii <= 90 || ascii >= 97 && ascii <= 122 { 13 | fmt.Println(ascii) 14 | return 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /solutions/printbits/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 2 { 11 | nbr, _ := strconv.Atoi(os.Args[1]) 12 | printBits(byte(nbr)) 13 | } 14 | } 15 | 16 | func printBits(octe byte) { 17 | fmt.Printf("%08b", octe) 18 | } 19 | -------------------------------------------------------------------------------- /solutions/printcomb.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func PrintComb() { 6 | for i := '0'; i <= '7'; i++ { 7 | for j := i + 1; j <= '8'; j++ { 8 | for k := j + 1; k <= '9'; k++ { 9 | fmt.Printf("%c%c%c", i, j, k) 10 | if i < '7' { 11 | fmt.Print(", ") 12 | } 13 | } 14 | } 15 | } 16 | fmt.Println() 17 | } 18 | -------------------------------------------------------------------------------- /solutions/printcomb2.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func PrintComb2() { 6 | for a := 0; a <= 98; a++ { 7 | for b := a + 1; b <= 99; b++ { 8 | fmt.Printf("%.2d %.2d", a, b) 9 | if a != 98 || b != 99 { 10 | fmt.Print(", ") 11 | } 12 | } 13 | } 14 | fmt.Println() 15 | } 16 | -------------------------------------------------------------------------------- /solutions/printdigits/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("0123456789") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printevenarguments/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) <= 2 { 10 | fmt.Println() 11 | return 12 | } 13 | for i, arg := range os.Args[1:] { 14 | if i%2 != 0 { 15 | fmt.Println(arg) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /solutions/printhex/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 2 { 11 | if i, err := strconv.Atoi(os.Args[1]); err == nil && i >= 0 { 12 | fmt.Printf("%x\n", i) 13 | } else { 14 | fmt.Println("ERROR") 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /solutions/printif.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func PrintIf(arg string) string { 4 | if len(arg) != 0 && len(arg) < 3 { 5 | return "Invalid Input\n" 6 | } 7 | return "G\n" 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printifnot.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func PrintIfNot(arg string) string { 4 | if len(arg) >= 3 { 5 | return "Invalid Input\n" 6 | } else { 7 | return "G\n" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /solutions/printmemory.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func PrintMemory(a [10]byte) { 9 | str := "" 10 | for i, nbr := range a { 11 | fmt.Printf("%.2x", nbr) 12 | 13 | if ((i+1)%4 == 0 && i != 0) || i == len(a)-1 { 14 | fmt.Println() 15 | } else { 16 | fmt.Print(" ") 17 | } 18 | 19 | if nbr >= 33 && nbr <= 126 { 20 | str += string(rune(nbr)) 21 | } else { 22 | str += "." 23 | } 24 | } 25 | fmt.Println(str + strings.Repeat(".", 10-len(a))) 26 | } 27 | -------------------------------------------------------------------------------- /solutions/printmiddle/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) < 2 { 10 | fmt.Println() 11 | return 12 | } 13 | args := os.Args[1:] 14 | 15 | if len(args)%2 == 0 { 16 | fmt.Println(args[len(args)/2-1] + " " + args[len(args)/2]) 17 | } else { 18 | fmt.Println(args[len(args)/2]) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /solutions/printnbr.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func PrintNbr(n int) { 6 | fmt.Print(n) 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printnbrbase.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/weightygroc/go-tests/lib/base" 7 | ) 8 | 9 | func PrintNbrBase(n int, b string) { 10 | if base.IsValid(b) { 11 | length := len(b) 12 | sign := 1 13 | rbase := []rune(b) 14 | if n < 0 { 15 | fmt.Print("-") 16 | sign = -1 17 | } 18 | if n < length && n >= 0 { 19 | fmt.Printf("%c", rbase[n]) 20 | } else { 21 | PrintNbrBase(sign*(n/length), b) 22 | fmt.Printf("%c", rbase[sign*(n%length)]) 23 | } 24 | } else { 25 | fmt.Print("NV") 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /solutions/printnbrinorder.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | ) 7 | 8 | func intToDigits(n int) (digits []int) { 9 | for n > 0 { 10 | if n == 0 { 11 | digits = append(digits, 0) 12 | } else { 13 | digits = append(digits, n%10) 14 | } 15 | n /= 10 16 | } 17 | return 18 | } 19 | 20 | func PrintNbrInOrder(n int) { 21 | if n == 0 { 22 | fmt.Print("0") 23 | return 24 | } 25 | digits := intToDigits(n) 26 | sort.Ints(digits) 27 | for _, i := range digits { 28 | fmt.Printf("%c", rune(i)+'0') 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /solutions/printparams/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | for _, a := range os.Args[1:] { 10 | fmt.Println(a) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solutions/printrange.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "github.com/01-edu/z01" 4 | 5 | func PrintRange(n, m int) { 6 | if n < 0 && m < 0 || n > 9 && m > 9 { 7 | z01.PrintRune('\n') 8 | return 9 | } 10 | if n < 0 { 11 | n = 0 12 | } else if n > 9 { 13 | n = 9 14 | } 15 | if m < 0 { 16 | m = 0 17 | } else if m > 9 { 18 | m = 9 19 | } 20 | if n > m { 21 | for i := n; i >= m; i-- { 22 | z01.PrintRune(rune(i) + '0') 23 | if i != m { 24 | z01.PrintRune(' ') 25 | } 26 | } 27 | } else { 28 | for i := n; i <= m; i++ { 29 | z01.PrintRune(rune(i) + '0') 30 | if i != m { 31 | z01.PrintRune(' ') 32 | } 33 | } 34 | } 35 | z01.PrintRune('\n') 36 | } 37 | -------------------------------------------------------------------------------- /solutions/printrevcomb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | for a := 9; a >= 2; a-- { 7 | for b := a - 1; b >= 1; b-- { 8 | for c := b - 1; c >= 0; c-- { 9 | fmt.Printf("%d%d%d", a, b, c) 10 | if a+b+c != 3 { 11 | fmt.Print(", ") 12 | } 13 | } 14 | } 15 | } 16 | fmt.Println() 17 | } 18 | -------------------------------------------------------------------------------- /solutions/printreversealphabet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("zyxwvutsrqponmlkjihgfedcba") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printreversealphabetalt/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") 7 | fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printreversealphabetalt2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("ZyXwVuTsRqPoNmLkJiHgFeDcBa") 7 | fmt.Println("AbCdEfGhIjKlMnOpQrStUvWxYz") 8 | } 9 | -------------------------------------------------------------------------------- /solutions/printreversealphabetg/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("gfedcba") 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printstr.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func PrintStr(s string) { 6 | fmt.Print(s) 7 | } 8 | -------------------------------------------------------------------------------- /solutions/printwordstables.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func PrintWordsTables(a []string) { 6 | for _, s := range a { 7 | fmt.Println(s) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /solutions/quadchecker/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | ) 8 | 9 | var testCasesMap = map[string]string{ 10 | "o": "[quadA] [1] [1]", 11 | "/": "[quadB] [1] [1]", 12 | "A": "[quadC] [1] [1] || [quadD] [1] [1] || [quadE] [1] [1]", 13 | `A 14 | A`: "[quadD] [2] [1]", 15 | `AA`: "[quadC] [1] [2]", 16 | `A 17 | C`: "[quadD] [2] [1] || [quadE] [2] [1]", 18 | `AC`: "[quadE] [1] [2]", 19 | `o---o 20 | | | 21 | o---o`: "[quadA] [3] [5]", 22 | "0 0": "Not a quad function", 23 | } 24 | 25 | func main() { 26 | info, err := io.ReadAll(os.Stdin) 27 | if err != nil { 28 | panic(err) 29 | } 30 | fmt.Println(testCasesMap[string(info)]) 31 | } 32 | -------------------------------------------------------------------------------- /solutions/quarterofayear.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func QuarterOfAYear(month int) int { 4 | if month < 1 || month > 12 { 5 | return -1 6 | } 7 | return (month + 2) / 3 8 | } 9 | -------------------------------------------------------------------------------- /solutions/range/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 3 { 11 | return 12 | } 13 | a, err := strconv.Atoi(os.Args[1]) 14 | if err != nil { 15 | fmt.Println(err) 16 | return 17 | } 18 | b, err := strconv.Atoi(os.Args[2]) 19 | if err != nil { 20 | fmt.Println(err) 21 | return 22 | } 23 | fmt.Print(a) 24 | for b != a { 25 | if a < b { 26 | a++ 27 | } else { 28 | a-- 29 | } 30 | fmt.Print(" ", a) 31 | } 32 | fmt.Println() 33 | } 34 | -------------------------------------------------------------------------------- /solutions/rectperimeter.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func RectPerimeter(w, h int) int { 4 | if (w < 0) || (h < 0) { 5 | return -1 6 | } 7 | 8 | return 2 * (w + h) 9 | } 10 | -------------------------------------------------------------------------------- /solutions/recursivefactorial.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func RecursiveFactorial(nb int) int { 4 | limit := 20 5 | if nb < 0 || nb > limit { 6 | return 0 7 | } 8 | if nb == 0 { 9 | return 1 10 | } 11 | return nb * RecursiveFactorial(nb-1) 12 | } 13 | -------------------------------------------------------------------------------- /solutions/recursivepower.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "math" 4 | 5 | func RecursivePower(nb, power int) int { 6 | if power < 0 { 7 | return 0 8 | } 9 | return int(math.Pow(float64(nb), float64(power))) 10 | } 11 | -------------------------------------------------------------------------------- /solutions/reduceint.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "fmt" 4 | 5 | func ReduceInt(a []int, f func(int, int) int) { 6 | acc := a[0] 7 | for i := 1; i < len(a); i++ { 8 | acc = f(acc, a[i]) 9 | } 10 | fmt.Println(acc) 11 | } 12 | -------------------------------------------------------------------------------- /solutions/removeduplicate.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func contains(slice []int, num int) bool { 4 | for _, v := range slice { 5 | if v == num { 6 | return true 7 | } 8 | } 9 | return false 10 | } 11 | 12 | func RemoveDuplicate(slice []int) []int { 13 | if len(slice) == 0 { 14 | return slice 15 | } 16 | newSlice := []int{} 17 | for _, v := range slice { 18 | if !contains(newSlice, v) { 19 | newSlice = append(newSlice, v) 20 | } 21 | } 22 | return newSlice 23 | } 24 | -------------------------------------------------------------------------------- /solutions/removeodd.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func RemoveOdd(str string) string { 4 | var result string 5 | for i:=0; i 2 { 12 | } else { 13 | lenString := len(os.Args[1]) 14 | for i := 0; i < lenString; i++ { 15 | if os.Args[1][i] != 97 { 16 | if counter == lenString-1 { 17 | fmt.Print("!(Contains the letter)\n") 18 | break 19 | } 20 | counter++ 21 | 22 | } else if os.Args[1][i] == 97 { 23 | fmt.Print("Contains the letter\n") 24 | break 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solutions/revargs/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) < 2 { 10 | fmt.Println() 11 | return 12 | } 13 | for i := len(os.Args) - 1; i >= 1; i-- { 14 | fmt.Print(os.Args[i]) 15 | if i != 1 { 16 | fmt.Print(" ") 17 | } 18 | } 19 | fmt.Println() 20 | } 21 | -------------------------------------------------------------------------------- /solutions/revconcatalternate.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func RevConcatAlternate(slice1, slice2 []int) []int { 4 | len1 := len(slice1) 5 | len2 := len(slice2) 6 | maxLen := len1 7 | result := make([]int, 0, len1+len2) 8 | 9 | if len2 > maxLen { 10 | maxLen = len2 11 | } 12 | 13 | for i := maxLen; i >= 0; i-- { 14 | if i < len1 { 15 | result = append(result, slice1[i]) 16 | } 17 | if i < len2 { 18 | result = append(result, slice2[i]) 19 | } 20 | } 21 | 22 | return result 23 | } 24 | -------------------------------------------------------------------------------- /solutions/reversemenuindex.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ReverseMenuIndex(menu []string) []string { 4 | menuLen := len(menu) 5 | output := make([]string, menuLen) 6 | 7 | for i, n := range menu { 8 | j := menuLen - i - 1 9 | 10 | output[j] = n 11 | } 12 | return output 13 | } 14 | -------------------------------------------------------------------------------- /solutions/reverserange/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 3 { 11 | return 12 | } 13 | a, err := strconv.Atoi(os.Args[1]) 14 | if err != nil { 15 | fmt.Println(err) 16 | return 17 | } 18 | b, err := strconv.Atoi(os.Args[2]) 19 | if err != nil { 20 | fmt.Println(err) 21 | return 22 | } 23 | fmt.Print(b) 24 | for a != b { 25 | if b < a { 26 | b++ 27 | } else { 28 | b-- 29 | } 30 | fmt.Print(" ", b) 31 | } 32 | fmt.Println() 33 | } 34 | -------------------------------------------------------------------------------- /solutions/reversesecondhalf.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ReverseSecondHalf(str string) string { 4 | if len(str) == 0 { 5 | return "Invalid Output\n" 6 | } else if len(str) == 1 { 7 | return (str + "\n") 8 | } else { 9 | res := "" 10 | i := 0 11 | for i = len(str) - 1; i >= int(len(str)/2); i-- { 12 | res += string(str[i]) 13 | } 14 | res += "\n" 15 | return res 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /solutions/reversestrcap/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "unicode" 7 | ) 8 | 9 | func main() { 10 | for _, arg := range os.Args[1:] { 11 | arg := []rune(arg) 12 | for j, r := range arg { 13 | if j+1 == len(arg) || arg[j+1] == ' ' { 14 | arg[j] = unicode.ToUpper(r) 15 | } else { 16 | arg[j] = unicode.ToLower(r) 17 | } 18 | } 19 | fmt.Println(string(arg)) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solutions/reversestrings.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ReverseStrings(arr []string) string { 4 | var reversed string 5 | for i := len(arr) - 1; i >= 0; i-- { 6 | for j := len(arr[i]) - 1; j >= 0; j-- { 7 | reversed += string(arr[i][j]) 8 | } 9 | if i != 0 && len(reversed) != 0 { 10 | reversed += " " 11 | } 12 | } 13 | return reversed 14 | } 15 | -------------------------------------------------------------------------------- /solutions/revparams/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | for i := len(os.Args) - 1; i >= 1; i-- { 10 | fmt.Println(os.Args[i]) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solutions/revwstr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 2 { 11 | a := strings.Split(os.Args[1], " ") 12 | for i := len(a) - 1; i >= 0; i-- { 13 | fmt.Print(a[i]) 14 | if i != 0 { 15 | fmt.Print(" ") 16 | } 17 | } 18 | fmt.Println() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /solutions/rockandroll.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func RockAndRoll(n int) string { 4 | if n < 0 { 5 | return "error: number is negative\n" 6 | } 7 | 8 | if (n%2 == 0) && (n%3 == 0) { 9 | return "rock and roll\n" 10 | } 11 | if n%2 == 0 { 12 | return "rock\n" 13 | } 14 | if n%3 == 0 { 15 | return "roll\n" 16 | } 17 | return "error: non divisible\n" 18 | } 19 | -------------------------------------------------------------------------------- /solutions/rostring/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func deleteExtraSpaces(a []string) []string { 10 | var res []string 11 | for _, v := range a { 12 | if v != "" { 13 | res = append(res, v) 14 | } 15 | } 16 | return res 17 | } 18 | 19 | func main() { 20 | if len(os.Args) == 2 { 21 | words := strings.Split(os.Args[1], " ") 22 | words = deleteExtraSpaces(words) 23 | if len(words) >= 1 { 24 | for _, v := range words[1:] { 25 | fmt.Print(v, " ") 26 | } 27 | fmt.Print(words[0]) 28 | } 29 | } 30 | fmt.Println() 31 | } 32 | -------------------------------------------------------------------------------- /solutions/rot13/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) == 2 { 10 | for _, r := range os.Args[1] { 11 | if r >= 'a' && r <= 'z' { 12 | if r >= 'a'+13 { 13 | r -= 13 14 | } else { 15 | r += 13 16 | } 17 | } else if r >= 'A' && r <= 'Z' { 18 | if r >= 'A'+13 { 19 | r -= 13 20 | } else { 21 | r += 13 22 | } 23 | } 24 | fmt.Printf("%c", r) 25 | } 26 | fmt.Println() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /solutions/rot14.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Rot14(s string) (result string) { 4 | for _, r := range s { 5 | if r >= 'a' && r <= 'z' { 6 | if r >= 'm' { 7 | r -= 12 8 | } else { 9 | r += 14 10 | } 11 | } else if r >= 'A' && r <= 'Z' { 12 | if r >= 'M' { 13 | r -= 12 14 | } else { 15 | r += 14 16 | } 17 | } 18 | result += string(r) 19 | } 20 | return result 21 | } 22 | -------------------------------------------------------------------------------- /solutions/saveandmiss.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SaveAndMiss(arg string, num int) string { 4 | if num <= 0 || num > len(arg) { 5 | return string(arg) 6 | } 7 | _str := "" 8 | for i := 0; i < len(arg); i++ { 9 | if i != 0 && i%num == 0 { 10 | i += num 11 | if i > len(arg)-1 { 12 | break 13 | } 14 | } 15 | if i != len(arg) { 16 | _str += string(rune(arg[i])) 17 | } 18 | } 19 | return _str 20 | } 21 | -------------------------------------------------------------------------------- /solutions/searchreplace/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 4 { 11 | fmt.Println(strings.Map(func(r rune) rune { 12 | if r == []rune(os.Args[2])[0] { 13 | return []rune(os.Args[3])[0] 14 | } 15 | return r 16 | }, os.Args[1])) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /solutions/secondhalf.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SecondHalf(slice []int) []int { 4 | var result []int 5 | start := len(slice) / 2 6 | 7 | for i := start; i < len(slice); i++ { 8 | result = append(result, slice[i]) 9 | } 10 | return result 11 | } 12 | -------------------------------------------------------------------------------- /solutions/setspace.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SetSpace(str string) string { 4 | res := "" 5 | for i := 0; i < len(str); i++ { 6 | if str[i] >= 'A' && str[i] <= 'Z' && i != 0 { 7 | res += " " + string(str[i]) 8 | } else if str[i] >= 'a' && str[i] <= 'z' && i != 0 || i == 0 && str[i] >= 'A' && str[i] <= 'Z' { 9 | res += string(str[i]) 10 | } else { 11 | return "Error" 12 | } 13 | } 14 | return res 15 | } 16 | -------------------------------------------------------------------------------- /solutions/shoppinglistsort.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func ShoppingListSort(slice []string) []string { 4 | for i := 0; i < len(slice)-1; i++ { 5 | for j := 0; j < len(slice)-i-1; j++ { 6 | if len(slice[j]) > len(slice[j+1]) { 7 | slice[j], slice[j+1] = slice[j+1], slice[j] 8 | } 9 | } 10 | } 11 | return slice 12 | } 13 | -------------------------------------------------------------------------------- /solutions/shoppingsummarycounter.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func ShoppingSummaryCounter(str string) map[string]int { 6 | wordList := strings.Split(str, " ") 7 | counts := make(map[string]int) 8 | for _, word := range wordList { 9 | _, ok := counts[word] 10 | if ok { 11 | counts[word] += 1 12 | } else { 13 | counts[word] = 1 14 | } 15 | } 16 | return counts 17 | } 18 | -------------------------------------------------------------------------------- /solutions/sliceadd.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SliceAdd(slice []int, num int) []int { 4 | if len(slice) == 0 { 5 | return []int{num} 6 | } 7 | slice = append(slice, num) 8 | return slice 9 | } 10 | -------------------------------------------------------------------------------- /solutions/sliceremove.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SliceRemove(slice []int, num int) []int { 4 | newSlice := []int{} 5 | for _, v := range slice { 6 | if v != num { 7 | newSlice = append(newSlice, v) 8 | } 9 | } 10 | return newSlice 11 | } 12 | -------------------------------------------------------------------------------- /solutions/sortedlistmerge.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SortedListMerge(l1 *NodeI, l2 *NodeI) *NodeI { 4 | if l1 == nil { 5 | return l2 6 | } 7 | if l2 == nil { 8 | return l1 9 | } 10 | if l1.Data <= l2.Data { 11 | l1.Next = SortedListMerge(l1.Next, l2) 12 | return l1 13 | } 14 | l2.Next = SortedListMerge(l1, l2.Next) 15 | return l2 16 | } 17 | -------------------------------------------------------------------------------- /solutions/sortlistinsert.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | // structures for the linked lists 4 | type NodeI struct { 5 | Data int 6 | Next *NodeI 7 | } 8 | 9 | func SortListInsert(l *NodeI, data_ref int) *NodeI { 10 | n := &NodeI{Data: data_ref} 11 | n.Next = nil 12 | 13 | if l == nil || l.Data >= n.Data { 14 | n.Next = l 15 | return n 16 | } 17 | temp := l 18 | for temp.Next != nil && temp.Next.Data < n.Data { 19 | temp = temp.Next 20 | } 21 | n.Next = temp.Next 22 | temp.Next = n 23 | 24 | return l 25 | } 26 | -------------------------------------------------------------------------------- /solutions/sortparams/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "sort" 7 | ) 8 | 9 | func main() { 10 | args := os.Args[1:] 11 | sort.Strings(args) 12 | for _, v := range args { 13 | fmt.Println(v) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /solutions/split.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var Split = strings.Split 6 | -------------------------------------------------------------------------------- /solutions/splitwhitespaces.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var SplitWhiteSpaces = strings.Fields 6 | -------------------------------------------------------------------------------- /solutions/sqrt.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "math" 4 | 5 | func Sqrt(value int) int { 6 | sr := math.Sqrt(float64(value)) 7 | if math.Mod(sr, 1) == 0 { 8 | return int(sr) 9 | } 10 | return 0 11 | } 12 | -------------------------------------------------------------------------------- /solutions/squareroot.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SquareRoot(number int) int { 4 | if number == 1 { 5 | return 1 6 | } 7 | if number >= 0 { 8 | var sqrt float32 = float32(number / 2) 9 | var temp float32 = 0.0 10 | for sqrt != temp { 11 | temp = sqrt 12 | sqrt = float32((float32(number)/temp + temp) / 2) 13 | } 14 | return int(sqrt) 15 | } 16 | return -1 17 | } 18 | -------------------------------------------------------------------------------- /solutions/stringtobool.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func StringToBool(s string) bool { 4 | if s == "True" || s == "T" || s == "t" { 5 | return true 6 | } 7 | return false 8 | } 9 | -------------------------------------------------------------------------------- /solutions/stringtointslice.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func StringToIntSlice(str string) []int { 4 | runes := []rune(str) 5 | 6 | var result []int 7 | 8 | for i := 0; i < len(runes); i++ { 9 | result = append(result, int(runes[i])) 10 | } 11 | return result 12 | } 13 | -------------------------------------------------------------------------------- /solutions/strisnegative.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func StrisNegative(str string) { 9 | if len(str) > 0 { 10 | val, err := strconv.Atoi(str) 11 | if err != nil { 12 | fmt.Println("!") 13 | } else { 14 | if val < 0 { 15 | fmt.Println("N") 16 | } else if val == 0 { 17 | fmt.Println("0") 18 | } else { 19 | fmt.Println("P") 20 | } 21 | } 22 | } else { 23 | fmt.Println("!") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/strlen.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func StrLen(s string) int { 4 | return len([]rune(s)) 5 | } 6 | -------------------------------------------------------------------------------- /solutions/strrev.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func StrRev(s string) string { 4 | runes := []rune(s) 5 | i := 0 6 | j := len(runes) - 1 7 | for i < j { 8 | runes[i], runes[j] = runes[j], runes[i] 9 | i++ 10 | j-- 11 | } 12 | return string(runes) 13 | } 14 | -------------------------------------------------------------------------------- /solutions/sum.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | func Sum(a, b string) int { 8 | numA, _ := strconv.Atoi(a) 9 | numB, _ := strconv.Atoi(b) 10 | if numA > 9 || numA < -9 || numB > 9 || numB < -9 { 11 | return 0 12 | } 13 | return numA + numB 14 | } 15 | -------------------------------------------------------------------------------- /solutions/sumarray.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SumArray(array []int) int { 4 | var sum int = 0 5 | for _, v := range array { 6 | sum += v 7 | } 8 | return sum 9 | } 10 | -------------------------------------------------------------------------------- /solutions/sumascii/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) != 2 { 10 | fmt.Println(0) 11 | return 12 | } 13 | var result byte 14 | for _, byte := range []byte(os.Args[1]) { 15 | result += byte 16 | } 17 | fmt.Println(result) 18 | } 19 | -------------------------------------------------------------------------------- /solutions/sumthemall/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | const ( 10 | MaxUint = ^uint(0) 11 | MinUint = 0 12 | MaxInt = int(MaxUint >> 1) 13 | MinInt = -MaxInt - 1 14 | ) 15 | 16 | func main() { 17 | if len(os.Args) < 2 { 18 | fmt.Println(0) 19 | return 20 | } 21 | result := 0 22 | for _, arg := range os.Args[1:] { 23 | num, err := strconv.Atoi(arg) 24 | if num >= MaxInt || num <= MinInt || err != nil { 25 | fmt.Println(0) 26 | return 27 | } 28 | result += num 29 | } 30 | fmt.Println(result) 31 | } 32 | -------------------------------------------------------------------------------- /solutions/swapargs/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | if len(os.Args) != 3 { 10 | fmt.Println("") 11 | return 12 | } 13 | fmt.Println(os.Args[2] + " " + os.Args[1]) 14 | } 15 | -------------------------------------------------------------------------------- /solutions/swapfirst.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SwapFirst(slice []int) []int { 4 | dst := make([]int, len(slice)) 5 | copy(dst, slice) 6 | 7 | if len(dst) < 2 { 8 | return dst 9 | } 10 | dst[0], dst[1] = dst[1], dst[0] 11 | return dst 12 | } 13 | -------------------------------------------------------------------------------- /solutions/swaplast.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func SwapLast(slice []int) []int { 4 | dst := make([]int, len(slice)) 5 | copy(dst, slice) 6 | 7 | if len(dst) < 2 { 8 | return dst 9 | } 10 | dst[len(dst)-1], dst[len(dst)-2] = dst[len(dst)-2], dst[len(dst)-1] 11 | return dst 12 | } 13 | -------------------------------------------------------------------------------- /solutions/switchcase/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "unicode" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 2 { 11 | runes := []rune(os.Args[1]) 12 | for i, r := range runes { 13 | if unicode.IsLower(r) { 14 | runes[i] = unicode.ToUpper(r) 15 | } else if unicode.IsUpper(r) { 16 | runes[i] = unicode.ToLower(r) 17 | } 18 | } 19 | fmt.Println(string(runes)) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /solutions/tabmult/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | ) 8 | 9 | func tabmul(nbr int) { 10 | i := 1 11 | for i < 10 { 12 | result := nbr * i 13 | fmt.Println(i, "x", nbr, "=", result) 14 | i++ 15 | } 16 | } 17 | 18 | func main() { 19 | if len(os.Args) == 2 { 20 | number, _ := strconv.Atoi(os.Args[1]) 21 | tabmul(number) 22 | } else { 23 | fmt.Println() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 2 { 11 | fmt.Println("usage: ./fillit filename") 12 | return 13 | } 14 | data, err := ioutil.ReadFile(os.Args[1]) 15 | if err != nil { 16 | fmt.Println(err) 17 | return 18 | } 19 | ok, tetriminos := validateFile(data) 20 | if !ok { 21 | fmt.Println("ERROR") 22 | return 23 | } 24 | board := solve(tetriminos) 25 | board.print() 26 | } 27 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/bad00.txt: -------------------------------------------------------------------------------- 1 | #### 2 | ...# 3 | .... 4 | .... 5 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/bad01.txt: -------------------------------------------------------------------------------- 1 | ...# 2 | ..#. 3 | .#.. 4 | #... 5 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/bad02.txt: -------------------------------------------------------------------------------- 1 | 2 | ##... 3 | ##... 4 | .... 5 | .... 6 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/bad03.txt: -------------------------------------------------------------------------------- 1 | .... 2 | .... 3 | .... 4 | .... 5 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/bad04.txt: -------------------------------------------------------------------------------- 1 | 2 | ..## 3 | .... 4 | .... 5 | ##.. 6 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/badFormat.txt: -------------------------------------------------------------------------------- 1 | ...# 2 | ...# 3 | ...# 4 | ...# 5 | .... 6 | .... 7 | .... 8 | #### 9 | 10 | 11 | .### 12 | ...# 13 | .... 14 | .... 15 | 16 | .... 17 | ..## 18 | .##. 19 | .... 20 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_01-1-2-0.00.txt: -------------------------------------------------------------------------------- 1 | ..## 2 | ..## 3 | .... 4 | .... 5 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_02-1-4-0.00.txt: -------------------------------------------------------------------------------- 1 | #... 2 | #... 3 | #... 4 | #... 5 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_03-2-4-0.00.txt: -------------------------------------------------------------------------------- 1 | .... 2 | ..#. 3 | .### 4 | .... 5 | 6 | .... 7 | .... 8 | ...# 9 | .### 10 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_04-6-6-0.00.txt: -------------------------------------------------------------------------------- 1 | .##. 2 | .##. 3 | .... 4 | .... 5 | 6 | ..## 7 | ..## 8 | .... 9 | .... 10 | 11 | ..## 12 | ..## 13 | .... 14 | .... 15 | 16 | .... 17 | ...# 18 | ..## 19 | ...# 20 | 21 | .... 22 | .... 23 | ##.. 24 | ##.. 25 | 26 | .... 27 | .... 28 | .... 29 | #### 30 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_09-11-7-0.07.txt: -------------------------------------------------------------------------------- 1 | .##. 2 | ##.. 3 | .... 4 | .... 5 | 6 | .#.. 7 | .#.. 8 | ##.. 9 | .... 10 | 11 | .... 12 | .... 13 | .##. 14 | ##.. 15 | 16 | ...# 17 | ...# 18 | ..## 19 | .... 20 | 21 | ..#. 22 | ###. 23 | .... 24 | .... 25 | 26 | ...# 27 | ...# 28 | ..## 29 | .... 30 | 31 | .... 32 | .... 33 | .##. 34 | .##. 35 | 36 | .... 37 | .#.. 38 | .#.. 39 | ##.. 40 | 41 | .... 42 | .... 43 | ...# 44 | .### 45 | 46 | .... 47 | .... 48 | ##.. 49 | ##.. 50 | 51 | .... 52 | .##. 53 | ##.. 54 | .... 55 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_10-12-7-0.52.txt: -------------------------------------------------------------------------------- 1 | ##.. 2 | .##. 3 | .... 4 | .... 5 | 6 | .... 7 | .... 8 | .##. 9 | .##. 10 | 11 | .#.. 12 | ##.. 13 | #... 14 | .... 15 | 16 | .... 17 | .#.. 18 | .### 19 | .... 20 | 21 | .... 22 | ..#. 23 | ..#. 24 | ..## 25 | 26 | .#.. 27 | .##. 28 | ..#. 29 | .... 30 | 31 | .... 32 | .... 33 | ##.. 34 | .##. 35 | 36 | ##.. 37 | .##. 38 | .... 39 | .... 40 | 41 | .... 42 | ##.. 43 | ##.. 44 | .... 45 | 46 | ...# 47 | ...# 48 | ..## 49 | .... 50 | 51 | ##.. 52 | #... 53 | #... 54 | .... 55 | 56 | .... 57 | ...# 58 | ..## 59 | ..#. 60 | -------------------------------------------------------------------------------- /solutions/tetrisoptimizer/samples/good_11-12-8-0.83.txt: -------------------------------------------------------------------------------- 1 | #... 2 | ##.. 3 | #... 4 | .... 5 | 6 | ###. 7 | ..#. 8 | .... 9 | .... 10 | 11 | ..## 12 | ..## 13 | .... 14 | .... 15 | 16 | .... 17 | .... 18 | .### 19 | ...# 20 | 21 | .... 22 | ##.. 23 | ##.. 24 | .... 25 | 26 | .... 27 | .... 28 | #... 29 | ###. 30 | 31 | .... 32 | .### 33 | .#.. 34 | .... 35 | 36 | .... 37 | .### 38 | ...# 39 | .... 40 | 41 | ..## 42 | ..## 43 | .... 44 | .... 45 | 46 | .... 47 | .... 48 | ..## 49 | ..## 50 | 51 | .... 52 | .... 53 | ..## 54 | ..## 55 | 56 | .... 57 | ..## 58 | ..## 59 | .... 60 | -------------------------------------------------------------------------------- /solutions/thirdtimeisacharm.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func ThirdTimeIsACharm(arg string) string { 6 | if arg == "" || len(arg) < 3 { 7 | return "\n" 8 | } 9 | var str strings.Builder 10 | for i := 0; i < len(arg); i++ { 11 | if i == 0 { 12 | continue 13 | } 14 | j := i + 1 15 | if j%3 == 0 { 16 | str.WriteRune(rune(arg[i])) 17 | } 18 | } 19 | str.WriteRune(rune('\n')) 20 | return (str.String()) 21 | } 22 | -------------------------------------------------------------------------------- /solutions/tolower.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var ToLower = strings.ToLower 6 | -------------------------------------------------------------------------------- /solutions/toupper.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | var ToUpper = strings.ToUpper 6 | -------------------------------------------------------------------------------- /solutions/trimatoi.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | func TrimAtoi(s string) int { 8 | var s2 string 9 | for _, r := range s { 10 | if (r >= '0' && r <= '9') || (r == '-' && s2 == "") { 11 | s2 += string(r) 12 | } 13 | } 14 | a, _ := strconv.Atoi(s2) 15 | return a 16 | } 17 | -------------------------------------------------------------------------------- /solutions/twosum.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func TwoSum(nums []int, target int) []int { 4 | for i := 0; i < len(nums); i++ { 5 | for j := i + 1; j < len(nums); j++ { 6 | if nums[i]+nums[j] == target { 7 | return []int{i, j} 8 | } 9 | } 10 | } 11 | return nil 12 | } 13 | -------------------------------------------------------------------------------- /solutions/union/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) == 3 { 11 | var res string 12 | s1 := os.Args[1] 13 | s2 := os.Args[2] 14 | 15 | for _, v := range s1 { 16 | if !strings.ContainsRune(res, v) { 17 | res += string(v) 18 | } 19 | } 20 | for _, v := range s2 { 21 | if !strings.ContainsRune(res, v) { 22 | res += string(v) 23 | } 24 | } 25 | fmt.Print(res) 26 | } 27 | fmt.Println() 28 | } 29 | -------------------------------------------------------------------------------- /solutions/unmatch.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func Unmatch(elems []int) int { 4 | var quant int 5 | for _, el := range elems { 6 | quant = 0 7 | for _, v := range elems { 8 | if v == el { 9 | quant++ 10 | } 11 | } 12 | if quant%2 != 0 { 13 | return el 14 | } 15 | } 16 | return -1 17 | } 18 | -------------------------------------------------------------------------------- /solutions/vowelsindex.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | func VowelsIndex(str string) []int { 4 | var res []int 5 | k := 0 6 | for i := 0; i < len(str); i++ { 7 | if str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U' { 8 | j := i 9 | if j < len(str) { 10 | res = append(res, j) 11 | k++ 12 | } 13 | } 14 | } 15 | return res 16 | } 17 | -------------------------------------------------------------------------------- /solutions/wdmatch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func ok(s1 string, s2 string) bool { 9 | runes1 := []rune(s1) 10 | runes2 := []rune(s2) 11 | var rest string 12 | count := 0 13 | for i := 0; i < len(runes1); i++ { 14 | for j := count; j < len(runes2); j++ { 15 | if runes1[i] == runes2[j] { 16 | rest += string(runes1[i]) 17 | j = len(runes2) - 1 18 | } 19 | count++ 20 | } 21 | } 22 | return s1 == rest 23 | } 24 | 25 | func main() { 26 | if len(os.Args) == 3 { 27 | if ok(os.Args[1], os.Args[2]) { 28 | fmt.Println(os.Args[1]) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /solutions/weareunique.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func WeAreUnique(str1 string, str2 string) int { 6 | var used [127]int 7 | if str1 == "" && str2 == "" { 8 | return -1 9 | } 10 | var argv []string = []string{str1, str2} 11 | k := 0 12 | i := 0 13 | for i < 2 { 14 | j := 0 15 | for j < len(argv[i]) { 16 | if used[argv[i][j]] == 0 && !strings.Contains(argv[1-i], string(argv[i][j])) { 17 | used[argv[i][j]] = 1 18 | k++ 19 | } 20 | j++ 21 | } 22 | i++ 23 | } 24 | return k 25 | } 26 | -------------------------------------------------------------------------------- /solutions/wordflip.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strings" 4 | 5 | func WordFlip(arg string) string { 6 | if arg == "" { 7 | return "Invalid Output\n" 8 | } 9 | var str []string = strings.Split(arg, " ") 10 | _len := len(str) 11 | var str1 string 12 | for i := _len - 1; i >= 0; i-- { 13 | if len(str[i]) != 0 { 14 | str1 += str[i] 15 | } 16 | if i > 0 && len(str[i-1]) != 0 { 17 | str1 += " " 18 | } 19 | } 20 | return (strings.TrimSpace(str1) + "\n") 21 | } 22 | -------------------------------------------------------------------------------- /solutions/zipstring.go: -------------------------------------------------------------------------------- 1 | package solutions 2 | 3 | import "strconv" 4 | 5 | func countDuplication(s string, i int) int { 6 | var count int = 0 7 | for _, v := range s[i:] { 8 | if v == rune(s[i]) { 9 | count++ 10 | } else { 11 | break 12 | } 13 | } 14 | return count 15 | } 16 | 17 | func ZipString(s string) string { 18 | var result string 19 | i := 0 20 | for i < len(s) { 21 | counter := countDuplication(s, i) 22 | result = result + strconv.Itoa(counter) + string(s[i]) 23 | i += int(counter) 24 | } 25 | return result 26 | } 27 | -------------------------------------------------------------------------------- /test_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #set -euo pipefail 4 | IFS=' 5 | ' 6 | # clear the student folder go binary cache 7 | # Fix for mac and linux temp directories 8 | if [ -z "$TMPDIR" ]; then 9 | # Linux 10 | rm -rf /tmp/binaries/student/ 11 | else 12 | # Mac 13 | rm -rf $TMPDIR/binaries/student/ 14 | fi 15 | # End of fix 16 | 17 | for dir in ./tests/*; do 18 | echo "$dir executed" 19 | if ! go run "$dir"; then 20 | echo "$dir FAILED" 21 | fi 22 | done 23 | -------------------------------------------------------------------------------- /test_one.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | IFS=' 4 | ' 5 | 6 | if [ -z "$1" ]; then 7 | echo "No folder supplied" 8 | exit 1 9 | else 10 | testFile="./tests/$1_test/main.go" 11 | if test -f "$testFile"; then 12 | # Fix for mac and linux temp directories 13 | if [ -z "$TMPDIR" ]; then 14 | # Linux 15 | rm -rf /tmp/binaries/student/ 16 | else 17 | # Mac 18 | rm -rf $TMPDIR/binaries/student/ 19 | fi 20 | # End of fix 21 | go run $testFile 22 | echo "$1 test executed!" 23 | else 24 | echo "Error: $testFile does not exist." 25 | fi 26 | fi 27 | -------------------------------------------------------------------------------- /tests/abort_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | arg := random.IntSlice() 13 | arg = append(arg, random.Int()) 14 | for i := 0; i < 15; i++ { 15 | challenge.Function("Abort", student.Abort, solutions.Abort, arg[0], arg[1], arg[2], arg[3], arg[4]) 16 | arg = random.IntSlice() 17 | arg = append(arg, random.Int()) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/activebits_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | args := []int{random.IntBetween(2, 20)} 13 | args = append(args, random.IntSliceBetween(2, 20)...) 14 | args = append(args, random.IntSliceBetween(2, 20)...) 15 | 16 | for _, v := range args { 17 | challenge.Function("ActiveBits", student.ActiveBits, solutions.ActiveBits, v) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/addfront_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]string{ 12 | {"", "a", "b", "c"}, 13 | {"a", "b", "c", "d"}, 14 | {"Hello", "World", "!"}, 15 | {"Hello", "World", "!"}, 16 | {"Hello", ""}, 17 | {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 18 | } 19 | for _, arg := range table { 20 | challenge.Function("AddFront", student.AddFront, solutions.AddFront, arg[0], arg[1:]) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/addifpositive_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]int{ 12 | {10, 10}, 13 | {-10, -10}, 14 | {0, 0}, 15 | {1, 1}, 16 | {-1, 20}, 17 | {23, 2}, 18 | {3, 0}, 19 | {0, 39}, 20 | } 21 | for _, arg := range table { 22 | challenge.Function("AddIfPositive", student.AddIfPositive, solutions.AddIfPositive, arg[0], arg[1]) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/alphacount_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | args := []string{ 14 | " ", 15 | "Hello 78 World! 4455 /", 16 | } 17 | for i := 0; i < 7; i++ { 18 | args = append(args, random.Str(chars.ASCII, random.IntBetween(5, 20))) 19 | } 20 | 21 | for _, arg := range args { 22 | challenge.Function("AlphaCount", student.AlphaCount, solutions.AlphaCount, arg) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/alphamirror_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := [][]string{ 11 | {""}, 12 | {"One", "ring!"}, 13 | {"testing spaces and #!*"}, 14 | {"more", "than", "three", "arguments"}, 15 | {"Upper anD LoWer cAsE"}, 16 | {random.Str(chars.Words, 13)}, 17 | } 18 | 19 | for _, v := range args { 20 | challenge.Program("alphamirror", v...) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/alphaposition_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []rune{ 12 | 'a', 13 | 'A', 14 | 'z', 15 | 'Z', 16 | '0', 17 | '9', 18 | '!', 19 | 'B', 20 | '@', 21 | 'b', 22 | 'c', 23 | 'd', 24 | } 25 | 26 | for _, arg := range args { 27 | challenge.Function("AlphaPosition", student.AlphaPosition, solutions.AlphaPosition, arg) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/argrotn_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {""}, 10 | {"1", "One", "ring!"}, 11 | {"2", "testing spaces and #!*"}, 12 | {"3", "more", "than", "three", "arguments"}, 13 | {"10", "Upper anD LoWer cAsE"}, 14 | {"0", "Hello", "World", "everyOne"}, 15 | {"-1", "Hello", "World", "everyOne"}, 16 | {"4", "Hello", "World", "everyOne"}, 17 | } 18 | 19 | for _, v := range args { 20 | challenge.Program("argrotn", v...) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/argsort_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"abc"}, 10 | {"abc", "def"}, 11 | {"125"}, 12 | {"125", "wde"}, 13 | {"def"}, 14 | {""}, 15 | {"123qa"}, 16 | {" HELLO!"}, 17 | {" kowz"}, 18 | {"a b c"}, 19 | {" abc"}, 20 | {" hello"}, 21 | {"hello "}, 22 | {"sto ry"}, 23 | {" @\\!\\n"}, 24 | {"9^_\\`abc"}, 25 | {" \n"}, 26 | {"\t\v\n"}, 27 | {"%Hey|}"}, 28 | {"123 $_$%d"}, 29 | } 30 | for _, v := range args { 31 | challenge.Program("argsort", v...) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/basicatoi_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | student "student" 7 | 8 | "github.com/weightygroc/go-tests/lib/challenge" 9 | "github.com/weightygroc/go-tests/lib/random" 10 | "github.com/weightygroc/go-tests/solutions" 11 | ) 12 | 13 | func main() { 14 | args := make([]string, 30) 15 | for i := range args { 16 | args[i] = strconv.Itoa(random.IntBetween(0, random.MaxInt)) 17 | } 18 | args = append(args, 19 | strconv.Itoa(random.MaxInt), 20 | "0", 21 | "12345", 22 | "0000012345", 23 | "000000", 24 | ) 25 | for _, arg := range args { 26 | challenge.Function("BasicAtoi", student.BasicAtoi, solutions.BasicAtoi, arg) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/betweenus_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3}, 13 | {1, 1, 2}, 14 | {10, 20, 30}, 15 | {20, 10, 30}, 16 | {200, 100, 300}, 17 | {-1, 0, 1}, 18 | // make sure that the function works with negative numbers 19 | {-1, -1, 0}, 20 | {-1, -20, 0}, 21 | {-1, -20, -10}, 22 | } 23 | 24 | for _, arg := range args { 25 | challenge.Function("Concat", student.BetweenUs, solutions.BetweenUs, arg[0], arg[1], arg[2]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/bezero_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3}, 13 | {1, 1, 2}, 14 | {10, 20, 30}, 15 | {20, 10, 30}, 16 | {200, 100, 300}, 17 | {-1, 0, 1}, 18 | {-1, -1, 0}, 19 | {-1, -20, 0}, 20 | {-1, -20, -10}, 21 | {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, 22 | {}, 23 | } 24 | 25 | for _, arg := range args { 26 | challenge.Function("BeZero", student.BeZero, solutions.BeZero, arg) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/binaryaddition_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]int{ 12 | {1, 1}, 13 | {0, 0}, 14 | {4, 2}, 15 | {7, 3}, 16 | {2, -1}, 17 | {-1, 1}, 18 | {3, 4}, 19 | {-1, -1}, 20 | {100, 303}, 21 | {2147483647, -2147483648}, 22 | } 23 | for _, arg := range table { 24 | challenge.Function("BinaryAddition", student.BinaryAddition, solutions.BinaryAddition, arg) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/binarycheck_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []int32{0, 6, 33, -3, 5, 8, -84, 938, 38, 92, -78, -53, -23, 33, 4, 64, 76, 24, 90, 22, 31, 241, 51, 391} 12 | for i := 0; i < len(args); i++ { 13 | challenge.Function("BinaryCheck", student.BinaryCheck, solutions.BinaryCheck, args[i]) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/boolean_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), "1 2 3 4 5") 13 | 14 | for _, s := range table { 15 | challenge.Program("boolean", strings.Fields(s)...) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/btreeapplybylevel_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | student "student" 7 | 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | root := &solutions.TreeNode{Data: "04"} 13 | rootS := &student.TreeNode{Data: "04"} 14 | 15 | ins := []string{"01", "07", "05", "12", "02", "03", "10"} 16 | 17 | for _, v := range ins { 18 | root = solutions.BTreeInsertData(root, v) 19 | rootS = student.BTreeInsertData(rootS, v) 20 | } 21 | 22 | solutions.ChallengeTree("BTreeApplyByLevel", solutions.BTreeApplyByLevel, student.BTreeApplyByLevel, root, rootS, fmt.Print) 23 | } 24 | -------------------------------------------------------------------------------- /tests/buzzinga_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []int32{20, 15, -125, 10, 5, 4, -9, 9, 24, 0, -85, 6, 11} 12 | 13 | for i := 0; i < len(args); i++ { 14 | challenge.Function("BuzZinga", student.BuzZinga, solutions.BuzZinga, args[i]) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/capitalize_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | args := append( 14 | random.StrSlice(chars.ASCII), 15 | "Hello! How are you? How+are+things+4you?", 16 | "Hello! How are you?", 17 | "a", 18 | "z", 19 | "!", 20 | "9a", 21 | "9a LALALA!", 22 | ) 23 | for _, arg := range args { 24 | challenge.Function("Capitalize", student.Capitalize, solutions.Capitalize, arg) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/checknumber_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{ 12 | "123", 13 | "H1ll0", 14 | "", 15 | "1", 16 | "1.1", 17 | "Containe1number", 18 | " ", 19 | "upson lorem ipsum", 20 | } 21 | 22 | for _, arg := range args { 23 | challenge.Function("CheckNumber", student.CheckNumber, solutions.CheckNumber, arg) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/cleanstr_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | args := []string{ 11 | "you see it's easy to display the same thing", 12 | " only it's harder ", 13 | "how funny", 14 | "", 15 | strings.Repeat(" ", 13), 16 | } 17 | 18 | for _, v := range args { 19 | challenge.Program("cleanstr", v) 20 | } 21 | challenge.Program("cleanstr", "this is not", "happening") 22 | } 23 | -------------------------------------------------------------------------------- /tests/collatzcountdown_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | args := append(random.IntSliceBetween(2, 20), 13 | random.IntBetween(-6, 20), 14 | -5, 15 | 0, 16 | ) 17 | for _, v := range args { 18 | challenge.Function("CollatzCountdown", student.CollatzCountdown, solutions.CollatzCountdown, v) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/comcheck_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), 13 | "01", 14 | "galaxy", 15 | "galaxy01", 16 | " 01", 17 | "as das d 01 asd", 18 | "as galaxy d 12", 19 | "as ds galaxy 01 asd") 20 | 21 | for _, s := range table { 22 | challenge.Program("comcheck", strings.Fields(s)...) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/concat2args_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"Abc", "Bcd"}, 10 | {"Hello", " World!"}, 11 | {"talented ", "student"}, 12 | {"A", "1"}, 13 | {"Hello", "World"}, 14 | {""}, 15 | {"he", "llo"}, 16 | {"1", "93"}, 17 | {"he", "llo", " world!"}, 18 | {" ", " "}, 19 | {"1 + ", "9 = 10"}, 20 | {"", ""}, 21 | {"01", "zone", "Oujda", "Morroco"}, 22 | {}, 23 | {" abc", "def12", "ghk34"}, 24 | } 25 | for _, arg := range args { 26 | challenge.Program("concat2args", arg...) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/concatalternate_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][][]int{ 12 | {{1, 2, 3}, {4, 5, 6}}, 13 | {{1, 2, 3}, {4, 5}}, 14 | {{}, {4, 5, 6}}, 15 | {{1, 2, 3}, {}}, 16 | {{}, {}}, 17 | {{1, 2, 4}, {10, 20, 30, 40, 50}}, 18 | } 19 | for _, arg := range args { 20 | challenge.Function("ConcatAlternate", student.ConcatAlternate, solutions.ConcatAlternate, arg[0], arg[1]) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/concatenate_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | table := [][]string{ 7 | {}, 8 | {"", "a", "b", "c"}, 9 | {"a", "b", "c", "d"}, 10 | {"Hello", "World", "!"}, 11 | {"Hello", "World", "!"}, 12 | {"Hello", ""}, 13 | {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 14 | {"hello there", "how are you?"}, 15 | {"hello there", " "}, 16 | } 17 | for _, arg := range table { 18 | challenge.Program("concatenate", arg...) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/concatparams_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := [][]string{{"Hello", "how", "are", "you?"}} 14 | 15 | // 30 random slice of strings 16 | for i := 0; i < 30; i++ { 17 | table = append(table, random.StrSlice(chars.ASCII)) 18 | } 19 | for _, arg := range table { 20 | challenge.Function("ConcatParams", student.ConcatParams, solutions.ConcatParams, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/concatslice_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][][]int{ 12 | {{1, 2, 3}, {4, 5, 6}}, 13 | {{}, {-10, 0, 2}}, 14 | {{-10, 0, 2}, {}}, 15 | {{}, {}}, 16 | {{1, 2, 3}, {4, 5, 6, 3, 4, 5, 6}}, 17 | {{0, 0, 0}, {0, 0, 0}}, 18 | } 19 | 20 | for _, arg := range args { 21 | challenge.Function("ConcatSlice", student.ConcatSlice, solutions.ConcatSlice, arg[0], arg[1]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/countalpha_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | params := []string{ 12 | "a", 13 | "abc", 14 | "", 15 | "H E L L O", 16 | "A1B2C3D4B5DE6", 17 | "a1b2c3d4b5de6", 18 | "A1b2C3D4B5De6", 19 | "1234", 20 | " ", 21 | } 22 | 23 | for _, param := range params { 24 | challenge.Function("CountAlpha", student.CountAlpha, solutions.CountAlpha, param) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/countdown_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("countdown") 7 | } 8 | -------------------------------------------------------------------------------- /tests/countnegative_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]int{ 12 | {10, 10, 3, 1, 2, 3, 5, 3, 63}, 13 | {-10, -10, 03, 1, 2, 3, 5, 3, 63}, 14 | {0, 0, 0, 0, 0, 0, 0, 0, 0}, 15 | {1, 3, -100, 39, 4, 10, -29, -49, 92}, 16 | {-1}, 17 | {23}, 18 | {3, -1, -2, -3}, 19 | {0, -3, -2, -1}, 20 | {}, 21 | } 22 | for _, arg := range table { 23 | challenge.Function("CountNegative", student.CountNegative, solutions.CountNegative, arg) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/countstars_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []int{1, 2, 9, -258, 0, 100, 48, 94, 41, -56, 520} 12 | for _, num := range table { 13 | challenge.Function("CountStars", student.CountStars, solutions.CountStars, num) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/dealapackofcards_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]int{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}} 12 | 13 | for _, s := range table { 14 | challenge.Function("DealAPackOfCards", student.DealAPackOfCards, solutions.DealAPackOfCards, s) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/delete_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | intsArgs := [][]int{ 12 | {}, 13 | {}, 14 | {1, 2, 3, 4, 5}, 15 | {1, 2}, 16 | {23, 25, 26, 65}, 17 | {98, 345, 456}, 18 | } 19 | positionArgs := []int{0, 1, 6, 1, 3, 2} 20 | for index, arg := range intsArgs { 21 | challenge.Function("Delete", student.Delete, solutions.Delete, arg, positionArgs[index]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/descendcomb_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | challenge.Function("DescendComb", student.DescendComb, solutions.DescendComb) 12 | } 13 | -------------------------------------------------------------------------------- /tests/displaya_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), 13 | "dsfda", 14 | "", 15 | "1", 16 | "1", 17 | ) 18 | for _, s := range table { 19 | challenge.Program("displaya", strings.Fields(s)...) 20 | } 21 | challenge.Program("displaya", "1", "a") 22 | } 23 | -------------------------------------------------------------------------------- /tests/displayalpham_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("displayalpham") 7 | } 8 | -------------------------------------------------------------------------------- /tests/displayalrevm_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("displayalrevm") 7 | } 8 | -------------------------------------------------------------------------------- /tests/displayfile_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "strings" 7 | 8 | "github.com/weightygroc/go-tests/lib/challenge" 9 | ) 10 | 11 | func main() { 12 | fileName := "quest8.txt" 13 | if err := ioutil.WriteFile(fileName, []byte("Almost there!!\n"), os.ModePerm); err != nil { 14 | panic(err) 15 | } 16 | table := []string{"", fileName, fileName + " asdsada"} 17 | for _, s := range table { 18 | challenge.Program("displayfile", strings.Fields(s)...) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/displayfirstparam_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), 13 | " ", 14 | "1", 15 | "1 2", 16 | "1 2 3", 17 | ) 18 | for _, s := range table { 19 | challenge.Program("displayfirstparam", strings.Fields(s)...) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/displaylastparam_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), 13 | " ", 14 | "1", 15 | "1 2", 16 | "1 2 3", 17 | ) 18 | for _, s := range table { 19 | challenge.Program("displaylastparam", strings.Fields(s)...) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/displayp_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("displayp") 7 | } 8 | -------------------------------------------------------------------------------- /tests/displays_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | args := []string{ 7 | "dsfdz", 8 | "", 9 | "1", 10 | "2", 11 | } 12 | for _, s := range args { 13 | challenge.Program("displays", s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/displayz_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | args := append(random.StrSlice(chars.Words), 13 | "dsfdz", 14 | "", 15 | "1", 16 | "1", 17 | ) 18 | for _, s := range args { 19 | challenge.Program("displayz", strings.Fields(s)...) 20 | } 21 | 22 | challenge.Program("displayz", "1", "z") 23 | } 24 | -------------------------------------------------------------------------------- /tests/divisors_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []int{1, 2, 3, 4, 9285, 74584, 0, -5585, 75418, 99999, -1, 526, 36} 12 | for _, n := range table { 13 | challenge.Function("Divisors", student.Divisors, solutions.Divisors, n) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/divmod_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | for i := 0; i < 8; i++ { 12 | a := random.Int() 13 | b := random.Int() 14 | var div int 15 | var mod int 16 | student.DivMod(a, b, &div, &mod) 17 | if div != a/b { 18 | challenge.Fatalf("DivMod(%d, %d, &div, &mod), div == %d instead of %d", a, b, div, a/b) 19 | } 20 | if mod != a%b { 21 | challenge.Fatalf("DivMod(%d, %d, &div, &mod), mod == %d instead of %d", a, b, mod, a%b) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/eightqueens_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | challenge.Function("EightQueens", student.EightQueens, solutions.EightQueens) 12 | } 13 | -------------------------------------------------------------------------------- /tests/expandstr_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := [][]string{ 11 | {"hello", "you"}, 12 | {" only it's harder "}, 13 | {"you see it's easy to display the same thing"}, 14 | } 15 | 16 | args = append(args, random.StrSlice(chars.Words)) 17 | 18 | for _, v := range args { 19 | challenge.Program("expandstr", v...) 20 | } 21 | challenge.Program("expandstr") 22 | } 23 | -------------------------------------------------------------------------------- /tests/fifthandskip_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"1234556789", "e 5£ @ 8* 7 =56 ;", "QKplq%QSw", "", "hello \\! n4ght cr3a8ure7 ", "Kimetsu no Yaiba", "8595485-52", "-552", "w58tw7474abc", "Po65 4o"} 12 | for _, s := range table { 13 | challenge.Function("FifthAndSkip", student.FifthAndSkip, solutions.FifthAndSkip, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/findmissingnumber_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 13 | {1, 3, 4, 5, 6, 7, 8, 9, 10}, 14 | {-20, -10, 0, 10, 20}, 15 | {29, 31, 32, 33, 34}, 16 | {(int(^uint(0)>>1) * -1) - 1, int(^uint(0) >> 1)}, 17 | } 18 | for _, arg := range args { 19 | challenge.Function("FindMissingNumber", student.FindMissingNumber, solutions.FindMissingNumber, arg) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/findnextprime_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | args := append(random.IntSliceBetween(-1000000, 1000000), 13 | 0, 14 | 1, 15 | 2, 16 | 3, 17 | 4, 18 | 5, 19 | 6, 20 | 7, 21 | 8, 22 | 9, 23 | 10, 24 | 11, 25 | 12, 26 | 100, 27 | 1000000086, 28 | 1000000087, 29 | 1000000088, 30 | ) 31 | for _, arg := range args { 32 | challenge.Function("FindNextPrime", student.FindNextPrime, solutions.FindNextPrime, arg) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/findprevprime_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | args := append(random.IntSliceBetween(0, 99999), 5, 4, 1, 0) 13 | for _, arg := range args { 14 | challenge.Function("FindPrevPrime", student.FindPrevPrime, solutions.FindPrevPrime, arg) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/firstrune_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := append( 14 | random.StrSlice(chars.ASCII), 15 | "Hello!", 16 | "Salut!", 17 | "Ola!", 18 | "♥01", 19 | ) 20 | for _, arg := range table { 21 | challenge.Function("FirstRune", student.FirstRune, solutions.FirstRune, arg) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/firstword_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | student "student" 7 | ) 8 | 9 | var testCases = []struct { 10 | in string 11 | want string 12 | }{ 13 | {"", "\n"}, 14 | {" a as", "a\n"}, 15 | {" f d", "f\n"}, 16 | {" asd ad", "asd\n"}, 17 | {" salut !!! ", "salut\n"}, 18 | {" salut ! ! !", "salut\n"}, 19 | {"salut ! !", "salut\n"}, 20 | } 21 | 22 | func main() { 23 | for _, tc := range testCases { 24 | got := student.FirstWord(tc.in) 25 | if got != tc.want { 26 | fmt.Printf("FirstWord(%q) = %q instead of %q\n", tc.in, got, tc.want) 27 | os.Exit(1) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/fishandchips_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []int{20, 15, -125, 10, 5, 4, -9, 9, 24, 0, -85, 6, 11} 12 | 13 | for i := 0; i < len(args); i++ { 14 | challenge.Function("FishAndChips", student.FishAndChips, solutions.FishAndChips, args[i]) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixthemain_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("fixthemain") 7 | } 8 | -------------------------------------------------------------------------------- /tests/fooddeliverytime_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"burger", "chips", "nuggets", "pizza", "pepper", " burger", "chi ps", "nuggets "} 12 | for _, s := range table { 13 | challenge.Function("FoodDeliveryTime", student.FoodDeliveryTime, solutions.FoodDeliveryTime, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/fprime_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | table := []string{ 12 | " ", 13 | "1", 14 | "1 1", 15 | "hello", 16 | "p 1", 17 | "804577", 18 | "225225", 19 | "8333325", 20 | "42", 21 | "9539", 22 | "1000002", 23 | "1000003", 24 | } 25 | for i := 0; i < 10; i++ { 26 | table = append(table, strconv.Itoa(random.IntBetween(1, 100))) 27 | } 28 | for _, s := range table { 29 | challenge.Program("fprime", s) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/fromto_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2}, 13 | {1, 10}, 14 | {1, 100}, 15 | {100, 1}, 16 | {99, 1}, 17 | {1, 1}, 18 | {1, 0}, 19 | {0, 1}, 20 | {-1, 10}, 21 | {1, 99}, 22 | {99, -1}, 23 | } 24 | for _, arg := range args { 25 | challenge.Function("FromTo", student.FromTo, solutions.FromTo, arg[0], arg[1]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/frontback_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | table := []string{ 11 | "A", 12 | "B", 13 | "C", 14 | "D", 15 | "AB", 16 | "a", 17 | "z", 18 | "HELLO WORLD", 19 | "1", 20 | "2", 21 | "-1", 22 | "$", 23 | "@", 24 | " ", 25 | "", 26 | } 27 | for _, s := range table { 28 | challenge.Program("frontback", strings.Fields(s)...) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/gcd_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | student "student" 7 | ) 8 | 9 | func main() { 10 | testCases := []struct { 11 | a uint 12 | b uint 13 | want uint 14 | }{ 15 | {42, 10, 2}, 16 | {42, 12, 6}, 17 | {14, 77, 7}, 18 | {17, 3, 1}, 19 | {12, 23, 1}, 20 | {25, 15, 5}, 21 | {23043, 122, 1}, 22 | {11, 77, 11}, 23 | } 24 | 25 | for _, tc := range testCases { 26 | got := student.Gcd(tc.a, tc.b) 27 | if got != tc.want { 28 | fmt.Printf("Gcd(%d, %d) = %d instead of %d\n", tc.a, tc.b, got, tc.want) 29 | os.Exit(1) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/getalpha_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"4"}, 10 | {""}, 11 | {"52"}, 12 | {"8"}, 13 | {"42"}, 14 | {"92"}, 15 | {"102"}, 16 | {"127"}, 17 | {"40"}, 18 | {"15"}, 19 | {"9"}, 20 | {"4"}, 21 | {"E"}, 22 | {" "}, 23 | {"13"}, 24 | {"68"}, 25 | {"77"}, 26 | {"87"}, 27 | {"51"}, 28 | {"2"}, 29 | {"3"}, 30 | {"15"}, 31 | {"16"}, 32 | {"0"}, 33 | } 34 | for _, s := range args { 35 | challenge.Program("getalpha", s...) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/getarea_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | table := []string{ 11 | "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", 12 | "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", 13 | "01", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", 14 | "120", "1201", "1202", "1203", "1204", "1205", "1206", "1207", "1208", "1209", "1210", 15 | "hello", "world", " ", "hello world hello", "hello world ", 16 | } 17 | for _, s := range table { 18 | challenge.Program("getarea", strings.Fields(s)...) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/getascii_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"W"}, 10 | {""}, 11 | {"H", "world"}, 12 | {"Hello World"}, 13 | {"A"}, 14 | {"B"}, 15 | {"C"}, 16 | {"&"}, 17 | {"20"}, 18 | {"100"}, 19 | {" "}, 20 | {"4"}, 21 | {"E"}, 22 | {" "}, 23 | {"13 233 4 23"}, 24 | {"1"}, 25 | {"7"}, 26 | {"8"}, 27 | {"£"}, 28 | {"@"}, 29 | {"$"}, 30 | {"~"}, 31 | {"0"}, 32 | {"*"}, 33 | {"本"}, 34 | {"人"}, 35 | {"的"}, 36 | } 37 | for _, s := range args { 38 | challenge.Program("getascii", s...) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/halfslice_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3, 4, 5}, 13 | {6, 7, 8, 9, 10}, 14 | {11, 12, 13, 14, 15}, 15 | {}, 16 | {10, 20, 30, 40}, 17 | {1, 2, 3}, 18 | } 19 | for _, arg := range args { 20 | challenge.Function("HalfSlice", student.HalfSlice, solutions.HalfSlice, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/hashcode_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"Z", "Hi!", "BB198365", "sabito", "14 Avril 1912", "zyx987bca", " pool-2020", "965truma747", " Mercedes-AMG GT"} 12 | for _, s := range table { 13 | challenge.Function("HashCode", student.HashCode, solutions.HashCode, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/hello_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("hello") 7 | } 8 | -------------------------------------------------------------------------------- /tests/iscapitalized_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{ 12 | "Hello! €How are you?", 13 | "a", 14 | "z", 15 | "!", 16 | "Hello How Are 4you", 17 | "What's this 4?", 18 | "Whatsthis4", 19 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", 20 | "131!", 21 | "H3110 W0r1d!", 22 | "", 23 | " ", 24 | } 25 | 26 | for _, arg := range table { 27 | challenge.Function("IsCapitalized", student.IsCapitalized, solutions.IsCapitalized, arg) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/ismultiple_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | 12 | table := []int{ 13 | 10, 14 | 9, 15 | 8, 16 | 0, 17 | -10, 18 | -9, 19 | 2948483, 20 | 4848, 21 | 3282, 22 | -3282, 23 | } 24 | for _, num := range table { 25 | challenge.Function("IsMultiple", student.IsMultiple, solutions.IsMultiple, num) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/isnegative_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := append( 13 | random.IntSlice(), 14 | random.MinInt, 15 | random.MaxInt, 16 | 0, 17 | ) 18 | for _, arg := range table { 19 | challenge.Function("IsNegative", student.IsNegative, solutions.IsNegative, arg) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/ispowerof2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | args := [][]string{ 12 | {"1"}, 13 | {"2"}, 14 | {"3"}, 15 | {"4"}, 16 | {"1024"}, 17 | {"4096"}, 18 | {"8388608"}, 19 | {"1", "2"}, 20 | {}, 21 | } 22 | for i := 0; i < 12; i++ { 23 | args = append(args, []string{strconv.Itoa(random.IntBetween(1, 2048))}) 24 | } 25 | for _, v := range args { 26 | challenge.Program("ispowerof2", v...) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/isprime_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := append( 13 | random.IntSliceBetween(-1000000, 1000000), 14 | 0, 15 | 1, 16 | 2, 17 | 3, 18 | 4, 19 | 5, 20 | 6, 21 | 7, 22 | 8, 23 | 9, 24 | 10, 25 | 11, 26 | 12, 27 | 100, 28 | 1000000086, 29 | 1000000087, 30 | ) 31 | for _, arg := range table { 32 | challenge.Function("IsPrime", student.IsPrime, solutions.IsPrime, arg) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/issamestring_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]string{ 12 | {"abcd", "AbCd"}, 13 | {"abcd", "abcddd"}, 14 | {"ab12", "abcd"}, 15 | {"", "abcd"}, 16 | {"ABCD", "abcd"}, 17 | {"abcd12HJK", "abcd12HJK"}, 18 | {"+++\t----", "+++\t----"}, 19 | {"abcdefgh", "abcdefghijklmnopqrstuvwxyz"}, 20 | {" ", " "}, 21 | {" ", " "}, 22 | } 23 | for _, arg := range args { 24 | challenge.Function("IsSameString", student.IsSameString, solutions.IsSameString, arg[0], arg[1]) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/issquare_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 1}, 13 | {2, 4}, 14 | {3, 9}, 15 | {4, 16}, 16 | {5, 25}, 17 | {6, 36}, 18 | {7, 49}, 19 | {-1, 0}, 20 | {8, -64}, 21 | {4, -16}, 22 | {-1, 1}, 23 | {-4, 16}, 24 | {-5, 25}, 25 | } 26 | for _, arg := range args { 27 | challenge.Function("IsSquare", student.IsSquare, solutions.IsSquare, arg[0], arg[1]) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/iterativefactorial_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := random.IntSlice() 13 | for i := 0; i <= 20; i++ { 14 | table = append(table, i) 15 | } 16 | for _, arg := range table { 17 | challenge.Function("IterativeFactorial", student.IterativeFactorial, solutions.IterativeFactorial, arg) 18 | } 19 | 20 | challenge.Function("IterativeFactorial", student.IterativeFactorial, solutions.IterativeFactorial, 22) 21 | } 22 | -------------------------------------------------------------------------------- /tests/itoa_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | for i := 0; i < 50; i++ { 13 | challenge.Function("Itoa", student.Itoa, solutions.Itoa, random.Int()) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/jumpover_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"1010101010", "plq%QSw", "", "Life Is Great", "Z", "johndoe@imposssible.io", "8595485-52", "-552", "w58tw7474abc", "Mine Craft"} 12 | for _, s := range table { 13 | challenge.Function("JumpOver", student.JumpOver, solutions.JumpOver, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/lastrune_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | args := append(random.StrSlice(chars.ASCII), 14 | "Hello!", 15 | "Salut!", 16 | "Ola!", 17 | random.Str(chars.Alnum, random.IntBetween(1, 15)), 18 | ) 19 | for _, arg := range args { 20 | challenge.Function("LastRune", student.LastRune, solutions.LastRune, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/lcm_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := [][2]int{ 13 | {50, 43}, 14 | {13, 13}, 15 | {10, 9}, 16 | {0, 9}, 17 | {1, 1}, 18 | } 19 | 20 | for i := 0; i < 15; i++ { 21 | table = append(table, [2]int{ 22 | random.IntBetween(0, 1000), 23 | random.IntBetween(0, 1000), 24 | }) 25 | } 26 | 27 | for _, arg := range table { 28 | challenge.Function("Lcm", student.Lcm, solutions.Lcm, arg[0], arg[1]) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/leapyear_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | years := []int{ 12 | 2016, 13 | 2017, 14 | 2000, 15 | 1900, 16 | 1920, 17 | 1921, 18 | 1, 19 | -10, 20 | 10000, 21 | 10001, 22 | 10002, 23 | -2012, 24 | 0, 25 | } 26 | for _, arg := range years { 27 | challenge.Function("LeapYear", student.LeapYear, solutions.LeapYear, arg) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/max_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | args := []int{random.Int()} 13 | limit := random.IntBetween(20, 50) 14 | for i := 0; i < limit; i++ { 15 | args = append(args, random.Int()) 16 | } 17 | 18 | challenge.Function("Max", student.Max, solutions.Max, args) 19 | } 20 | -------------------------------------------------------------------------------- /tests/notdecimal_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{"-19.525856", "00.02", "56s44", "", "415.458", "1.6", "165", "502.3254", "51.3+95.9", "-5.0f00d00", "-53.124"} 12 | 13 | for i := 0; i < len(args); i++ { 14 | challenge.Function("NotDecimal", student.NotDecimal, solutions.NotDecimal, args[i]) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/numofdigits_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | ar := []int{ 12 | 1, 13 | 5858, 14 | 485, 15 | 5, 16 | -525, 17 | 47, 18 | 85955, 19 | 0, 20 | -8, 21 | 5285, 22 | -48, 23 | } 24 | for i := 0; i < len(ar); i++ { 25 | challenge.Function("Numofdigits", student.Numofdigits, solutions.Numofdigits, ar[i]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/only1_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("only1") 7 | } 8 | -------------------------------------------------------------------------------- /tests/onlya_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("onlya") 7 | } 8 | -------------------------------------------------------------------------------- /tests/onlyb_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("onlyb") 7 | } 8 | -------------------------------------------------------------------------------- /tests/onlyf_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("onlyf") 7 | } 8 | -------------------------------------------------------------------------------- /tests/onlyz_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("onlyz") 7 | } 8 | -------------------------------------------------------------------------------- /tests/paramrange_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"2", "5", "u", "19"}, 10 | {"2"}, 11 | {"1", "2", "3", "5", "7", "24"}, 12 | {"6", "12", "24"}, 13 | {""}, 14 | {"-10", "10", "20", "30", "40", "50"}, 15 | {"Hello world"}, 16 | {"10", "20", "-1"}, 17 | {"1", "-2", "3"}, 18 | } 19 | for _, v := range args { 20 | challenge.Program("paramrange", v...) 21 | } 22 | challenge.Program("paramrange") 23 | } 24 | -------------------------------------------------------------------------------- /tests/piglatin_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := []string{ 11 | "", "pig", "is", "crunch", "crnch", "something else", 12 | } 13 | 14 | for i := 0; i < 4; i++ { 15 | args = append(args, random.Str(chars.Basic, 7)) 16 | } 17 | 18 | for _, v := range args { 19 | challenge.Program("piglatin", v) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/pilot_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("pilot") 7 | } 8 | -------------------------------------------------------------------------------- /tests/pingpong_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {""}, 10 | {"0"}, 11 | {"3", "5"}, 12 | {"5"}, 13 | {"9"}, 14 | {"24"}, 15 | {"99"}, 16 | {"100"}, 17 | } 18 | for _, arg := range args { 19 | challenge.Program("pingpong", arg...) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/point_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("point") 7 | } 8 | -------------------------------------------------------------------------------- /tests/pointone_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | n := 0 11 | student.PointOne(&n) 12 | if n != 1 { 13 | challenge.Fatalf("PointOne(&n), n == %d instead of 1\n", n) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/popint_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | 12 | args := [][]int{ 13 | {1, 3, 5}, 14 | {-1, -2, 3}, 15 | {}, 16 | {22134, 2345345, 575672, 2567567, 2456456, 2345345}, 17 | } 18 | 19 | for _, arg := range args { 20 | challenge.Function("PopInt", student.PopInt, solutions.PopInt, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/printalphabet_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalphabet") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printalphabetalt2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalphabetalt2") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printalphabetalt_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalphabetalt") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printalphabetg_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalphabetg") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printalt2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalt2") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printalt_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printalt") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printaltu2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printaltu2") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printaltu_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printaltu") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printascii_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"S"}, 10 | {"One", "ring!"}, 11 | {"A"}, 12 | {"E"}, 13 | {"z"}, 14 | {"testing spaces and #!*"}, 15 | {"more", "than", "three", "arguments"}, 16 | {"W"}, 17 | {"1"}, 18 | {""}, 19 | } 20 | for _, v := range args { 21 | challenge.Program("printascii", v...) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/printbits_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | 7 | "github.com/weightygroc/go-tests/lib/challenge" 8 | "github.com/weightygroc/go-tests/lib/chars" 9 | "github.com/weightygroc/go-tests/lib/random" 10 | ) 11 | 12 | func main() { 13 | args := []string{ 14 | "", 15 | "a", 16 | "bc", 17 | "def", 18 | "notanumber", 19 | random.Str(chars.Basic, 13), 20 | } 21 | for i := 0; i < 20; i++ { 22 | args = append(args, strconv.Itoa(random.IntBetween(0, 255))) 23 | } 24 | for _, v := range args { 25 | challenge.Program("printbits", strings.Fields(v)...) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/printcomb2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | challenge.Function("PrintComb2", student.PrintComb2, solutions.PrintComb2) 12 | } 13 | -------------------------------------------------------------------------------- /tests/printcomb_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | challenge.Function("PrintComb", student.PrintComb, solutions.PrintComb) 12 | } 13 | -------------------------------------------------------------------------------- /tests/printcombn_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} 12 | for _, arg := range table { 13 | challenge.Function("PrintCombN", student.PrintCombN, solutions.PrintCombN, arg) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/printdigits_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printdigits") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printevenarguments_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | table := [][]string{ 7 | {}, 8 | {"a"}, 9 | {"", "a", "b", "c"}, 10 | {"a", "b", "c", "d"}, 11 | {"Hello", "World", "!"}, 12 | {"Hello", "World", "!"}, 13 | {"Hello", ""}, 14 | {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, 15 | } 16 | for _, arg := range table { 17 | challenge.Program("printevenarguments", arg...) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/printhex_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | 7 | "github.com/weightygroc/go-tests/lib/challenge" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := []string{ 13 | " ", 14 | "123 132 1", 15 | "1 5", 16 | "0", 17 | } 18 | for i := 0; i < 10; i++ { 19 | table = append(table, strconv.Itoa(random.IntBetween(-1000, random.MaxInt))) 20 | } 21 | for i := 0; i < 15; i++ { 22 | table = append(table, strconv.Itoa(i)) 23 | } 24 | for _, s := range table { 25 | challenge.Program("printhex", strings.Fields(s)...) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/printif_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"First78last", " ", " 280jsl", "he", "", "honey!", "Z", "email123@live.fr", "w45m$", "-552", "474abc", "<=>"} 12 | for _, s := range table { 13 | challenge.Function("PrintIf", student.PrintIf, solutions.PrintIf, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/printifnot_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"ab", " ", "good morning sunshine!", " 28", "he", "", "honey!", "Z", "email123@live.fr", "w45m$", "-552", "474abc", "<="} 12 | for _, s := range table { 13 | challenge.Function("PrintIfNot", student.PrintIfNot, solutions.PrintIfNot, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/printnbr_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := append(random.IntSlice(), 13 | random.MinInt, 14 | random.MaxInt, 15 | 0, 16 | ) 17 | for _, arg := range table { 18 | challenge.Function("PrintNbr", student.PrintNbr, solutions.PrintNbr, arg) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/printnbrinorder_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := append( 13 | random.IntSliceBetween(0, random.MaxInt), 14 | random.MaxInt, 15 | 321, 16 | 321321, 17 | 0, 18 | ) 19 | for _, arg := range table { 20 | challenge.Function("PrintNbrInOrder", student.PrintNbrInOrder, solutions.PrintNbrInOrder, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/printparams_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), "choumi is the best cat") 13 | for _, s := range table { 14 | challenge.Program("printparams", strings.Fields(s)...) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/printrange_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 10}, 13 | {10, 1}, 14 | {1, 1}, 15 | {10, 10}, 16 | {0, 9}, 17 | {-1, -10}, 18 | {-10, -1}, 19 | {-1, 9}, 20 | {-10, 15}, 21 | {10, -15}, 22 | } 23 | for _, arg := range args { 24 | challenge.Function("PrintRange", student.PrintRange, solutions.PrintRange, arg[0], arg[1]) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/printrevcomb_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printrevcomb") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printreversealphabet_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printreversealphabet") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printreversealphabetalt2_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printreversealphabetalt2") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printreversealphabetalt_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printreversealphabetalt") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printreversealphabetg_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("printreversealphabetg") 7 | } 8 | -------------------------------------------------------------------------------- /tests/printrot_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | table := []string{ 11 | "A", 12 | "a", 13 | "b", 14 | "c", 15 | "d", 16 | "e", 17 | "f", 18 | "g", 19 | "h", 20 | "i", 21 | "j", 22 | "k", 23 | "l", 24 | "m", 25 | "n", 26 | "o", 27 | "p", 28 | "q", 29 | "r", 30 | "s", 31 | "t", 32 | "u", 33 | "v", 34 | "w", 35 | "x", 36 | "y", 37 | "z", 38 | "Z", 39 | "2 arguments", 40 | "4 arguments so invalid", 41 | } 42 | for _, s := range table { 43 | challenge.Program("printrot", strings.Fields(s)...) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/printstr_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := append(random.StrSlice(chars.ASCII), "Hello World!") 14 | for _, arg := range table { 15 | challenge.Function("PrintStr", student.PrintStr, solutions.PrintStr, arg) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/printwordstables_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := [][]string{{"Hello", "how", "are", "you?"}} 14 | 15 | // 30 random slice of slice of strings 16 | for i := 0; i < 30; i++ { 17 | table = append(table, random.StrSlice(chars.ASCII)) 18 | } 19 | 20 | for _, arg := range table { 21 | challenge.Function("PrintWordsTables", student.PrintWordsTables, solutions.PrintWordsTables, arg) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/quarterofayear_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 13, -5} 12 | 13 | for _, arg := range args { 14 | challenge.Function("QuarterOfAYear", student.QuarterOfAYear, solutions.QuarterOfAYear, arg) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/range_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | table := [][]string{ 12 | {"2", "1", "3"}, 13 | {"a", "1"}, 14 | {"1", "b"}, 15 | {"1", "nan"}, 16 | {"nan", "b"}, 17 | {}, 18 | } 19 | 20 | for i := 0; i < 10; i++ { 21 | start := random.IntBetween(-20, 20) 22 | end := random.IntBetween(-20, 20) 23 | table = append(table, []string{strconv.Itoa(start), strconv.Itoa(end)}) 24 | } 25 | for _, v := range table { 26 | challenge.Program("range", v...) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/rectangle_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | challenge.Program("rectangle") 7 | } 8 | -------------------------------------------------------------------------------- /tests/rectperimeter_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2}, 13 | {0, 0}, 14 | {8423, 9485}, 15 | {-1, -1}, 16 | {2147483647, 3}, 17 | {14342, -1}, 18 | } 19 | for _, arg := range args { 20 | challenge.Function("RectPerimeter", student.RectPerimeter, solutions.RectPerimeter, arg[0], arg[1]) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/recursivefactorial_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := random.IntSlice() 13 | for i := 0; i <= 20; i++ { 14 | table = append(table, i) 15 | } 16 | for _, arg := range table { 17 | challenge.Function("RecursiveFactorial", student.RecursiveFactorial, solutions.RecursiveFactorial, arg) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/removeduplicate_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][]int{ 12 | {1, 2, 3, 4, 5}, 13 | {1, 2, 3, 4, 5, 5, 4, 4, 2, 1}, 14 | {1, 1, 1, 1}, 15 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 1}, 16 | {}, 17 | {1}, 18 | {0, 0, 0, 2}, 19 | {10, 20, 10, 20, 30, 20, 10, 20, 10, 20}, 20 | } 21 | for _, v := range table { 22 | challenge.Function("RemoveDuplicate", solutions.RemoveDuplicate, student.RemoveDuplicate, v) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/removeodd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{ 12 | "ReverseBits", 13 | "Hello, world!", 14 | "My name is John", 15 | "I am a student", 16 | "Five is 5", 17 | "Seven never sevens", 18 | "Eight is 8", 19 | "H", 20 | "I", 21 | } 22 | 23 | for _, v := range args { 24 | challenge.Function("RemoveOdd", student.RemoveOdd,solutions.RemoveOdd, v) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/repeatalpha_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | student "student" 7 | ) 8 | 9 | func main() { 10 | testCases := []struct { 11 | in string 12 | want string 13 | }{ 14 | {"abc", "abbccc"}, 15 | {"Choumi.", "CCChhhhhhhhooooooooooooooouuuuuuuuuuuuuuuuuuuuummmmmmmmmmmmmiiiiiiiii."}, 16 | {"", ""}, 17 | {"abacadaba 01!", "abbacccaddddabba 01!"}, 18 | } 19 | for _, tc := range testCases { 20 | got := student.RepeatAlpha(tc.in) 21 | if got != tc.want { 22 | fmt.Printf("RepeatAlpha(%q) = %q instead of %q\n", tc.in, got, tc.want) 23 | os.Exit(1) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/replaceeven_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := [][]string{ 11 | {""}, 12 | {"Hello", "Hello"}, 13 | {"World", "World"}, 14 | {"01010101010"}, 15 | {" "}, 16 | {"Z01 is the best place in the world", "isn't it?"}, 17 | } 18 | 19 | args = append(args, random.StrSlice(chars.Words)) 20 | 21 | for _, v := range args { 22 | challenge.Program("replaceeven", v...) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/retainfirsthalf_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"hello", "", "Kimetsu no Yaiba", "Z", "123@live.fr", "write %d ==> 45m$", "-552"} 12 | for _, s := range table { 13 | challenge.Function("RetainFirstHalf", student.RetainFirstHalf, solutions.RetainFirstHalf, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/returna_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | args := [][]string{ 9 | {"Exam"}, 10 | {""}, 11 | {"Hello blah blah", "more blabh lah"}, 12 | {"See you at ", "Monday"}, 13 | {"a"}, 14 | {"30", "20"}, 15 | {"A B C E"}, 16 | {"4 3 2 1 0"}, 17 | {"A B C D E"}, 18 | {"13 285 8528 -25a"}, 19 | {"first go "}, 20 | {"pool"}, 21 | } 22 | 23 | for _, s := range args { 24 | challenge.Program("returna", s...) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/revargs_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | 5 | "github.com/weightygroc/go-tests/lib/challenge" 6 | ) 7 | 8 | func main() { 9 | args := [][]string{ 10 | {"Hello"}, 11 | {""}, 12 | {}, 13 | {"Hello World", "world"}, 14 | {"Hello World", "world", "Hello World"}, 15 | {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, 16 | {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, 17 | {"A B C D E"}, 18 | {"4 3 2 1 0"}, 19 | {"13 233 4 23"}, 20 | } 21 | for _, s := range args { 22 | challenge.Program("revargs", s...) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/reverserange_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | table := [][]string{ 12 | {"2", "1", "3"}, 13 | {"-1", "2"}, 14 | {"0", "-3"}, 15 | {"1", "nan"}, 16 | {"nan", "b"}, 17 | } 18 | for i := 0; i < 10; i++ { 19 | start := random.IntBetween(-20, 20) 20 | end := random.IntBetween(-20, 20) 21 | table = append(table, []string{strconv.Itoa(start), strconv.Itoa(end)}) 22 | } 23 | for _, v := range table { 24 | challenge.Program("reverserange", v...) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/reversesecondhalf_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"hello wold", "", "Kimetsu no Yaiba", "Z", "email123@live.fr", "write ==> 45m$", "-552", "w58tw7474abc", "fifa world cup `2022`"} 12 | for _, s := range table { 13 | challenge.Function("ReverseSecondHalf", student.ReverseSecondHalf, solutions.ReverseSecondHalf, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/reversestrcap_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := [][]string{ 11 | {"First SMALL TesT"}, 12 | {"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"}, 13 | {""}, 14 | } 15 | 16 | for i := 0; i < 15; i++ { 17 | args = append(args, random.StrSlice(chars.Alnum)) 18 | } 19 | 20 | for _, v := range args { 21 | challenge.Program("reversestrcap", v...) 22 | } 23 | challenge.Program("reversestrcap") 24 | } 25 | -------------------------------------------------------------------------------- /tests/reversestrings_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]string{ 12 | {"good", "morning!"}, 13 | {"Zoo", "mice"}, 14 | {"", ""}, 15 | {"Even", "more"}, 16 | {"Try", "this", "one"}, 17 | {"A", "B", "C", "D"}, 18 | {"1", "3", "$", "301", "hELLO", "WORLD"}, 19 | } 20 | for _, arg := range args { 21 | challenge.Function("ReverseStrings", student.ReverseStrings, solutions.ReverseStrings, arg) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/revparams_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | challenge.Program("revparams", "choumi", "is", "the", "best", "cat") 11 | challenge.Program("revparams", random.StrSlice(chars.Words)...) 12 | } 13 | -------------------------------------------------------------------------------- /tests/rockandroll_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []int{20, 15, -125, 10, 5, 4, -9, 9, 24, 0, -85, 6, 11} 12 | 13 | for i := 0; i < len(args); i++ { 14 | challenge.Function("RockAndRoll", student.RockAndRoll, solutions.RockAndRoll, args[i]) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/romannumbers_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | table := []string{ 12 | "0", 13 | "4000", 14 | "5000", 15 | "12433", 16 | "hello", 17 | "good luck", 18 | } 19 | for i := 0; i < 7; i++ { 20 | table = append(table, strconv.Itoa(random.IntBetween(0, 4000))) 21 | } 22 | for _, v := range table { 23 | challenge.Program("romannumbers", v) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/rostring_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | args := []string{ 11 | "abc ", 12 | "Let there be light", 13 | " AkjhZ zLKIJz , 23y", 14 | "", 15 | } 16 | args = append(args, random.StrSlice(chars.Words)...) 17 | 18 | for _, arg := range args { 19 | challenge.Program("rostring", arg) 20 | } 21 | challenge.Program("rostring") 22 | challenge.Program("rostring", "this", "is") 23 | challenge.Program("rostring", "not", "good", "for you") 24 | } 25 | -------------------------------------------------------------------------------- /tests/rot13_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | table := append(random.StrSlice(chars.Words), 11 | " ", 12 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ", 13 | "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ", 14 | ) 15 | for _, s := range table { 16 | challenge.Program("rot13", s) 17 | } 18 | challenge.Program("rot13", "1 argument", "2 arguments") 19 | challenge.Program("rot13", "1 argument", "2 arguments", "3 arguments") 20 | } 21 | -------------------------------------------------------------------------------- /tests/samecase_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | 9 | args := [][]string{ 10 | {"A", "B"}, 11 | {"a", "b"}, 12 | {"A", "b"}, 13 | {"A", "1"}, 14 | {" "}, 15 | {"Hello", "World"}, 16 | {""}, 17 | {"1", "2"}, 18 | {"a", "B"}, 19 | } 20 | for _, arg := range args { 21 | challenge.Program("samecase", arg...) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/secondhalf_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3, 4, 5}, 13 | {6, 7, 8, 9, 10}, 14 | {11, 12, 13, 14, 15}, 15 | {}, 16 | {10, 20, 30, 40}, 17 | {1, 2, 3}, 18 | } 19 | for _, arg := range args { 20 | challenge.Function("SecondHalf", solutions.SecondHalf, student.SecondHalf, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/setspace_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{ 12 | "Hello World", 13 | "HelloWorldB", 14 | "ClipClapWalk", 15 | "ClipClapWalkClipClapWalk", 16 | "#@13word", 17 | "Wron2Word", 18 | "Oneword", 19 | "", 20 | " ", 21 | "RightWordLargeWorldALotOfWords", 22 | "Onecapital", 23 | "loWerCaseInBeginning", 24 | } 25 | for _, arg := range args { 26 | challenge.Function("SetSpace", student.SetSpace, solutions.SetSpace, arg) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/shoppingsummarycounter_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"Burger Burger Water Coffee Water Chips Carrot", "Burger Burger Water Coffe e Water Chips Carrot", "Burger Burger Water Coffe e Water Chips Carrot", "32312&%", " ", "", "#$sds "} 12 | 13 | for _, s := range table { 14 | challenge.Function("ShoppingSummaryCounter", student.ShoppingSummaryCounter, solutions.ShoppingSummaryCounter, s) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/sliceadd_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := [][][]int{ 12 | {{1, 2, 3}, {1}}, 13 | {{3}, {5}}, 14 | {{1, 2}, {6}}, 15 | {{}, {0}}, 16 | {{12, 13, 32, 23, 3, 3, 2, 2, 1, 33, 4}, {-10}}, 17 | {{}, {-10}}, 18 | } 19 | for _, arg := range table { 20 | challenge.Function("SliceAdd", student.SliceAdd, solutions.SliceAdd, arg[0], arg[1][0]) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/sliceremove_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][][]int{ 12 | {{1, 2, 3, 4, 5}, {1}}, 13 | {{1, 2, 3, 4, 5}, {5}}, 14 | {{1, 2, 3, 4, 5}, {2}}, 15 | {{}, {1}}, 16 | {{1}, {1}}, 17 | {{1, 3, 4}, {2}}, 18 | {{1, 2}, {1}}, 19 | } 20 | for _, s := range args { 21 | challenge.Function("SliceRemove", student.SliceRemove, solutions.SliceRemove, s[0], s[1][0]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/sortparams_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | challenge.Program("sortparams", random.StrSlice(chars.Words)...) 11 | } 12 | -------------------------------------------------------------------------------- /tests/sqrt_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | "github.com/weightygroc/go-tests/solutions" 9 | ) 10 | 11 | func main() { 12 | table := append(random.IntSliceBetween(-1000000, 1000000), 13 | 0, 14 | 1, 15 | 2, 16 | 3, 17 | 4, 18 | 5, 19 | 6, 20 | 7, 21 | 8, 22 | 9, 23 | 10, 24 | 11, 25 | 12, 26 | 100, 27 | ) 28 | for _, arg := range table { 29 | challenge.Function("Sqrt", student.Sqrt, solutions.Sqrt, arg) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/squareroot_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | arr := []int{1, 244, 3, 45, -58, 8, 2147483647, 0, 98, 7} 12 | for _, arg := range arr { 13 | challenge.Function("SquareRoot", student.SquareRoot, solutions.SquareRoot, arg) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/stringtobool_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{ 12 | "true", 13 | "false", 14 | "TRUE", 15 | "FALSE", 16 | "1", 17 | "0", 18 | "Hello", 19 | "World", 20 | "T", 21 | "F", 22 | "t", 23 | "True", 24 | } 25 | for _, s := range args { 26 | challenge.Function("StringToBool", student.StringToBool, solutions.StringToBool, s) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/strisnegative_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{ 12 | "", 13 | "0", 14 | "-551", 15 | "+551", 16 | "585 41 -9", 17 | "hekiii", 18 | "sda", 19 | "2147483647", 20 | "5898", 21 | "697abc8", 22 | "82-58", 23 | "-2147483648", 24 | " -585", 25 | "10 15", 26 | "975 ", 27 | } 28 | for _, arg := range table { 29 | challenge.Function("StrisNegative", student.StrisNegative, solutions.StrisNegative, arg) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/strlen_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | args := []string{"Héllo!", random.Str(chars.Words, 26)} 14 | for i := 0; i < 10; i++ { 15 | args = append(args, random.Str(chars.Words, random.IntBetween(1, 20))) 16 | } 17 | for _, s := range args { 18 | challenge.Function("StrLen", student.StrLen, solutions.StrLen, s) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/strrev_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := append( 14 | random.StrSlice(chars.ASCII), 15 | "Hello!", 16 | "Bonjour!", 17 | "Hola!", 18 | ) 19 | for _, arg := range table { 20 | challenge.Function("StrRev", student.StrRev, solutions.StrRev, arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/sum_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]string{ 12 | {"0", "0"}, 13 | {"1", "0"}, 14 | {"0", "1"}, 15 | {"1", "2"}, 16 | {"9", "9"}, 17 | {"-9", "-9"}, 18 | {"-3", "7"}, 19 | {"8", "-7"}, 20 | {"11", "7"}, 21 | {"6", "256"}, 22 | } 23 | for _, arg := range args { 24 | challenge.Function("Sum", student.Sum, solutions.Sum, arg[0], arg[1]) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/sumarray_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {2, 5, 19}, 13 | {2}, 14 | {1, 2, 3, 5, 7, 24}, 15 | {-10, 10, 20, 30, 40, 50}, 16 | {}, 17 | {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}, 18 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 19 | } 20 | for _, v := range args { 21 | challenge.Function("SumArray", student.SumArray, solutions.SumArray, v) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/sumascii_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/weightygroc/go-tests/lib/challenge" 4 | 5 | func main() { 6 | args := [][]string{ 7 | {"S", "A"}, 8 | {"One", "ring!"}, 9 | {"A", "B"}, 10 | {"E", "Z"}, 11 | {"z", "R"}, 12 | {"testing spaces and #!*"}, 13 | {"more", "than", "three", "arguments"}, 14 | {"W"}, 15 | {"1"}, 16 | {" "}, 17 | {""}, 18 | {}, 19 | } 20 | for _, arg := range args { 21 | challenge.Program("sumascii", arg...) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/swap_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | i := 0 12 | for i < 30 { 13 | a := random.Int() 14 | b := random.Int() 15 | aCopy := a 16 | bCopy := b 17 | student.Swap(&a, &b) 18 | if a != bCopy { 19 | challenge.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) 20 | } 21 | if b != aCopy { 22 | challenge.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) 23 | } 24 | i++ 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/swapargs_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | ) 6 | 7 | func main() { 8 | table := [][]string{ 9 | {"choumi", "is", "the", "best", "cat"}, 10 | {" "}, 11 | {""}, 12 | {"hello", "world"}, 13 | {"1", "2"}, 14 | {"", " "}, 15 | } 16 | for _, s := range table { 17 | challenge.Program("swapargs", s...) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/swapfirst_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3, 4, 5}, 13 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 14 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, 15 | {}, 16 | {1}, 17 | {1, 2}, 18 | {1, 2, 3}, 19 | } 20 | for _, arg := range args { 21 | challenge.Function("SwapFirst", student.SwapFirst, solutions.SwapFirst, arg) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/swaplast_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := [][]int{ 12 | {1, 2, 3, 4, 5}, 13 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 14 | {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, 15 | {}, 16 | {1}, 17 | {1, 2}, 18 | {1, 2, 3}, 19 | } 20 | for _, arg := range args { 21 | challenge.Function("SwapLast", student.SwapLast, solutions.SwapLast, arg) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/switchcase_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/weightygroc/go-tests/lib/challenge" 5 | "github.com/weightygroc/go-tests/lib/chars" 6 | "github.com/weightygroc/go-tests/lib/random" 7 | ) 8 | 9 | func main() { 10 | table := append(random.StrSlice(chars.Words), 11 | " ", 12 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 13 | "abcdefghi jklmnop qrstuvwxyz ABCDEFGHI JKLMNOPQR STUVWXYZ ! ", 14 | ) 15 | for _, s := range table { 16 | challenge.Program("switchcase", s) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/tabmult_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | var table []string 12 | for i := 1; i < 10; i++ { 13 | table = append(table, strconv.Itoa(i)) 14 | } 15 | for i := 0; i < 5; i++ { 16 | table = append(table, strconv.Itoa(random.IntBetween(1, 1000))) 17 | } 18 | 19 | for _, arg := range table { 20 | challenge.Program("tabmult", arg) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/thirdtimeisacharm_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"1234556789", "QKplq%QSw", "", "Kimetsu no Yaiba", "Z", "email123@live.fr", "8595485-52", "-552", "abc", "w58tw7474abc", "fifa world cup `2022`"} 12 | 13 | for _, s := range table { 14 | challenge.Function("ThirdTimeIsACharm", student.ThirdTimeIsACharm, solutions.ThirdTimeIsACharm, s) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/tolower_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := append(random.StrSlice(chars.ASCII), "Hello! How are you?") 14 | for _, arg := range table { 15 | challenge.Function("ToLower", student.ToLower, solutions.ToLower, arg) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/toupper_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | table := append(random.StrSlice(chars.ASCII), "Hello! How are you?") 14 | for _, arg := range table { 15 | challenge.Function("ToUpper", student.ToUpper, solutions.ToUpper, arg) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/twosum_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "math/rand" 5 | 6 | student "student" 7 | 8 | "github.com/weightygroc/go-tests/lib/challenge" 9 | "github.com/weightygroc/go-tests/solutions" 10 | ) 11 | 12 | func main() { 13 | for i := 0; i < 20; i++ { 14 | token := rand.Perm(20) 15 | target := rand.Intn(30) 16 | challenge.Function("TwoSum", student.TwoSum, solutions.TwoSum, token, target) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/ultimatedivmod_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/random" 8 | ) 9 | 10 | func main() { 11 | for i := 0; i < 8; i++ { 12 | a := random.Int() 13 | b := random.Int() 14 | aCopy := a 15 | bCopy := b 16 | div := a / b 17 | mod := a % b 18 | student.UltimateDivMod(&a, &b) 19 | if a != div { 20 | challenge.Fatalf("DivMod(%d, %d), a == %d instead of %d", aCopy, bCopy, a, div) 21 | } 22 | if b != mod { 23 | challenge.Fatalf("DivMod(%d, %d), b == %d instead of %d", aCopy, bCopy, b, mod) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/ultimatepointone_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | ) 8 | 9 | func main() { 10 | a := 0 11 | b := &a 12 | n := &b 13 | student.UltimatePointOne(&n) 14 | if a != 1 { 15 | challenge.Fatalf("UltimatePointOne(&n), a == %d instead of 1", a) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/vowelsindex_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"student", "hello Iyan", "world","ptghjkvl", "Hello! How are you?", "AAEO$%&UOTX", "", "AEMNOoa*+-aeiou", "wo5opi=ws8;eza"} 12 | 13 | for _, arg := range table { 14 | challenge.Function("VowelsIndex", student.VowelsIndex, solutions.VowelsIndex, arg) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/wdmatch_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/lib/chars" 8 | "github.com/weightygroc/go-tests/lib/random" 9 | ) 10 | 11 | func main() { 12 | table := append(random.StrSlice(chars.Words), 13 | " ", 14 | "123 123", 15 | "abc abc", 16 | "ac abc", 17 | "13 123", 18 | "faya fgvvfdxcacpolhyghbreda", 19 | "faya fgvvfdxcacpolhyghbred", 20 | "error rrerrrfiiljdfxjyuifrrvcoojh", 21 | "error rrerrrfiiljdfxjyuifrrvcoojrh", 22 | ) 23 | 24 | for _, s := range table { 25 | challenge.Program("wdmatch", strings.Fields(s)...) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/wordflip_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | table := []string{"First second last", " ", " Bleach ", " Attack on Titan", "Spy X Family", "Z", "email123@live.fr", "write ==> 45m$", "-552", "w58tw7474abc", "fifa world cup `2022`"} 12 | for _, s := range table { 13 | challenge.Function("WordFlip", student.WordFlip, solutions.WordFlip, s) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/zipstring_test/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | student "student" 5 | 6 | "github.com/weightygroc/go-tests/lib/challenge" 7 | "github.com/weightygroc/go-tests/solutions" 8 | ) 9 | 10 | func main() { 11 | args := []string{ 12 | "aaaa", 13 | "zzzzzZZZZZZ", 14 | "", 15 | "ziiiiipMeee", 16 | "hhellloTthereYouuunggFelllas", 17 | } 18 | 19 | for _, arg := range args { 20 | challenge.Function("ZipString", student.ZipString, solutions.ZipString, arg) 21 | } 22 | } 23 | --------------------------------------------------------------------------------