# Get delta of days by current hour and added delta of days

Inputs:

• current hour: from 0 to 23 (inclusive)
• delta of hours: [current hour] + [delta of hours] = withing the range of Integer

Output:

• delta of days: the value which shows difference in days between day of current hour and day of sum [current hour] + [delta of hours]

Scoring

• Answers will be scored in bytes with fewer bytes being better.

Examples:

• [current hour] = 23; [delta of hours] = -23; delta of days = 0
• [current hour] = 23; [delta of hours] = 1; delta of days = 1
• [current hour] = 23; [delta of hours] = 24; delta of days = 1
• [current hour] = 23; [delta of hours] = 25; delta of days = 2
• [current hour] = 23; [delta of hours] = -24; delta of days = -1
• [current hour] = 23; [delta of hours] = -47; delta of days = -1
• Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf? – Arnauld Jul 26 '19 at 9:39
• @Arnauld , yeah, is it enough to specify tag? – Ivan Gerasimenko Jul 26 '19 at 9:49
• Yes, that's fine. – Arnauld Jul 26 '19 at 9:51
• Welcome to the site! I am going to have to disagree with Arnauld and suggest that a description of the winning criterion is present in the body of the challenge. Here is a good summary of why I think this which seems to have the approval of our community. I've gone ahead and edited a winning criterion into your challenge based on my best guess feel free to change it. – Post Rock Garf Hunter Jul 26 '19 at 11:38
• @SriotchilismO'Zaic , nice! Thank you – Ivan Gerasimenko Jul 26 '19 at 11:47

# JavaScript (ES6),  26  25 bytes

Takes input as (current)(delta).

a=>b=>(a+b-(a<-b)*2)/3>>3


Try it online!

### Commented

a =>                // a = current hour
b =>                // b = delta of hours
(                 //
a + b           // 1) we compute the sum
- (a < -b) * 2  //    and we subtract 2 if this sum is negative
//    examples:
//      51 remains 51
//      23 remains 23
//      -1 is turned into -3
) / 3             // 2) float division by 3
//    examples:
//      51 is turned into 17
//      23 is turned into 7.666…
//      -3 is turned back into -1
>> 3              // 3) right arithmetic shift by 3 on the integer part
//    examples:
//      17 becomes 2
//      7.666… becomes 0
//      -1 is unchanged


# JavaScript (ES6), 26 bytes

More straightforward, but less fun and 1 byte longer anyway.

Takes input as (current)(delta).

a=>b=>Math.floor((a+b)/24)


Try it online!

# Jelly, 4 bytes

+:24


Try it online!

+ add the arguments

:24 integer divide by 24

# APL (Dyalog Unicode), 6 bytesSBCS

Anonymous tacit infix function, taking current and delta as arguments.

⌊24÷⍨+


Try it online!

+ add the arguments

24÷⍨ divide that by 24

⌊ floor

# 05AB1E (legacy), 4 bytes

+24÷


# 05AB1E, 11 5 bytes

+24/ï


Explanation:

+      # Sum the two (implicit) input-integers together
24÷   # Integer-divide this sum by 24
# (after which the result is output implicitly)

+      # Sum the two (implicit) input-integers together
24/   # Divide this sum by 24
ï  # Floor
# (after which the result is output implicitly)


The legacy version of 05AB1E uses a Python compiler. When integer-dividing, it will always floor the integer, whether the integer it divides is positive or negative.

The new version of 05AB1E uses an Elixir compiler. When integer-dividing in the new version of 05AB1E, it will round towards 0 (so basically truncates the decimal digits after dividing). So this will floor for positive integers, but ceil for negative integers.

• 5 bytes? – Expired Data Jul 26 '19 at 10:41
• @ExpiredData Ah, noticed your comment after Adam's answer. But you're indeed right this can be done much easier.. Maybe I should just delete my answer out of shame and let you get the 5-byter. ;) – Kevin Cruijssen Jul 26 '19 at 10:52
• nah I'm sure you'll pay me back in bytes saved given how terrible me 05AB1E is at the moment so don't worry! – Expired Data Jul 26 '19 at 10:53
• @Adám That's what I initially had in mind when I saw the challenge, but it doesn't work for the [23,-24] and [23,-48] test cases. Which is why I had that weird 11 byter as my initial answer. Integer division will ceil for negative integers, instead of floor. – Kevin Cruijssen Jul 26 '19 at 11:29
• Ah, so it rounds towards 0. Fair enough. – Adám Jul 26 '19 at 11:32

# Python 3, 20 19 bytes

Simple lambda:

lambda*a:sum(a)//24


-1 byte thanx to Jonathan Allan

Try it online!

Full program for 38 bytes:

