diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-11-16 20:43:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-16 20:43:33 +0000 |
| commit | 5686877d65d9edfa938bacf078fcabedaff96812 (patch) | |
| tree | f467493b3bb329da9c8b5bee2a4b436398573aab | |
| parent | 3ae0d75a89314b9a330324dd463d7a8da7baddea (diff) | |
| parent | 022a87da3c4407ebbda26c677337756f75f77aa1 (diff) | |
| download | perlweeklychallenge-club-5686877d65d9edfa938bacf078fcabedaff96812.tar.gz perlweeklychallenge-club-5686877d65d9edfa938bacf078fcabedaff96812.tar.bz2 perlweeklychallenge-club-5686877d65d9edfa938bacf078fcabedaff96812.zip | |
Merge pull request #13035 from HVukman/branch-for-challenge-347
Branch for challenge 347
| -rw-r--r-- | challenge-347/hvukman/odin/part1/347_p1.odin | 56 | ||||
| -rw-r--r-- | challenge-347/hvukman/odin/part2/347_p2.odin | 78 |
2 files changed, 134 insertions, 0 deletions
diff --git a/challenge-347/hvukman/odin/part1/347_p1.odin b/challenge-347/hvukman/odin/part1/347_p1.odin new file mode 100644 index 0000000000..24ae6a0342 --- /dev/null +++ b/challenge-347/hvukman/odin/part1/347_p1.odin @@ -0,0 +1,56 @@ +package p1347 + +import "core:fmt" +import "core:strings" +import "core:slice" +import "core:strconv" + + +format_date ::proc(inp:^string){ + MONTHS := []string{"Jan", "Feb", "Mar", "Apr", "May","June","July","August","Sep","Oct","Nov","Dec"} + // reverse loop for the format + #reverse for v,i in strings.split(inp^," "){ + + switch i{ + // switch indices + case 2: + // sep="" for the right format + fmt.print(v,"-",sep="") + case 1: + // find index and add one; if below zero add 0 in front + ind,found:=slice.linear_search(MONTHS,v) + if ind < 9{ + fmt.print("0",ind+1,"-",sep="") + } + else{ + fmt.print(ind+1,"-",sep="") + } + case 0: + sub,_:=strings.substring(v,0,2) + num,isnum:= strconv.parse_int(sub) + // if first two chars are numbers, print ; else add 0 in front + if isnum{ + fmt.print(sub,sep="") + } + else{ + sub,_:=strings.substring(v,0,1) + fmt.print("0",sub,sep="") + } + + } + } +} + +main :: proc() { + + + inpt:= []string{"1st Jan 2025","22nd Feb 2025","15th Apr 2025","23rd Oct 2025","31st Dec 2025"} + + for &i in inpt{ + format_date(&i) + fmt.println() + } + + + +} diff --git a/challenge-347/hvukman/odin/part2/347_p2.odin b/challenge-347/hvukman/odin/part2/347_p2.odin new file mode 100644 index 0000000000..f6bc7f20ff --- /dev/null +++ b/challenge-347/hvukman/odin/part2/347_p2.odin @@ -0,0 +1,78 @@ +package p2347 + +import "core:fmt" +import "core:strings" + + +remove :: proc(str,rem:string)->string{ + // remove the rem string from str; return str_ + str_,_:=strings.remove_all(str,rem) + return str_ +} + + +format_phone::proc(inpt:string){ + ind:=0 + // look for length of inpt and print "-" at the right place + for v,i in inpt{ + + fmt.print(v,sep="") + ind = ind+1 + if len(inpt)%4==0 && len(inpt)>4 + { + if ind==3&&i!=len(inpt)-1 + { + fmt.print("-",sep="") + ind=0 + } + } + else if len(inpt)%3==0 + { + if ind==3&&i!=len(inpt)-1 + { + fmt.print("-",sep="") + ind=0 + } + } + else if len(inpt)%2==0 + { + if ind==2&&i!=len(inpt)-1 + { + fmt.print("-",sep="") + ind=0 + } + }else{ + // 4th case only + if ind==3&&i!=len(inpt)-1&&len(inpt)-i>=4{ + fmt.print("-",sep="") + ind=0 + } + else if ind==2&&i!=len(inpt)-1&&len(inpt)-i==3{ + fmt.print("-",sep="") + ind=0 + } + } + + + } + + +} + +main ::proc(){ + + removed:= []string{"-"," "} + + inputs:= []string{"1-23-45-6","12 34","12 345-6789","123 4567","123 456-78"} + + for i in inputs{ + i:=i + for j in removed + { + i= remove(i,j) + } + format_phone(i) + fmt.println(" ") + } + +} |
