From 022a87da3c4407ebbda26c677337756f75f77aa1 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 16 Nov 2025 20:53:02 +0100 Subject: Create 347_p2.odin --- challenge-347/hvukman/odin/part2/347_p2.odin | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 challenge-347/hvukman/odin/part2/347_p2.odin 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(" ") + } + +} -- cgit