aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHVukman <peterslopp@googlemail.com>2025-11-16 20:53:02 +0100
committerGitHub <noreply@github.com>2025-11-16 20:53:02 +0100
commit022a87da3c4407ebbda26c677337756f75f77aa1 (patch)
treefd36886e554d94abd5438f52947988d9d5a989c9
parenta88837e0bdc4d457baded76be3a0ac309e2bd1ee (diff)
downloadperlweeklychallenge-club-022a87da3c4407ebbda26c677337756f75f77aa1.tar.gz
perlweeklychallenge-club-022a87da3c4407ebbda26c677337756f75f77aa1.tar.bz2
perlweeklychallenge-club-022a87da3c4407ebbda26c677337756f75f77aa1.zip
Create 347_p2.odin
-rw-r--r--challenge-347/hvukman/odin/part2/347_p2.odin78
1 files changed, 78 insertions, 0 deletions
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(" ")
+ }
+
+}