aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHVukman <peterslopp@googlemail.com>2025-11-16 20:52:31 +0100
committerGitHub <noreply@github.com>2025-11-16 20:52:31 +0100
commita88837e0bdc4d457baded76be3a0ac309e2bd1ee (patch)
treeab13d5cf45828b87ada3d4304b35c0407e06cd9e
parent4175bc8a7ecc7650796f2923f84b9d3d903a2cae (diff)
downloadperlweeklychallenge-club-a88837e0bdc4d457baded76be3a0ac309e2bd1ee.tar.gz
perlweeklychallenge-club-a88837e0bdc4d457baded76be3a0ac309e2bd1ee.tar.bz2
perlweeklychallenge-club-a88837e0bdc4d457baded76be3a0ac309e2bd1ee.zip
Create 347_p1.odin
-rw-r--r--challenge-347/hvukman/odin/part1/347_p1.odin56
1 files changed, 56 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()
+ }
+
+
+
+}