Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Post History

71%
+3 −0
Sandbox 12-hour time is weird [finalized]

posted 10mo ago by honnza‭  ·  edited 10mo ago by honnza‭

#3: Post edited by user avatar honnza‭ · 2024-03-08T13:34:53Z (10 months ago)
  • 12-hour time is weird
  • 12-hour time is weird [finalized]
  • Your mission for today, should you choose to accept it, is to write a simple [12-hour clock](https://en.m.wikipedia.org/wiki/12-hour_clock) calculator. Your input will always be in the form of `arg op arg`, where `op` is either `+` or `-`, and `arg` is either:
  • * Absolute hour, which is one of, in sequence, `12 AM`, `1 AM` through `11 AM`, `12 PM`, or `1 PM` through `11 PM`. The sequence then repeats cyclically.
  • * Time offset, which goes from `(-11)` through `(+0)` to `(+12)` inclusive. `(-0)` is not a permitted notation.
  • In either case, a leading zero is not permitted.
  • Your output shall be:
  • * If the input is in the form offset + offset or offset - offset, add/subtract the offsets as indicated. If the value exceeds `(+12)`, subtract 24 from the offset. If the value is lower than `(-11)`, add 24 to the offset.
  • E.g. `(-7) + (-5) = (+12)`, `(-7) - (-5) = (-2)`
  • * If the input is in the form absolute + offset, absolute - offset or offset + absolute, output the corresponding absolute hour.
  • E.g. `7 AM + (-5) = (-5) + 7 AM = 2 AM`, `7 AM - (-5) = 7 AM + (+5) = 12 PM`
  • * If the input is in the form absolute - absolute, output the unique offset such that right + offset = left.
  • E.g. `12 PM - 1 PM = (-1)`, `11 PM - 1 PM = (+10)`
  • * If the input is in the form offset - absolute or absolute + absolute, output `TE` (type error).
  • You may assume that the input follows the syntax and range limits defined above. Your output is required to follow the same syntax and range limits that apply to the input arguments.
  • Posted: https://codegolf.codidact.com/posts/291018
  • Your mission for today, should you choose to accept it, is to write a simple [12-hour clock](https://en.m.wikipedia.org/wiki/12-hour_clock) calculator. Your input will always be in the form of `arg op arg`, where `op` is either `+` or `-`, and `arg` is either:
  • * Absolute hour, which is one of, in sequence, `12 AM`, `1 AM` through `11 AM`, `12 PM`, or `1 PM` through `11 PM`. The sequence then repeats cyclically.
  • * Time offset, which goes from `(-11)` through `(+0)` to `(+12)` inclusive. `(-0)` is not a permitted notation.
  • In either case, a leading zero is not permitted.
  • Your output shall be:
  • * If the input is in the form offset + offset or offset - offset, add/subtract the offsets as indicated. If the value exceeds `(+12)`, subtract 24 from the offset. If the value is lower than `(-11)`, add 24 to the offset.
  • E.g. `(-7) + (-5) = (+12)`, `(-7) - (-5) = (-2)`
  • * If the input is in the form absolute + offset, absolute - offset or offset + absolute, output the corresponding absolute hour.
  • E.g. `7 AM + (-5) = (-5) + 7 AM = 2 AM`, `7 AM - (-5) = 7 AM + (+5) = 12 PM`
  • * If the input is in the form absolute - absolute, output the unique offset such that right + offset = left.
  • E.g. `12 PM - 1 PM = (-1)`, `11 PM - 1 PM = (+10)`
  • * If the input is in the form offset - absolute or absolute + absolute, output `TE` (type error).
  • You may assume that the input follows the syntax and range limits defined above. Your output is required to follow the same syntax and range limits that apply to the input arguments.
#2: Post edited by user avatar honnza‭ · 2024-03-06T22:04:28Z (10 months ago)
  • Your mission for today, should you choose to accept it, is to write a simple [12-hour clock](https://en.m.wikipedia.org/wiki/12-hour_clock) calculator. Your input will always be in the form of `arg op arg`, where `op` is either `+` or `-`, and `arg` is either:
  • * Absolute hour, which is one of, in sequence, `12 AM`, `1 AM` through `11 AM`, `12 PM`, or `1 PM` through `11 PM`. The sequence then repeats cyclically.
  • * Time offset, which goes from `(-11)` through `(+0)` to `(+12)` inclusive. `(-0)` is not a permitted notation.
  • In either case, a leading zero is not permitted.
  • Your output shall be:
  • * If the input is in the form offset + offset or offset - offset, add/subtract the offsets as indicated. If the value exceeds `(+12)`, subtract 24 from the offset. If the value is lower than `(-11)`, add 24 to the offset.
  • E.g. `(-7) + (-5) = (+12)`, `(-7) - (-5) = (-2)`
  • * If the input is in the form absolute + offset, absolute - offset or offset + absolute, output the corresponding absolute hour.
  • E.g. `7 AM + (-5) = (-5) + 7 AM = 2 AM`, `7 AM - (-5) = 7 AM + (+5) = 12 PM`
  • * If the input is in the form absolute - absolute, output the unique offset such that right + offset = left.
  • E.g. `12 PM - 1 AM = (-1)`, `11 PM - 1 PM = (+10)`
  • * If the input is in the form offset - absolute or absolute + absolute, output `TE` (type error).
  • You may assume that the input follows the syntax and range limits defined above. Your output is required to follow the same syntax and range limits that apply to the input arguments.
  • Your mission for today, should you choose to accept it, is to write a simple [12-hour clock](https://en.m.wikipedia.org/wiki/12-hour_clock) calculator. Your input will always be in the form of `arg op arg`, where `op` is either `+` or `-`, and `arg` is either:
  • * Absolute hour, which is one of, in sequence, `12 AM`, `1 AM` through `11 AM`, `12 PM`, or `1 PM` through `11 PM`. The sequence then repeats cyclically.
  • * Time offset, which goes from `(-11)` through `(+0)` to `(+12)` inclusive. `(-0)` is not a permitted notation.
  • In either case, a leading zero is not permitted.
  • Your output shall be:
  • * If the input is in the form offset + offset or offset - offset, add/subtract the offsets as indicated. If the value exceeds `(+12)`, subtract 24 from the offset. If the value is lower than `(-11)`, add 24 to the offset.
  • E.g. `(-7) + (-5) = (+12)`, `(-7) - (-5) = (-2)`
  • * If the input is in the form absolute + offset, absolute - offset or offset + absolute, output the corresponding absolute hour.
  • E.g. `7 AM + (-5) = (-5) + 7 AM = 2 AM`, `7 AM - (-5) = 7 AM + (+5) = 12 PM`
  • * If the input is in the form absolute - absolute, output the unique offset such that right + offset = left.
  • E.g. `12 PM - 1 PM = (-1)`, `11 PM - 1 PM = (+10)`
  • * If the input is in the form offset - absolute or absolute + absolute, output `TE` (type error).
  • You may assume that the input follows the syntax and range limits defined above. Your output is required to follow the same syntax and range limits that apply to the input arguments.
#1: Initial revision by user avatar honnza‭ · 2024-03-06T11:03:13Z (10 months ago)
12-hour time is weird
Your mission for today, should you choose to accept it, is to write a simple [12-hour clock](https://en.m.wikipedia.org/wiki/12-hour_clock) calculator. Your input will always be in the form of `arg op arg`, where `op` is either `+` or `-`, and `arg` is either:
* Absolute hour, which is one of, in sequence, `12 AM`, `1 AM` through `11 AM`, `12 PM`, or `1 PM` through `11 PM`. The sequence then repeats cyclically.
* Time offset, which goes from `(-11)` through `(+0)` to `(+12)` inclusive. `(-0)` is not a permitted notation.

In either case, a leading zero is not permitted.

Your output shall be:
* If the input is in the form offset + offset or offset - offset, add/subtract the offsets as indicated. If the value exceeds `(+12)`, subtract 24 from the offset. If the value is lower than `(-11)`, add 24 to the offset.  
E.g. `(-7) + (-5) = (+12)`, `(-7) - (-5) = (-2)`
* If the input is in the form absolute + offset, absolute - offset or offset + absolute, output the corresponding absolute hour.  
E.g. `7 AM + (-5) = (-5) + 7 AM = 2 AM`, `7 AM - (-5) = 7 AM + (+5) = 12 PM`
* If the input is in the form absolute - absolute, output the unique offset such that right + offset = left.  
E.g. `12 PM - 1 AM = (-1)`, `11 PM - 1 PM = (+10)`
* If the input is in the form offset - absolute or absolute + absolute, output `TE` (type error).

You may assume that the input follows the syntax and range limits defined above. Your output is required to follow the same syntax and range limits that apply to the input arguments.