Number in overlapping rangeShortest Port ScannerFinding Not-Quite-Prime NumbersA newly discovered number: bleen!Safety in numbersDo the circles intersect?Date within range?count ones in rangeThe first, the last, and everything betweenIs this Pascal's Matrix?Is it double speak?
How to measure if Scrum Master is making a difference and when to give up
Why do my bicycle brakes get worse and feel more 'squishy" over time?
How do figure out how powerful I am, when my abilities far exceed my knowledge?
Why won't the Republicans use a superdelegate system like the DNC in their nomination process?
The more + the + comparative degree
When was "Fredo" an insult to Italian-Americans?
Output the list of musical notes
Because my friend asked me to
Is this bar slide trick shown on Cheers real or a visual effect?
Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?
Bringing Power Supplies on Plane?
Word for an event that will likely never happen again
What are the advantages of this gold finger shape?
Why did IBM make the PC BIOS source code public?
What is the most difficult concept to grasp in Calculus 1?
Solving pricing problem heuristically in column generation algorithm for VRP
What should we do with manuals from the 80s?
Is there any official ruling on how characters go from 0th to 1st level in a class?
Number in overlapping range
Graphs for which a calculus student can reasonably compute the arclength
What if a restaurant suddenly cannot accept credit cards, and the customer has no cash?
Are there liquid fueled rocket boosters having coaxial fuel/oxidizer tanks?
How can I shoot a bow using Strength instead of Dexterity?
Do I need to start off my book by describing the character's "normal world"?
Number in overlapping range
Shortest Port ScannerFinding Not-Quite-Prime NumbersA newly discovered number: bleen!Safety in numbersDo the circles intersect?Date within range?count ones in rangeThe first, the last, and everything betweenIs this Pascal's Matrix?Is it double speak?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
You are given two integers between lets say 1 and 12, one
and two
and a integer between lets say 0 and 4 which is called range
.
The challange is to decide if one
is inside or equal the range from two
± range
.
The range is restarting with 1 (one
) after 12 (two
) and vise versa.
For example, if one = 2
, two = 11
and range = 3
, the result is true
, as one
is the the range [8, 9, 10, 11, 12, 1, 2]
.
The input has to be 3 seperated integers, the order doesn't matter. Input via string with seperators possible. But the Input has to consist of numbers reading as '10' and not 'A' e.g.
Test cases:
one=7 two=6 range=0 result=false
one=5 two=6 range=1 result=true
one=8 two=11 range=3 result=true
one=1 two=11 range=3 result=true
one=2 two=10 range=3 result=false
one=11 two=1 range=2 result=true
one=6 two=1 range=4 result=false
one=12 two=1 range=3 result=true
Shortest valid answer in bytes wins.
code-golf decision-problem
New contributor
$endgroup$
|
show 7 more comments
$begingroup$
You are given two integers between lets say 1 and 12, one
and two
and a integer between lets say 0 and 4 which is called range
.
The challange is to decide if one
is inside or equal the range from two
± range
.
The range is restarting with 1 (one
) after 12 (two
) and vise versa.
For example, if one = 2
, two = 11
and range = 3
, the result is true
, as one
is the the range [8, 9, 10, 11, 12, 1, 2]
.
The input has to be 3 seperated integers, the order doesn't matter. Input via string with seperators possible. But the Input has to consist of numbers reading as '10' and not 'A' e.g.
Test cases:
one=7 two=6 range=0 result=false
one=5 two=6 range=1 result=true
one=8 two=11 range=3 result=true
one=1 two=11 range=3 result=true
one=2 two=10 range=3 result=false
one=11 two=1 range=2 result=true
one=6 two=1 range=4 result=false
one=12 two=1 range=3 result=true
Shortest valid answer in bytes wins.
code-golf decision-problem
New contributor
$endgroup$
$begingroup$
Welcome to the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps overtwo
so ifone
is 2 andtwo
is 11 and therange
is 3,one
is still inside the range because it restarts attwo
withone
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
So ifone
is 2,two
is 11, andrange
is 3, is the task basically to check ifone
is in the list[8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
1
$begingroup$
one
andtwo
really should be calledA
andB
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?
$endgroup$
– Arnauld
9 hours ago
|
show 7 more comments
$begingroup$
You are given two integers between lets say 1 and 12, one
and two
and a integer between lets say 0 and 4 which is called range
.
The challange is to decide if one
is inside or equal the range from two
± range
.
The range is restarting with 1 (one
) after 12 (two
) and vise versa.
For example, if one = 2
, two = 11
and range = 3
, the result is true
, as one
is the the range [8, 9, 10, 11, 12, 1, 2]
.
The input has to be 3 seperated integers, the order doesn't matter. Input via string with seperators possible. But the Input has to consist of numbers reading as '10' and not 'A' e.g.
Test cases:
one=7 two=6 range=0 result=false
one=5 two=6 range=1 result=true
one=8 two=11 range=3 result=true
one=1 two=11 range=3 result=true
one=2 two=10 range=3 result=false
one=11 two=1 range=2 result=true
one=6 two=1 range=4 result=false
one=12 two=1 range=3 result=true
Shortest valid answer in bytes wins.
code-golf decision-problem
New contributor
$endgroup$
You are given two integers between lets say 1 and 12, one
and two
and a integer between lets say 0 and 4 which is called range
.
The challange is to decide if one
is inside or equal the range from two
± range
.
The range is restarting with 1 (one
) after 12 (two
) and vise versa.
For example, if one = 2
, two = 11
and range = 3
, the result is true
, as one
is the the range [8, 9, 10, 11, 12, 1, 2]
.
The input has to be 3 seperated integers, the order doesn't matter. Input via string with seperators possible. But the Input has to consist of numbers reading as '10' and not 'A' e.g.
Test cases:
one=7 two=6 range=0 result=false
one=5 two=6 range=1 result=true
one=8 two=11 range=3 result=true
one=1 two=11 range=3 result=true
one=2 two=10 range=3 result=false
one=11 two=1 range=2 result=true
one=6 two=1 range=4 result=false
one=12 two=1 range=3 result=true
Shortest valid answer in bytes wins.
code-golf decision-problem
code-golf decision-problem
New contributor
New contributor
edited 8 hours ago
Arnauld
90.1k7 gold badges105 silver badges366 bronze badges
90.1k7 gold badges105 silver badges366 bronze badges
New contributor
asked 10 hours ago
Tom UngerTom Unger
142 bronze badges
142 bronze badges
New contributor
New contributor
$begingroup$
Welcome to the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps overtwo
so ifone
is 2 andtwo
is 11 and therange
is 3,one
is still inside the range because it restarts attwo
withone
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
So ifone
is 2,two
is 11, andrange
is 3, is the task basically to check ifone
is in the list[8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
1
$begingroup$
one
andtwo
really should be calledA
andB
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?
$endgroup$
– Arnauld
9 hours ago
|
show 7 more comments
$begingroup$
Welcome to the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps overtwo
so ifone
is 2 andtwo
is 11 and therange
is 3,one
is still inside the range because it restarts attwo
withone
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
So ifone
is 2,two
is 11, andrange
is 3, is the task basically to check ifone
is in the list[8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
1
$begingroup$
one
andtwo
really should be calledA
andB
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?
$endgroup$
– Arnauld
9 hours ago
$begingroup$
Welcome to the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
Welcome to the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps over
two
so if one
is 2 and two
is 11 and the range
is 3, one
is still inside the range because it restarts at two
with one
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps over
two
so if one
is 2 and two
is 11 and the range
is 3, one
is still inside the range because it restarts at two
with one
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
So if
one
is 2, two
is 11, and range
is 3, is the task basically to check if one
is in the list [8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
So if
one
is 2, two
is 11, and range
is 3, is the task basically to check if one
is in the list [8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
1
1
$begingroup$
one
and two
really should be called A
and B
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?$endgroup$
– Arnauld
9 hours ago
$begingroup$
one
and two
really should be called A
and B
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?$endgroup$
– Arnauld
9 hours ago
|
show 7 more comments
16 Answers
16
active
oldest
votes
$begingroup$
JavaScript (ES6), 38 bytes
(a,b,r)=>((a=a<b?b-a:a-b)>6?12-a:a)<=r
Try it online!
JavaScript (Node.js), 53 bytes
Silly branchless method. Expects BigInts. Returns $0textn$ or $1textn$.
(a,b,r)=>0x4C5C038B885n>>((a-=b)*a+347n*r)%282n%46n&1n
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 52 bytes
lambda a,b,c:a in[i%12or 12for i in range(b-c,b-~c)]
Try it online!
Python 2, 52 bytes
lambda a,b,c:any(set(range(b-c,b-~c))&a,a-12,a+12)
Try it online!
Python 3, 50 bytes
lambda a,b,c:any(*range(b-c,b-~c)&a,a-12,a+12)
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 10 8 10 bytes
ŒR’+%12‘Ɠe
Try it online!
Saved 2 bytes thanks to Mr. Xcoder
+2 bytes due a bug if one = 12
I believe this meets the criteria. Takes one
from STDIN, range
as left argument and two
as right argument
$endgroup$
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takesone
from STDIN,range
as the first argument andtwo
as the second argument. Try it online!
$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails ifone
is12
(i.e.one=12; two=1; range=3
should result in truthy).
$endgroup$
– Kevin Cruijssen
8 hours ago
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Java 10, 70 38 bytes
(o,t,r)->((o=o<t?t-o:o-t)>6?12-o:o)<=r
-32 bytes by porting @Arnauld's JavaScript answer.
Try it online.
Explanation:
(o,t,r)-> // Method with three integer parameters and boolean return-type
((o=o<t?t-o:o-t) // Replace `o` with abs(t-o)
>6? // And if it's smaller than 6:
12-o // Use 12-o
: // Else (it's larger than or equal to 6):
o // Use o itself
)<=r // And check if that is smaller than or equal to r
$endgroup$
add a comment |
$begingroup$
05AB1E, 11 8 bytes
αD12α‚ß@
-3 bytes by porting @Arnauld's JavaScript answer, so make sure to upvote him!
Inputs in the same order as the challenge description: one
; two
; range
.
Try it online or verify all test cases.
Explanation:
$temp=lvert two-onervert$
$result=rangegeq min(temp,lvert12-temprvert)$
α # Take the absolute difference between the first two (implicit) inputs one & two
D # Duplicate it
12α # And take the absolute difference with 12
‚ß # Pair, pop, and push the minimum of the two values on the stack
@ # And check if the (implicit) input range is larger than or equal to this value
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 24 bytes
Abs@Mod[#-#2,12,-6]<=#3&
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 63 bytes
sub fgrep$_[0]==$_%12,(1..36)[11+$_[1]-$_[2]..11+$_[1]+$_[2]]
Try it online!
Ungolfed:
sub f
my($one, $two, $range) = @_;
my @n = (1..36);
return 0 + grep $one==$_%12, @n[ 11+$two-$range ..
11+$two+$range ];
$endgroup$
add a comment |
$begingroup$
Haskell, 42 bytes
t#r=(`elem`[1+(n-1)`mod`12|n<-[t-r..t+r]])
two # range
returns a function which when applied to one
returns a Bool
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 11 bytes
aV
aC mU §W
Try it
$endgroup$
add a comment |
$begingroup$
Ruby, 45 characters
->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o
Nothing fancy, just a chance to use Array#rotate
.
Sample run:
irb(main):001:0> ->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o[2, 11, 3]
=> true
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 31 bytes
lambda o,t,r:5-r<(o-t+6)%12<7+r
Try it online!
Python 2, 33 bytes
lambda o,t,r:abs((o-t+6)%12-6)<=r
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 27 bytes
o%t=(abs(mod(o-t+6)12-6)<=)
Try it online!
$endgroup$
add a comment |
$begingroup$
Charcoal, 11 bytes
‹⁵⁺N↔⁻⁶↔⁻NN
Try it online! Link is to verbose version of code. Takes the size of the range as the first input. Output uses Charcoal's default Boolean format of -
for true, nothing for false. Explanation:
NN Two inputs
↔⁻ Absolute difference
⁶ Literal 6
↔⁻ Absolute difference
⁺N Plus range
‹⁵ Is greater than 5
$endgroup$
add a comment |
$begingroup$
R, 48 bytes
function(a,b,r)a%in%c(9:12,1:12,1:4)[-r:r+b+4]
Try it online!
Pretty straightforward, I struggled for a while to find the best way to test if a was in the given range. There is likely a method I haven't seen or tried yet.
$endgroup$
add a comment |
$begingroup$
Julia 1.0, 35 bytes
f(o,t,r)=o in@.mod(t-1+(-r:r),12)+1
Try it online!
$endgroup$
add a comment |
$begingroup$
Stax, 7 bytes
₧╝g╙╖²╞
Run and debug it
It takes input as space separated [range] [one] [two]
and outputs 0
for false, 1
for true.
In pseudo-code:
d = abs(one - two)
return min(d, 12 - d) <= range
Hm, that's probably almost a python submission.
$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
);
);
Tom Unger 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%2f190056%2fnumber-in-overlapping-range%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
16 Answers
16
active
oldest
votes
16 Answers
16
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (ES6), 38 bytes
(a,b,r)=>((a=a<b?b-a:a-b)>6?12-a:a)<=r
Try it online!
JavaScript (Node.js), 53 bytes
Silly branchless method. Expects BigInts. Returns $0textn$ or $1textn$.
(a,b,r)=>0x4C5C038B885n>>((a-=b)*a+347n*r)%282n%46n&1n
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 38 bytes
(a,b,r)=>((a=a<b?b-a:a-b)>6?12-a:a)<=r
Try it online!
JavaScript (Node.js), 53 bytes
Silly branchless method. Expects BigInts. Returns $0textn$ or $1textn$.
(a,b,r)=>0x4C5C038B885n>>((a-=b)*a+347n*r)%282n%46n&1n
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 38 bytes
(a,b,r)=>((a=a<b?b-a:a-b)>6?12-a:a)<=r
Try it online!
JavaScript (Node.js), 53 bytes
Silly branchless method. Expects BigInts. Returns $0textn$ or $1textn$.
(a,b,r)=>0x4C5C038B885n>>((a-=b)*a+347n*r)%282n%46n&1n
Try it online!
$endgroup$
JavaScript (ES6), 38 bytes
(a,b,r)=>((a=a<b?b-a:a-b)>6?12-a:a)<=r
Try it online!
JavaScript (Node.js), 53 bytes
Silly branchless method. Expects BigInts. Returns $0textn$ or $1textn$.
(a,b,r)=>0x4C5C038B885n>>((a-=b)*a+347n*r)%282n%46n&1n
Try it online!
edited 7 hours ago
answered 8 hours ago
ArnauldArnauld
90.1k7 gold badges105 silver badges366 bronze badges
90.1k7 gold badges105 silver badges366 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 52 bytes
lambda a,b,c:a in[i%12or 12for i in range(b-c,b-~c)]
Try it online!
Python 2, 52 bytes
lambda a,b,c:any(set(range(b-c,b-~c))&a,a-12,a+12)
Try it online!
Python 3, 50 bytes
lambda a,b,c:any(*range(b-c,b-~c)&a,a-12,a+12)
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 52 bytes
lambda a,b,c:a in[i%12or 12for i in range(b-c,b-~c)]
Try it online!
Python 2, 52 bytes
lambda a,b,c:any(set(range(b-c,b-~c))&a,a-12,a+12)
Try it online!
Python 3, 50 bytes
lambda a,b,c:any(*range(b-c,b-~c)&a,a-12,a+12)
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 52 bytes
lambda a,b,c:a in[i%12or 12for i in range(b-c,b-~c)]
Try it online!
Python 2, 52 bytes
lambda a,b,c:any(set(range(b-c,b-~c))&a,a-12,a+12)
Try it online!
Python 3, 50 bytes
lambda a,b,c:any(*range(b-c,b-~c)&a,a-12,a+12)
Try it online!
$endgroup$
Python 2, 52 bytes
lambda a,b,c:a in[i%12or 12for i in range(b-c,b-~c)]
Try it online!
Python 2, 52 bytes
lambda a,b,c:any(set(range(b-c,b-~c))&a,a-12,a+12)
Try it online!
Python 3, 50 bytes
lambda a,b,c:any(*range(b-c,b-~c)&a,a-12,a+12)
Try it online!
edited 9 hours ago
answered 9 hours ago
TFeldTFeld
18.3k3 gold badges14 silver badges57 bronze badges
18.3k3 gold badges14 silver badges57 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 10 8 10 bytes
ŒR’+%12‘Ɠe
Try it online!
Saved 2 bytes thanks to Mr. Xcoder
+2 bytes due a bug if one = 12
I believe this meets the criteria. Takes one
from STDIN, range
as left argument and two
as right argument
$endgroup$
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takesone
from STDIN,range
as the first argument andtwo
as the second argument. Try it online!
$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails ifone
is12
(i.e.one=12; two=1; range=3
should result in truthy).
$endgroup$
– Kevin Cruijssen
8 hours ago
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Jelly, 10 8 10 bytes
ŒR’+%12‘Ɠe
Try it online!
Saved 2 bytes thanks to Mr. Xcoder
+2 bytes due a bug if one = 12
I believe this meets the criteria. Takes one
from STDIN, range
as left argument and two
as right argument
$endgroup$
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takesone
from STDIN,range
as the first argument andtwo
as the second argument. Try it online!
$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails ifone
is12
(i.e.one=12; two=1; range=3
should result in truthy).
$endgroup$
– Kevin Cruijssen
8 hours ago
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Jelly, 10 8 10 bytes
ŒR’+%12‘Ɠe
Try it online!
Saved 2 bytes thanks to Mr. Xcoder
+2 bytes due a bug if one = 12
I believe this meets the criteria. Takes one
from STDIN, range
as left argument and two
as right argument
$endgroup$
Jelly, 10 8 10 bytes
ŒR’+%12‘Ɠe
Try it online!
Saved 2 bytes thanks to Mr. Xcoder
+2 bytes due a bug if one = 12
I believe this meets the criteria. Takes one
from STDIN, range
as left argument and two
as right argument
edited 8 hours ago
answered 10 hours ago
caird coinheringaahingcaird coinheringaahing
7,6763 gold badges31 silver badges86 bronze badges
7,6763 gold badges31 silver badges86 bronze badges
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takesone
from STDIN,range
as the first argument andtwo
as the second argument. Try it online!
$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails ifone
is12
(i.e.one=12; two=1; range=3
should result in truthy).
$endgroup$
– Kevin Cruijssen
8 hours ago
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takesone
from STDIN,range
as the first argument andtwo
as the second argument. Try it online!
$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails ifone
is12
(i.e.one=12; two=1; range=3
should result in truthy).
$endgroup$
– Kevin Cruijssen
8 hours ago
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takes one
from STDIN, range
as the first argument and two
as the second argument. Try it online!$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
ŒR+%12Ɠe
(ŒR
is (inclusive) range from $-|z|$ to $|z|$) saves 2 bytes. Takes one
from STDIN, range
as the first argument and two
as the second argument. Try it online!$endgroup$
– Mr. Xcoder
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
@Mr.Xcoder So it does! Thanks
$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails if
one
is 12
(i.e. one=12; two=1; range=3
should result in truthy).$endgroup$
– Kevin Cruijssen
8 hours ago
$begingroup$
Your solution has the same problem as my 05AB1E answer had: it fails if
one
is 12
(i.e. one=12; two=1; range=3
should result in truthy).$endgroup$
– Kevin Cruijssen
8 hours ago
1
1
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
$begingroup$
@KevinCruijssen I believe that is fixed, but I'm on mobile so haven't fully tested it
$endgroup$
– caird coinheringaahing
8 hours ago
add a comment |
$begingroup$
Java 10, 70 38 bytes
(o,t,r)->((o=o<t?t-o:o-t)>6?12-o:o)<=r
-32 bytes by porting @Arnauld's JavaScript answer.
Try it online.
Explanation:
(o,t,r)-> // Method with three integer parameters and boolean return-type
((o=o<t?t-o:o-t) // Replace `o` with abs(t-o)
>6? // And if it's smaller than 6:
12-o // Use 12-o
: // Else (it's larger than or equal to 6):
o // Use o itself
)<=r // And check if that is smaller than or equal to r
$endgroup$
add a comment |
$begingroup$
Java 10, 70 38 bytes
(o,t,r)->((o=o<t?t-o:o-t)>6?12-o:o)<=r
-32 bytes by porting @Arnauld's JavaScript answer.
Try it online.
Explanation:
(o,t,r)-> // Method with three integer parameters and boolean return-type
((o=o<t?t-o:o-t) // Replace `o` with abs(t-o)
>6? // And if it's smaller than 6:
12-o // Use 12-o
: // Else (it's larger than or equal to 6):
o // Use o itself
)<=r // And check if that is smaller than or equal to r
$endgroup$
add a comment |
$begingroup$
Java 10, 70 38 bytes
(o,t,r)->((o=o<t?t-o:o-t)>6?12-o:o)<=r
-32 bytes by porting @Arnauld's JavaScript answer.
Try it online.
Explanation:
(o,t,r)-> // Method with three integer parameters and boolean return-type
((o=o<t?t-o:o-t) // Replace `o` with abs(t-o)
>6? // And if it's smaller than 6:
12-o // Use 12-o
: // Else (it's larger than or equal to 6):
o // Use o itself
)<=r // And check if that is smaller than or equal to r
$endgroup$
Java 10, 70 38 bytes
(o,t,r)->((o=o<t?t-o:o-t)>6?12-o:o)<=r
-32 bytes by porting @Arnauld's JavaScript answer.
Try it online.
Explanation:
(o,t,r)-> // Method with three integer parameters and boolean return-type
((o=o<t?t-o:o-t) // Replace `o` with abs(t-o)
>6? // And if it's smaller than 6:
12-o // Use 12-o
: // Else (it's larger than or equal to 6):
o // Use o itself
)<=r // And check if that is smaller than or equal to r
edited 8 hours ago
answered 8 hours ago
Kevin CruijssenKevin Cruijssen
49.8k7 gold badges83 silver badges246 bronze badges
49.8k7 gold badges83 silver badges246 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E, 11 8 bytes
αD12α‚ß@
-3 bytes by porting @Arnauld's JavaScript answer, so make sure to upvote him!
Inputs in the same order as the challenge description: one
; two
; range
.
Try it online or verify all test cases.
Explanation:
$temp=lvert two-onervert$
$result=rangegeq min(temp,lvert12-temprvert)$
α # Take the absolute difference between the first two (implicit) inputs one & two
D # Duplicate it
12α # And take the absolute difference with 12
‚ß # Pair, pop, and push the minimum of the two values on the stack
@ # And check if the (implicit) input range is larger than or equal to this value
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 11 8 bytes
αD12α‚ß@
-3 bytes by porting @Arnauld's JavaScript answer, so make sure to upvote him!
Inputs in the same order as the challenge description: one
; two
; range
.
Try it online or verify all test cases.
Explanation:
$temp=lvert two-onervert$
$result=rangegeq min(temp,lvert12-temprvert)$
α # Take the absolute difference between the first two (implicit) inputs one & two
D # Duplicate it
12α # And take the absolute difference with 12
‚ß # Pair, pop, and push the minimum of the two values on the stack
@ # And check if the (implicit) input range is larger than or equal to this value
# (after which the result is output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 11 8 bytes
αD12α‚ß@
-3 bytes by porting @Arnauld's JavaScript answer, so make sure to upvote him!
Inputs in the same order as the challenge description: one
; two
; range
.
Try it online or verify all test cases.
Explanation:
$temp=lvert two-onervert$
$result=rangegeq min(temp,lvert12-temprvert)$
α # Take the absolute difference between the first two (implicit) inputs one & two
D # Duplicate it
12α # And take the absolute difference with 12
‚ß # Pair, pop, and push the minimum of the two values on the stack
@ # And check if the (implicit) input range is larger than or equal to this value
# (after which the result is output implicitly)
$endgroup$
05AB1E, 11 8 bytes
αD12α‚ß@
-3 bytes by porting @Arnauld's JavaScript answer, so make sure to upvote him!
Inputs in the same order as the challenge description: one
; two
; range
.
Try it online or verify all test cases.
Explanation:
$temp=lvert two-onervert$
$result=rangegeq min(temp,lvert12-temprvert)$
α # Take the absolute difference between the first two (implicit) inputs one & two
D # Duplicate it
12α # And take the absolute difference with 12
‚ß # Pair, pop, and push the minimum of the two values on the stack
@ # And check if the (implicit) input range is larger than or equal to this value
# (after which the result is output implicitly)
edited 8 hours ago
answered 9 hours ago
Kevin CruijssenKevin Cruijssen
49.8k7 gold badges83 silver badges246 bronze badges
49.8k7 gold badges83 silver badges246 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 24 bytes
Abs@Mod[#-#2,12,-6]<=#3&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 24 bytes
Abs@Mod[#-#2,12,-6]<=#3&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 24 bytes
Abs@Mod[#-#2,12,-6]<=#3&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 24 bytes
Abs@Mod[#-#2,12,-6]<=#3&
Try it online!
answered 8 hours ago
RomanRoman
6251 silver badge6 bronze badges
6251 silver badge6 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5, 63 bytes
sub fgrep$_[0]==$_%12,(1..36)[11+$_[1]-$_[2]..11+$_[1]+$_[2]]
Try it online!
Ungolfed:
sub f
my($one, $two, $range) = @_;
my @n = (1..36);
return 0 + grep $one==$_%12, @n[ 11+$two-$range ..
11+$two+$range ];
$endgroup$
add a comment |
$begingroup$
Perl 5, 63 bytes
sub fgrep$_[0]==$_%12,(1..36)[11+$_[1]-$_[2]..11+$_[1]+$_[2]]
Try it online!
Ungolfed:
sub f
my($one, $two, $range) = @_;
my @n = (1..36);
return 0 + grep $one==$_%12, @n[ 11+$two-$range ..
11+$two+$range ];
$endgroup$
add a comment |
$begingroup$
Perl 5, 63 bytes
sub fgrep$_[0]==$_%12,(1..36)[11+$_[1]-$_[2]..11+$_[1]+$_[2]]
Try it online!
Ungolfed:
sub f
my($one, $two, $range) = @_;
my @n = (1..36);
return 0 + grep $one==$_%12, @n[ 11+$two-$range ..
11+$two+$range ];
$endgroup$
Perl 5, 63 bytes
sub fgrep$_[0]==$_%12,(1..36)[11+$_[1]-$_[2]..11+$_[1]+$_[2]]
Try it online!
Ungolfed:
sub f
my($one, $two, $range) = @_;
my @n = (1..36);
return 0 + grep $one==$_%12, @n[ 11+$two-$range ..
11+$two+$range ];
edited 8 hours ago
answered 8 hours ago
Kjetil S.Kjetil S.
7072 silver badges5 bronze badges
7072 silver badges5 bronze badges
add a comment |
add a comment |
$begingroup$
Haskell, 42 bytes
t#r=(`elem`[1+(n-1)`mod`12|n<-[t-r..t+r]])
two # range
returns a function which when applied to one
returns a Bool
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 42 bytes
t#r=(`elem`[1+(n-1)`mod`12|n<-[t-r..t+r]])
two # range
returns a function which when applied to one
returns a Bool
.
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 42 bytes
t#r=(`elem`[1+(n-1)`mod`12|n<-[t-r..t+r]])
two # range
returns a function which when applied to one
returns a Bool
.
Try it online!
$endgroup$
Haskell, 42 bytes
t#r=(`elem`[1+(n-1)`mod`12|n<-[t-r..t+r]])
two # range
returns a function which when applied to one
returns a Bool
.
Try it online!
answered 8 hours ago
Leo TenenbaumLeo Tenenbaum
1,5782 gold badges7 silver badges16 bronze badges
1,5782 gold badges7 silver badges16 bronze badges
add a comment |
add a comment |
$begingroup$
Japt, 11 bytes
aV
aC mU §W
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 11 bytes
aV
aC mU §W
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 11 bytes
aV
aC mU §W
Try it
$endgroup$
Japt, 11 bytes
aV
aC mU §W
Try it
edited 8 hours ago
answered 8 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
4,9861 silver badge30 bronze badges
4,9861 silver badge30 bronze badges
add a comment |
add a comment |
$begingroup$
Ruby, 45 characters
->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o
Nothing fancy, just a chance to use Array#rotate
.
Sample run:
irb(main):001:0> ->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o[2, 11, 3]
=> true
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 45 characters
->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o
Nothing fancy, just a chance to use Array#rotate
.
Sample run:
irb(main):001:0> ->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o[2, 11, 3]
=> true
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 45 characters
->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o
Nothing fancy, just a chance to use Array#rotate
.
Sample run:
irb(main):001:0> ->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o[2, 11, 3]
=> true
Try it online!
$endgroup$
Ruby, 45 characters
->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o
Nothing fancy, just a chance to use Array#rotate
.
Sample run:
irb(main):001:0> ->o,t,r[*1..12].rotate(t-r-1)[0..r*2].any?o[2, 11, 3]
=> true
Try it online!
answered 7 hours ago
manatworkmanatwork
16.7k4 gold badges38 silver badges72 bronze badges
16.7k4 gold badges38 silver badges72 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 31 bytes
lambda o,t,r:5-r<(o-t+6)%12<7+r
Try it online!
Python 2, 33 bytes
lambda o,t,r:abs((o-t+6)%12-6)<=r
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 31 bytes
lambda o,t,r:5-r<(o-t+6)%12<7+r
Try it online!
Python 2, 33 bytes
lambda o,t,r:abs((o-t+6)%12-6)<=r
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 31 bytes
lambda o,t,r:5-r<(o-t+6)%12<7+r
Try it online!
Python 2, 33 bytes
lambda o,t,r:abs((o-t+6)%12-6)<=r
Try it online!
$endgroup$
Python 2, 31 bytes
lambda o,t,r:5-r<(o-t+6)%12<7+r
Try it online!
Python 2, 33 bytes
lambda o,t,r:abs((o-t+6)%12-6)<=r
Try it online!
edited 7 hours ago
answered 7 hours ago
xnorxnor
97.8k19 gold badges201 silver badges461 bronze badges
97.8k19 gold badges201 silver badges461 bronze badges
add a comment |
add a comment |
$begingroup$
Haskell, 27 bytes
o%t=(abs(mod(o-t+6)12-6)<=)
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 27 bytes
o%t=(abs(mod(o-t+6)12-6)<=)
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 27 bytes
o%t=(abs(mod(o-t+6)12-6)<=)
Try it online!
$endgroup$
Haskell, 27 bytes
o%t=(abs(mod(o-t+6)12-6)<=)
Try it online!
answered 7 hours ago
xnorxnor
97.8k19 gold badges201 silver badges461 bronze badges
97.8k19 gold badges201 silver badges461 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 11 bytes
‹⁵⁺N↔⁻⁶↔⁻NN
Try it online! Link is to verbose version of code. Takes the size of the range as the first input. Output uses Charcoal's default Boolean format of -
for true, nothing for false. Explanation:
NN Two inputs
↔⁻ Absolute difference
⁶ Literal 6
↔⁻ Absolute difference
⁺N Plus range
‹⁵ Is greater than 5
$endgroup$
add a comment |
$begingroup$
Charcoal, 11 bytes
‹⁵⁺N↔⁻⁶↔⁻NN
Try it online! Link is to verbose version of code. Takes the size of the range as the first input. Output uses Charcoal's default Boolean format of -
for true, nothing for false. Explanation:
NN Two inputs
↔⁻ Absolute difference
⁶ Literal 6
↔⁻ Absolute difference
⁺N Plus range
‹⁵ Is greater than 5
$endgroup$
add a comment |
$begingroup$
Charcoal, 11 bytes
‹⁵⁺N↔⁻⁶↔⁻NN
Try it online! Link is to verbose version of code. Takes the size of the range as the first input. Output uses Charcoal's default Boolean format of -
for true, nothing for false. Explanation:
NN Two inputs
↔⁻ Absolute difference
⁶ Literal 6
↔⁻ Absolute difference
⁺N Plus range
‹⁵ Is greater than 5
$endgroup$
Charcoal, 11 bytes
‹⁵⁺N↔⁻⁶↔⁻NN
Try it online! Link is to verbose version of code. Takes the size of the range as the first input. Output uses Charcoal's default Boolean format of -
for true, nothing for false. Explanation:
NN Two inputs
↔⁻ Absolute difference
⁶ Literal 6
↔⁻ Absolute difference
⁺N Plus range
‹⁵ Is greater than 5
answered 3 hours ago
NeilNeil
87.3k8 gold badges46 silver badges183 bronze badges
87.3k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
R, 48 bytes
function(a,b,r)a%in%c(9:12,1:12,1:4)[-r:r+b+4]
Try it online!
Pretty straightforward, I struggled for a while to find the best way to test if a was in the given range. There is likely a method I haven't seen or tried yet.
$endgroup$
add a comment |
$begingroup$
R, 48 bytes
function(a,b,r)a%in%c(9:12,1:12,1:4)[-r:r+b+4]
Try it online!
Pretty straightforward, I struggled for a while to find the best way to test if a was in the given range. There is likely a method I haven't seen or tried yet.
$endgroup$
add a comment |
$begingroup$
R, 48 bytes
function(a,b,r)a%in%c(9:12,1:12,1:4)[-r:r+b+4]
Try it online!
Pretty straightforward, I struggled for a while to find the best way to test if a was in the given range. There is likely a method I haven't seen or tried yet.
$endgroup$
R, 48 bytes
function(a,b,r)a%in%c(9:12,1:12,1:4)[-r:r+b+4]
Try it online!
Pretty straightforward, I struggled for a while to find the best way to test if a was in the given range. There is likely a method I haven't seen or tried yet.
answered 3 hours ago
Sumner18Sumner18
7202 silver badges8 bronze badges
7202 silver badges8 bronze badges
add a comment |
add a comment |
$begingroup$
Julia 1.0, 35 bytes
f(o,t,r)=o in@.mod(t-1+(-r:r),12)+1
Try it online!
$endgroup$
add a comment |
$begingroup$
Julia 1.0, 35 bytes
f(o,t,r)=o in@.mod(t-1+(-r:r),12)+1
Try it online!
$endgroup$
add a comment |
$begingroup$
Julia 1.0, 35 bytes
f(o,t,r)=o in@.mod(t-1+(-r:r),12)+1
Try it online!
$endgroup$
Julia 1.0, 35 bytes
f(o,t,r)=o in@.mod(t-1+(-r:r),12)+1
Try it online!
answered 2 hours ago
user3263164user3263164
1313 bronze badges
1313 bronze badges
add a comment |
add a comment |
$begingroup$
Stax, 7 bytes
₧╝g╙╖²╞
Run and debug it
It takes input as space separated [range] [one] [two]
and outputs 0
for false, 1
for true.
In pseudo-code:
d = abs(one - two)
return min(d, 12 - d) <= range
Hm, that's probably almost a python submission.
$endgroup$
add a comment |
$begingroup$
Stax, 7 bytes
₧╝g╙╖²╞
Run and debug it
It takes input as space separated [range] [one] [two]
and outputs 0
for false, 1
for true.
In pseudo-code:
d = abs(one - two)
return min(d, 12 - d) <= range
Hm, that's probably almost a python submission.
$endgroup$
add a comment |
$begingroup$
Stax, 7 bytes
₧╝g╙╖²╞
Run and debug it
It takes input as space separated [range] [one] [two]
and outputs 0
for false, 1
for true.
In pseudo-code:
d = abs(one - two)
return min(d, 12 - d) <= range
Hm, that's probably almost a python submission.
$endgroup$
Stax, 7 bytes
₧╝g╙╖²╞
Run and debug it
It takes input as space separated [range] [one] [two]
and outputs 0
for false, 1
for true.
In pseudo-code:
d = abs(one - two)
return min(d, 12 - d) <= range
Hm, that's probably almost a python submission.
answered 1 hour ago
recursiverecursive
7,85115 silver badges31 bronze badges
7,85115 silver badges31 bronze badges
add a comment |
add a comment |
Tom Unger is a new contributor. Be nice, and check out our Code of Conduct.
Tom Unger is a new contributor. Be nice, and check out our Code of Conduct.
Tom Unger is a new contributor. Be nice, and check out our Code of Conduct.
Tom Unger 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%2f190056%2fnumber-in-overlapping-range%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 the site! While this challenge is understandable, there are still a few issues. For example, why between 1 and 12, and 0 and 4 particularly? Also, please keep in mind that homework questions are not on-topic here, so if this is homework (or similar), I'd recommend loosening the requirements of the challenge (allowing the integers/range to be any number, etc.). Finally, what do you mean by "Restarting with 1 after 12 and vise versa."?
$endgroup$
– caird coinheringaahing
10 hours ago
$begingroup$
@cairdcoinheringaahing Hey thank you, I picked those numbers randomly, but two has to be bigger than one. How big the range is does not really matter. With restarting I mean that your range overlaps over
two
so ifone
is 2 andtwo
is 11 and therange
is 3,one
is still inside the range because it restarts attwo
withone
$endgroup$
– Tom Unger
10 hours ago
$begingroup$
So if
one
is 2,two
is 11, andrange
is 3, is the task basically to check ifone
is in the list[8, 9, 10, 11, 12, 1, 2]
? That the range cycles round if it goes out of bounds?$endgroup$
– caird coinheringaahing
9 hours ago
$begingroup$
Exactly, sorry If my description was irritating
$endgroup$
– Tom Unger
9 hours ago
1
$begingroup$
one
andtwo
really should be calledA
andB
for the sake of clarity. Also, it's still unclear IMO what is given as input and what is a constant. Are $1$ and $12$ the input values, or are the input values guaranteed to be in $[1..12]$?$endgroup$
– Arnauld
9 hours ago