Get delta of days by current hour and added delta of daysAdvance Happy New Year, 2016!Difference of the square of the sumChange the TimezoneHow many times will a bell tower ring?Sums of 24-hour timeSort a difference listFind the smallest triangle encompassing the specified polygonCount the lucky tickets within the given rangeAll ASCII characters with a given bit countAnalog is Obtuse!
Decreasing star size
Is this photo showing a woman posing in the nude before teenagers real?
Character is called by their first initial. How do I write it?
Why are all my history books dividing Chinese history after the Han dynasty?
Why can't my huge trees be chopped down?
Inadvertently nuked my disk permission structure - why?
Expansion with *.txt in the shell doesn't work if no .txt file exists
The Sword in the Stone
Is it legal for private citizens to "impound" e-scooters?
What does コテッと mean?
Why did so many MPs not vote in Meaningful Vote 3?
High income, sudden windfall
How can I prevent corporations from growing their own workforce?
What is AM-CM inequality?
How do I stop my characters falling in love?
Integral of the integral using NIntegrate
Giant space birds hatching out of planets; short story
At what rate does the volume (velocity) of a note decay?
Why is drive/partition number still used?
What's the difference between 2a and 10a charging options?
Trying to build a function to compute divided difference for arbitrary list of points
Print sums of all subsets
How acidic does a mixture have to be for milk to curdle?
Is a fighting a fallen friend with the help of a redeemed villain story too much for one book
Get delta of days by current hour and added delta of days
Advance Happy New Year, 2016!Difference of the square of the sumChange the TimezoneHow many times will a bell tower ring?Sums of 24-hour timeSort a difference listFind the smallest triangle encompassing the specified polygonCount the lucky tickets within the given rangeAll ASCII characters with a given bit countAnalog is Obtuse!
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Inputs:
current hour
: from 0 to 23 (inclusive)delta of hours
:[current hour]
+[delta of hours]
= withing the range ofInteger
Output:
delta of days
: the value which shows difference in days between day ofcurrent 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
code-golf date
New contributor
$endgroup$
add a comment |
$begingroup$
Inputs:
current hour
: from 0 to 23 (inclusive)delta of hours
:[current hour]
+[delta of hours]
= withing the range ofInteger
Output:
delta of days
: the value which shows difference in days between day ofcurrent 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
code-golf date
New contributor
$endgroup$
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday
add a comment |
$begingroup$
Inputs:
current hour
: from 0 to 23 (inclusive)delta of hours
:[current hour]
+[delta of hours]
= withing the range ofInteger
Output:
delta of days
: the value which shows difference in days between day ofcurrent 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
code-golf date
New contributor
$endgroup$
Inputs:
current hour
: from 0 to 23 (inclusive)delta of hours
:[current hour]
+[delta of hours]
= withing the range ofInteger
Output:
delta of days
: the value which shows difference in days between day ofcurrent 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
code-golf date
code-golf date
New contributor
New contributor
edited yesterday
Sriotchilism O'Zaic
37k10 gold badges168 silver badges379 bronze badges
37k10 gold badges168 silver badges379 bronze badges
New contributor
asked yesterday
Ivan GerasimenkoIvan Gerasimenko
1273 bronze badges
1273 bronze badges
New contributor
New contributor
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday
add a comment |
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday
add a comment |
13 Answers
13
active
oldest
votes
$begingroup$
Jelly, 4 bytes
+:24
Try it online!
+
add the arguments
:24
integer divide by 24
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
1
$begingroup$
Save a byte with*args
like so:lambda*a:sum(a)//24
. Switch to Python 2 and save another withlambda*a:sum(a)/24
.
$endgroup$
– Jonathan Allan
yesterday
add a comment |
$begingroup$
05AB1E (legacy), 4 bytes
+24÷
Try it online or verify all test cases.
05AB1E, 11 5 bytes
+24/ï
-6 bytes by porting @Adam's approach in his APL answer.
Try it online or verify all test cases.
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.
$endgroup$
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
|
show 1 more comment
$begingroup$
Ohm v2, 4 bytes
+24v
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 26 bytes
a=>b=>Math.Floor((a+b)/24)
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 18 bytes
(flip(div)24.).(+)
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:
flip(div)24
First, div
is the shorter integer division operator, but it takes in its arguments as x//24 => div x 24
, so we need to use flip so that we can partially apply it to 24.
The double composition is a little weird to explain, so I'll follow the template of this great SO answer:
f a b = (flip(div)24) (a + b) -- what we want
f a b = (flip(div)24) ((+) a b) -- un-infixing (+)
f a b = ((flip(div)24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = (flip(div)24) . ((+) a) -- pointfree reduction
f a = ((flip(div)24) .) ((+) a) -- associative property
f a = (((flip(div)24) .) . (+)) a -- definition of function composition
f = (flip(div)24.) . (+) -- pointfree reduction
$endgroup$
$begingroup$
You can use backquotes instead offlip
:((`div`24).).(+)
.
$endgroup$
– nimi
18 hours ago
add a comment |
$begingroup$
R, 28 16 bytes
Just a port of most of the other answers...
-12 bytes thanks Giuseppe
sum(scan())%/%24
Try it online!
$endgroup$
$begingroup$
Usex%/%y
instead offloor(x/y)
$endgroup$
– Giuseppe
yesterday
1
$begingroup$
Or better yet, take input from stdin and dosum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
add a comment |
$begingroup$
Lua, 70 bytes
s=io.read()
c,d=s:match("([^,]+),([^,]+)")
print(math.floor((c+d)/24))
Try it online!
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 41 bytes
d+,?
$*
(1+)-1
-
^((-)1|124)*.*
$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|124)*.*
$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.
$endgroup$
add a comment |
$begingroup$
Python 2, 18 bytes
lambda*a:sum(a)/24
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Ivan Gerasimenko is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188809%2fget-delta-of-days-by-current-hour-and-added-delta-of-days%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Jelly, 4 bytes
+:24
Try it online!
+
add the arguments
:24
integer divide by 24
$endgroup$
add a comment |
$begingroup$
Jelly, 4 bytes
+:24
Try it online!
+
add the arguments
:24
integer divide by 24
$endgroup$
add a comment |
$begingroup$
Jelly, 4 bytes
+:24
Try it online!
+
add the arguments
:24
integer divide by 24
$endgroup$
Jelly, 4 bytes
+:24
Try it online!
+
add the arguments
:24
integer divide by 24
answered yesterday
AdámAdám
29k2 gold badges79 silver badges212 bronze badges
29k2 gold badges79 silver badges212 bronze badges
add a comment |
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
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
answered yesterday
AdámAdám
29k2 gold badges79 silver badges212 bronze badges
29k2 gold badges79 silver badges212 bronze badges
add a comment |
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
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!
edited 19 hours ago
answered yesterday
ArnauldArnauld
88.5k7 gold badges103 silver badges362 bronze badges
88.5k7 gold badges103 silver badges362 bronze badges
add a comment |
add a comment |
$begingroup$
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)
$endgroup$
1
$begingroup$
Save a byte with*args
like so:lambda*a:sum(a)//24
. Switch to Python 2 and save another withlambda*a:sum(a)/24
.
$endgroup$
– Jonathan Allan
yesterday
add a comment |
$begingroup$
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)
$endgroup$
1
$begingroup$
Save a byte with*args
like so:lambda*a:sum(a)//24
. Switch to Python 2 and save another withlambda*a:sum(a)/24
.
$endgroup$
– Jonathan Allan
yesterday
add a comment |
$begingroup$
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)
$endgroup$
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)
edited yesterday
answered yesterday
movaticamovatica
4586 bronze badges
4586 bronze badges
1
$begingroup$
Save a byte with*args
like so:lambda*a:sum(a)//24
. Switch to Python 2 and save another withlambda*a:sum(a)/24
.
$endgroup$
– Jonathan Allan
yesterday
add a comment |
1
$begingroup$
Save a byte with*args
like so:lambda*a:sum(a)//24
. Switch to Python 2 and save another withlambda*a:sum(a)/24
.
$endgroup$
– Jonathan Allan
yesterday
1
1
$begingroup$
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
.$endgroup$
– Jonathan Allan
yesterday
$begingroup$
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
.$endgroup$
– Jonathan Allan
yesterday
add a comment |
$begingroup$
05AB1E (legacy), 4 bytes
+24÷
Try it online or verify all test cases.
05AB1E, 11 5 bytes
+24/ï
-6 bytes by porting @Adam's approach in his APL answer.
Try it online or verify all test cases.
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.
$endgroup$
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
|
show 1 more comment
$begingroup$
05AB1E (legacy), 4 bytes
+24÷
Try it online or verify all test cases.
05AB1E, 11 5 bytes
+24/ï
-6 bytes by porting @Adam's approach in his APL answer.
Try it online or verify all test cases.
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.
$endgroup$
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
|
show 1 more comment
$begingroup$
05AB1E (legacy), 4 bytes
+24÷
Try it online or verify all test cases.
05AB1E, 11 5 bytes
+24/ï
-6 bytes by porting @Adam's approach in his APL answer.
Try it online or verify all test cases.
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.
$endgroup$
05AB1E (legacy), 4 bytes
+24÷
Try it online or verify all test cases.
05AB1E, 11 5 bytes
+24/ï
-6 bytes by porting @Adam's approach in his APL answer.
Try it online or verify all test cases.
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.
edited yesterday
answered yesterday
Kevin CruijssenKevin Cruijssen
48k7 gold badges83 silver badges241 bronze badges
48k7 gold badges83 silver badges241 bronze badges
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
|
show 1 more comment
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
1
1
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
5 bytes?
$endgroup$
– Expired Data
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@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. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
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!
$endgroup$
– Expired Data
yesterday
$begingroup$
@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.$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@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.$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
$begingroup$
Ah, so it rounds towards 0. Fair enough.
$endgroup$
– Adám
yesterday
|
show 1 more comment
$begingroup$
Ohm v2, 4 bytes
+24v
Try it online!
$endgroup$
add a comment |
$begingroup$
Ohm v2, 4 bytes
+24v
Try it online!
$endgroup$
add a comment |
$begingroup$
Ohm v2, 4 bytes
+24v
Try it online!
$endgroup$
Ohm v2, 4 bytes
+24v
Try it online!
answered yesterday
CinaskiCinaski
1,3781 gold badge3 silver badges15 bronze badges
1,3781 gold badge3 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 26 bytes
a=>b=>Math.Floor((a+b)/24)
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 26 bytes
a=>b=>Math.Floor((a+b)/24)
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 26 bytes
a=>b=>Math.Floor((a+b)/24)
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 26 bytes
a=>b=>Math.Floor((a+b)/24)
Try it online!
answered yesterday
Embodiment of IgnoranceEmbodiment of Ignorance
4,5461 silver badge28 bronze badges
4,5461 silver badge28 bronze badges
add a comment |
add a comment |
$begingroup$
Haskell, 18 bytes
(flip(div)24.).(+)
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:
flip(div)24
First, div
is the shorter integer division operator, but it takes in its arguments as x//24 => div x 24
, so we need to use flip so that we can partially apply it to 24.
The double composition is a little weird to explain, so I'll follow the template of this great SO answer:
f a b = (flip(div)24) (a + b) -- what we want
f a b = (flip(div)24) ((+) a b) -- un-infixing (+)
f a b = ((flip(div)24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = (flip(div)24) . ((+) a) -- pointfree reduction
f a = ((flip(div)24) .) ((+) a) -- associative property
f a = (((flip(div)24) .) . (+)) a -- definition of function composition
f = (flip(div)24.) . (+) -- pointfree reduction
$endgroup$
$begingroup$
You can use backquotes instead offlip
:((`div`24).).(+)
.
$endgroup$
– nimi
18 hours ago
add a comment |
$begingroup$
Haskell, 18 bytes
(flip(div)24.).(+)
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:
flip(div)24
First, div
is the shorter integer division operator, but it takes in its arguments as x//24 => div x 24
, so we need to use flip so that we can partially apply it to 24.
The double composition is a little weird to explain, so I'll follow the template of this great SO answer:
f a b = (flip(div)24) (a + b) -- what we want
f a b = (flip(div)24) ((+) a b) -- un-infixing (+)
f a b = ((flip(div)24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = (flip(div)24) . ((+) a) -- pointfree reduction
f a = ((flip(div)24) .) ((+) a) -- associative property
f a = (((flip(div)24) .) . (+)) a -- definition of function composition
f = (flip(div)24.) . (+) -- pointfree reduction
$endgroup$
$begingroup$
You can use backquotes instead offlip
:((`div`24).).(+)
.
$endgroup$
– nimi
18 hours ago
add a comment |
$begingroup$
Haskell, 18 bytes
(flip(div)24.).(+)
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:
flip(div)24
First, div
is the shorter integer division operator, but it takes in its arguments as x//24 => div x 24
, so we need to use flip so that we can partially apply it to 24.
The double composition is a little weird to explain, so I'll follow the template of this great SO answer:
f a b = (flip(div)24) (a + b) -- what we want
f a b = (flip(div)24) ((+) a b) -- un-infixing (+)
f a b = ((flip(div)24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = (flip(div)24) . ((+) a) -- pointfree reduction
f a = ((flip(div)24) .) ((+) a) -- associative property
f a = (((flip(div)24) .) . (+)) a -- definition of function composition
f = (flip(div)24.) . (+) -- pointfree reduction
$endgroup$
Haskell, 18 bytes
(flip(div)24.).(+)
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:
flip(div)24
First, div
is the shorter integer division operator, but it takes in its arguments as x//24 => div x 24
, so we need to use flip so that we can partially apply it to 24.
The double composition is a little weird to explain, so I'll follow the template of this great SO answer:
f a b = (flip(div)24) (a + b) -- what we want
f a b = (flip(div)24) ((+) a b) -- un-infixing (+)
f a b = ((flip(div)24) . ((+) a)) b -- definition of function composition (partially applying (+) onto a)
f a = (flip(div)24) . ((+) a) -- pointfree reduction
f a = ((flip(div)24) .) ((+) a) -- associative property
f a = (((flip(div)24) .) . (+)) a -- definition of function composition
f = (flip(div)24.) . (+) -- pointfree reduction
edited yesterday
answered yesterday
Rin's Fourier transformRin's Fourier transform
5274 silver badges11 bronze badges
5274 silver badges11 bronze badges
$begingroup$
You can use backquotes instead offlip
:((`div`24).).(+)
.
$endgroup$
– nimi
18 hours ago
add a comment |
$begingroup$
You can use backquotes instead offlip
:((`div`24).).(+)
.
$endgroup$
– nimi
18 hours ago
$begingroup$
You can use backquotes instead of
flip
: ((`div`24).).(+)
.$endgroup$
– nimi
18 hours ago
$begingroup$
You can use backquotes instead of
flip
: ((`div`24).).(+)
.$endgroup$
– nimi
18 hours ago
add a comment |
$begingroup$
R, 28 16 bytes
Just a port of most of the other answers...
-12 bytes thanks Giuseppe
sum(scan())%/%24
Try it online!
$endgroup$
$begingroup$
Usex%/%y
instead offloor(x/y)
$endgroup$
– Giuseppe
yesterday
1
$begingroup$
Or better yet, take input from stdin and dosum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
add a comment |
$begingroup$
R, 28 16 bytes
Just a port of most of the other answers...
-12 bytes thanks Giuseppe
sum(scan())%/%24
Try it online!
$endgroup$
$begingroup$
Usex%/%y
instead offloor(x/y)
$endgroup$
– Giuseppe
yesterday
1
$begingroup$
Or better yet, take input from stdin and dosum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
add a comment |
$begingroup$
R, 28 16 bytes
Just a port of most of the other answers...
-12 bytes thanks Giuseppe
sum(scan())%/%24
Try it online!
$endgroup$
R, 28 16 bytes
Just a port of most of the other answers...
-12 bytes thanks Giuseppe
sum(scan())%/%24
Try it online!
edited yesterday
answered yesterday
Robert S.Robert S.
8485 silver badges15 bronze badges
8485 silver badges15 bronze badges
$begingroup$
Usex%/%y
instead offloor(x/y)
$endgroup$
– Giuseppe
yesterday
1
$begingroup$
Or better yet, take input from stdin and dosum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
add a comment |
$begingroup$
Usex%/%y
instead offloor(x/y)
$endgroup$
– Giuseppe
yesterday
1
$begingroup$
Or better yet, take input from stdin and dosum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
$begingroup$
Use
x%/%y
instead of floor(x/y)
$endgroup$
– Giuseppe
yesterday
$begingroup$
Use
x%/%y
instead of floor(x/y)
$endgroup$
– Giuseppe
yesterday
1
1
$begingroup$
Or better yet, take input from stdin and do
sum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Or better yet, take input from stdin and do
sum(scan())%/%24
$endgroup$
– Giuseppe
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
$begingroup$
Nice one. Will have to remember that trick.
$endgroup$
– Robert S.
yesterday
add a comment |
$begingroup$
Lua, 70 bytes
s=io.read()
c,d=s:match("([^,]+),([^,]+)")
print(math.floor((c+d)/24))
Try it online!
$endgroup$
add a comment |
$begingroup$
Lua, 70 bytes
s=io.read()
c,d=s:match("([^,]+),([^,]+)")
print(math.floor((c+d)/24))
Try it online!
$endgroup$
add a comment |
$begingroup$
Lua, 70 bytes
s=io.read()
c,d=s:match("([^,]+),([^,]+)")
print(math.floor((c+d)/24))
Try it online!
$endgroup$
Lua, 70 bytes
s=io.read()
c,d=s:match("([^,]+),([^,]+)")
print(math.floor((c+d)/24))
Try it online!
answered yesterday
ouflakouflak
3401 gold badge5 silver badges16 bronze badges
3401 gold badge5 silver badges16 bronze badges
add a comment |
add a comment |
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
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)
answered yesterday
AdámAdám
29k2 gold badges79 silver badges212 bronze badges
29k2 gold badges79 silver badges212 bronze badges
add a comment |
add a comment |
$begingroup$
Retina 0.8.2, 41 bytes
d+,?
$*
(1+)-1
-
^((-)1|124)*.*
$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|124)*.*
$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.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 41 bytes
d+,?
$*
(1+)-1
-
^((-)1|124)*.*
$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|124)*.*
$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.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 41 bytes
d+,?
$*
(1+)-1
-
^((-)1|124)*.*
$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|124)*.*
$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.
$endgroup$
Retina 0.8.2, 41 bytes
d+,?
$*
(1+)-1
-
^((-)1|124)*.*
$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|124)*.*
$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.
answered yesterday
NeilNeil
86.5k8 gold badges46 silver badges183 bronze badges
86.5k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 18 bytes
lambda*a:sum(a)/24
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 18 bytes
lambda*a:sum(a)/24
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 18 bytes
lambda*a:sum(a)/24
Try it online!
$endgroup$
Python 2, 18 bytes
lambda*a:sum(a)/24
Try it online!
answered 43 mins ago
U10-ForwardU10-Forward
2314 bronze badges
2314 bronze badges
add a comment |
add a comment |
Ivan Gerasimenko is a new contributor. Be nice, and check out our Code of Conduct.
Ivan Gerasimenko is a new contributor. Be nice, and check out our Code of Conduct.
Ivan Gerasimenko is a new contributor. Be nice, and check out our Code of Conduct.
Ivan Gerasimenko is a new contributor. Be nice, and check out our Code of Conduct.
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188809%2fget-delta-of-days-by-current-hour-and-added-delta-of-days%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Welcome to CGCC! The code-challenge tag is reserved for custom winning criteria. Did you mean code-golf?
$endgroup$
– Arnauld
yesterday
$begingroup$
@Arnauld , yeah, is it enough to specify tag?
$endgroup$
– Ivan Gerasimenko
yesterday
$begingroup$
Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
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.
$endgroup$
– Sriotchilism O'Zaic
yesterday
$begingroup$
@SriotchilismO'Zaic , nice! Thank you
$endgroup$
– Ivan Gerasimenko
yesterday