print((int(input())+int(input()))//24)

• Save a byte with *args like so: lambda*a:sum(a)//24. Switch to Python 2 and save another with lambda*a:sum(a)/24. – Jonathan Allan Jul 26 '19 at 15:18

# R, 28 16 bytes

Just a port of most of the other answers...
-12 bytes thanks Giuseppe

sum(scan())%/%24


Try it online!

• Use x%/%y instead of floor(x/y) – Giuseppe Jul 26 '19 at 20:16
• Or better yet, take input from stdin and do sum(scan())%/%24 – Giuseppe Jul 26 '19 at 20:18
• Nice one. Will have to remember that trick. – Robert S. Jul 26 '19 at 20:21

((div24).).(+)


Try it online!

If taking input as a list is allowed, this can be done in 13 bytes (thanks cole):

(div24).sum


Try it online!

I've seen people leave off the function declaration in the byte count for pointfree style, so I'm doing the same here.

Explanation:

(div24)


div is the shorter integer division operator. Haskell has this nice syntactic sugar where you can curry infixes by putting the argument on its respective side of the infix (thanks mimi), so this is a function that does integer division by 24.

The double composition is a little weird to explain, so I'll follow the template of this great SO answer:

f a b = (div24) (a + b)       -- what we want
f a b = (div24) ((+) a b)     -- un-infixing (+)
f a b = ((div24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = ((div24) . ((+) a)       -- pointfree reduction
f a = ((div24) .) ((+) a)     -- associative property
f a = (((div24) .) . (+)) a   -- definition of function composition
f = ((div24).) . (+)            -- pointfree reduction


When this takes a list as input, the sum function only has one argument, so the extra composition isn't needed (since we don't have to do that extra curry).

• You can use backquotes instead of flip: ((div24).).(+). – nimi Jul 27 '19 at 11:09
• if you can take input as an array, then (div24).sum is shorter – cole Jul 28 '19 at 6:04

# Ohm v2, 4 bytes

+24v


Try it online!

# C# (Visual C# Interactive Compiler), 26 bytes

a=>b=>Math.Floor((a+b)/24)


Try it online!

# Perl 6, 11 bytes

(*+*)div 24


Try it online!

Anonymous Whatever lambda that takes two arguments and returns the sum of the two integer divided by 24

# Lua, 32 26 bytes

print((arg[1]+arg[2])//24)


Try it online!

Rather boring solution. Take input as arguments, print to stdout. Require Lua 5.3 or greater.

# Old solution: Lua, 32 bytes

function(a,b)return(a+b)//24 end


Try it online!

Same idea, but implemented as function instead of full program.

• Nice. Thought briefly about a function, but didn't take the time. – ouflak Jul 29 '19 at 20:45
• @ouflak New solution is full program taking input as command like arguments tho. – val says Reinstate Monica Jul 29 '19 at 20:56

# Lua, 70 50 bytes

c,d=io.read():match("(%S+) (%S+)")print((c+d)//24)


-20 bytes thanks to val

Try it online!

• Second line can be made shorter by specifying valid input format. Third line is just print((c+d)//24) in Lua 5.3. There are also some other ways to golf this. – val says Reinstate Monica Jul 28 '19 at 9:36
• Mind if I'll edit and improve your answer later today? Mine is shorter, but your is full program. – val says Reinstate Monica Jul 28 '19 at 9:37
• @val, Just go ahead and post your solution with your own TIO. Or if you don't want to do that, just comment here your suggested improvement and I'll edit it giving credit. These options seem to be the way things work around here. – ouflak Jul 28 '19 at 21:46
• 50 bytes: Try it online!. Use space separated input. I'll also add another solution which take arguments from command line to my answer. – val says Reinstate Monica Jul 29 '19 at 14:25

# I, 6 bytes

Anonymous tacit infix function, taking current and delta as arguments.

+/24.m


Try it online!

Beginning with:

+ the sum of the arguments

/ divide by:

24 twentyfour

. apply:

m floor (minimum)

# Retina 0.8.2, 41 bytes

\d+,?
$* (1+)-\1 - ^((-)1|1{24})*.*$2$#1  Try it online! Link includes test suite. Explanation: \d+,?$*


Convert both inputs to unary and take the sum if the second input is positive.

(1+)-\1
-


But if the second input is negative then take the difference.

^((-)1|1{24})*.*
$2$#1


Floor divide the input by 24 and convert to decimal. For positive numbers the first alternation never matches so this just counts the number of whole multiples of 24 in the number. For negative numbers the leading -1 counts as an extra negative multiple of 24 in addition to any remaining multiples of 24, thus achieving the desired floor division.

# Python 2, 18 bytes

lambda*a:sum(a)/24


Try it online!

# Perl 5 (-MPOSIX=floor -MList::Util=sum -alp), 19 bytes

$_=floor+(sum@F)/24  TIO # Whitespace, 49 bytes [S S S N _Push_0][S N S _Duplicate_0][T N T T _Read_STDIN_as_integer][T T T _Retrieve_input][S S S N _Push_0][S N S _Duplicate_0][T N T T _Read_STDIN_as_integer][T T T _Retrieve_input][T S S S _Add][S S S T T S S S N _Push_24][T S T S _integer_division][T N S T _Print_as_integer]  Letters S (space), T (tab), and N (new-line) added as highlighting only. [..._some_action] added as explanation only. Try it online (with raw spaces, tabs, and new-lines only). Explanation in pseudo-code: Integer a = STDIN as integer Integer b = STDIN as integer a = a + b a = a integer-divided by 24 Print a as integer to STDOUT  # Forth (gforth), 12 bytes : f + 24 / ;  Try it online! ### Code Explanation : f \ start a new word definition + \ add current hour and delta 24 / \ (integer) divide result by 24, round towards negative infinity ; \ end word definition  # PHP, 29 bytes <?=floor((date(G)+$argn)/24);


Try it online!

Full program, with current hour being the current hour on the platform host, and delta of hours input via STDIN.

Or

# PHP, 30 bytes

<?=floor(array_sum(\$argv)/24);


Try it online!

Input of current hour and delta of hours via command line.