Unlock your LockCombination bike lockGolf String's format() inverseCrack the code to the combination lockFinding the DeadlockIT'S CAPS LOCK DAYCombination lock counterCombination bike lockZipper multiplicationRoom Number LocatorThe weight of a Zero
Handling Disruptive Student on the Autism Spectrum
Duplicate instruments in unison in an orchestra
What is Spectral Subtraction for noise reduction?
Was the Boeing 2707 design flawed?
Can Orcus use Multiattack with any melee weapon?
When, exactly, does the Rogue Scout get to use their Skirmisher ability?
Is the negative potential of 書く used in this sentence and what is its meaning?
What stops you from using fixed income in developing countries?
What to look for in a spotting scope?
Changing JPEG to RAW to use on Lightroom?
Why is proof-of-work required in Bitcoin?
Breaker Mapping Questions
If the Shillelagh cantrip is applied to a club with non-standard damage dice, what is the resulting damage dice?
Why is "-ber" the suffix of the last four months of the year?
To what extent are we obligated to continue to procreate beyond having two kids?
Cooking Scrambled Eggs
LINQ for generating all possible permutations
How does the OS tell whether an "Address is already in use"?
How much does Commander Data weigh?
Is it legal for source code containing undefined behavior to crash the compiler?
"There were either twelve sexes or none."
How were medieval castles built in swamps or marshes without draining them?
How many lines of code does the original TeX contain?
Can you board the plane when your passport is valid less than 3 months?
Unlock your Lock
Combination bike lockGolf String's format() inverseCrack the code to the combination lockFinding the DeadlockIT'S CAPS LOCK DAYCombination lock counterCombination bike lockZipper multiplicationRoom Number LocatorThe weight of a Zero
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9
= 8
but
1 -> 0 -> 9
= 2.
Notes
- You can rely on Default I/O rules
- You can change the order of the parameters.
Examples
Example 1, correct
Input: 999 001
Output:
999
099
009
000
001
Example 2, correct
Input: 911 232
Output:
911
011
111
211
221
231
232
Example 3, wrong output
Input: 999 121
Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...
Correct output:
999
099
199
109
119
129
120
121
Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.
This is code-golf the shortest answer wins.
code-golf path-finding
New contributor
$endgroup$
|
show 2 more comments
$begingroup$
You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9
= 8
but
1 -> 0 -> 9
= 2.
Notes
- You can rely on Default I/O rules
- You can change the order of the parameters.
Examples
Example 1, correct
Input: 999 001
Output:
999
099
009
000
001
Example 2, correct
Input: 911 232
Output:
911
011
111
211
221
231
232
Example 3, wrong output
Input: 999 121
Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...
Correct output:
999
099
199
109
119
129
120
121
Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.
This is code-golf the shortest answer wins.
code-golf path-finding
New contributor
$endgroup$
$begingroup$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
2
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
2
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago
|
show 2 more comments
$begingroup$
You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9
= 8
but
1 -> 0 -> 9
= 2.
Notes
- You can rely on Default I/O rules
- You can change the order of the parameters.
Examples
Example 1, correct
Input: 999 001
Output:
999
099
009
000
001
Example 2, correct
Input: 911 232
Output:
911
011
111
211
221
231
232
Example 3, wrong output
Input: 999 121
Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...
Correct output:
999
099
199
109
119
129
120
121
Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.
This is code-golf the shortest answer wins.
code-golf path-finding
New contributor
$endgroup$
You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9
= 8
but
1 -> 0 -> 9
= 2.
Notes
- You can rely on Default I/O rules
- You can change the order of the parameters.
Examples
Example 1, correct
Input: 999 001
Output:
999
099
009
000
001
Example 2, correct
Input: 911 232
Output:
911
011
111
211
221
231
232
Example 3, wrong output
Input: 999 121
Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...
Correct output:
999
099
199
109
119
129
120
121
Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.
This is code-golf the shortest answer wins.
code-golf path-finding
code-golf path-finding
New contributor
New contributor
edited 24 mins ago
user2190035
New contributor
asked 8 hours ago
user2190035user2190035
1614 bronze badges
1614 bronze badges
New contributor
New contributor
$begingroup$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
2
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
2
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago
|
show 2 more comments
$begingroup$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
2
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
2
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago
$begingroup$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
2
2
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
2
2
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago
|
show 2 more comments
7 Answers
7
active
oldest
votes
$begingroup$
Python 2, 113 107 bytes
a,b=input()
print a
for x,y,i in zip(a,b,(0,1,2)):
while x-y:a[i]=x=(x+1-2*((y-x)%10>(x-y)%10))%10;print a
Try it online!
Takes input as lists of integers
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 73 72 70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b)
. Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b
Try it online!
Commented
a => // a[] = initial combination
g = b => // b[] = target combination
b.some(x => // for each digit x in b[]:
d = // compute the difference d:
x - // between x
(a[++i] %= 10), // and the corresponding digit in a[]
// we apply a mod 10, because it may have exceed 9
// during the previous iteration
i = -1 // start with i = -1
) ? // end of some(); if it's truthy:
a + `n` + // append a[] followed by a line feed
g( // followed by the result of a recursive call:
b, // pass b[] unchanged
a[i] += // add either 1 or 9 to a[i]:
d / 5 < 5 / d // add 1 if d / 5 < 5 / d
|| 9 // otherwise, add 9
) // end of recursive call
: // else:
b // stop recursion and return b[]
$endgroup$
$begingroup$
d/6&1^d>0||9
->d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
add a comment |
$begingroup$
Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+%⁵
Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!
$endgroup$
add a comment |
$begingroup$
PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;
Try it online!
My solution probably sucks, but that is the best I can think of for now!
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 bytes
θ≔EθIιθF³«≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζF↔櫧≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω
Try it online! Link is to verbose version of code. Explanation:
θ
Print the initial position.
≔EθIιθ
Change the initial position string into an array of numeric digits for calculation purposes.
F³«
Loop over each digit in turn.
≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζ
Calculate the number of rotations needed to unlock that digit. This is a number from -5
to 4
where -5
means 5 downward rotations and 4
means 4 upward rotations.
F↔ζ«
Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ
Update the digit according to the sign of the rotation.
⸿⪫θω
Output the digits as a string on a new line.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ
Try it online!
Full program.
$endgroup$
add a comment |
$begingroup$
T-SQL 2012, 229 bytes
Not 100 % sql, but it is a full program, that works with the link
DECLARE @1 char(3)=##i##, @2 char(3)=##j##,@ INT=1PRINT @1
WHILE @<4IF substring(@1,@,1)=substring(@2,@,1)SET @+=1
ELSE
BEGIN
SET @1=stuff(@1,@,1,(9+substring(@1,@,1)+(9+substring(@1,@,1)-substring(@2,@,1))/5%2*2)%10)PRINT @1
END
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
);
);
user2190035 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%2f190875%2funlock-your-lock%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 113 107 bytes
a,b=input()
print a
for x,y,i in zip(a,b,(0,1,2)):
while x-y:a[i]=x=(x+1-2*((y-x)%10>(x-y)%10))%10;print a
Try it online!
Takes input as lists of integers
$endgroup$
add a comment |
$begingroup$
Python 2, 113 107 bytes
a,b=input()
print a
for x,y,i in zip(a,b,(0,1,2)):
while x-y:a[i]=x=(x+1-2*((y-x)%10>(x-y)%10))%10;print a
Try it online!
Takes input as lists of integers
$endgroup$
add a comment |
$begingroup$
Python 2, 113 107 bytes
a,b=input()
print a
for x,y,i in zip(a,b,(0,1,2)):
while x-y:a[i]=x=(x+1-2*((y-x)%10>(x-y)%10))%10;print a
Try it online!
Takes input as lists of integers
$endgroup$
Python 2, 113 107 bytes
a,b=input()
print a
for x,y,i in zip(a,b,(0,1,2)):
while x-y:a[i]=x=(x+1-2*((y-x)%10>(x-y)%10))%10;print a
Try it online!
Takes input as lists of integers
answered 8 hours ago
TFeldTFeld
18.4k3 gold badges14 silver badges57 bronze badges
18.4k3 gold badges14 silver badges57 bronze badges
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 73 72 70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b)
. Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b
Try it online!
Commented
a => // a[] = initial combination
g = b => // b[] = target combination
b.some(x => // for each digit x in b[]:
d = // compute the difference d:
x - // between x
(a[++i] %= 10), // and the corresponding digit in a[]
// we apply a mod 10, because it may have exceed 9
// during the previous iteration
i = -1 // start with i = -1
) ? // end of some(); if it's truthy:
a + `n` + // append a[] followed by a line feed
g( // followed by the result of a recursive call:
b, // pass b[] unchanged
a[i] += // add either 1 or 9 to a[i]:
d / 5 < 5 / d // add 1 if d / 5 < 5 / d
|| 9 // otherwise, add 9
) // end of recursive call
: // else:
b // stop recursion and return b[]
$endgroup$
$begingroup$
d/6&1^d>0||9
->d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b)
. Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b
Try it online!
Commented
a => // a[] = initial combination
g = b => // b[] = target combination
b.some(x => // for each digit x in b[]:
d = // compute the difference d:
x - // between x
(a[++i] %= 10), // and the corresponding digit in a[]
// we apply a mod 10, because it may have exceed 9
// during the previous iteration
i = -1 // start with i = -1
) ? // end of some(); if it's truthy:
a + `n` + // append a[] followed by a line feed
g( // followed by the result of a recursive call:
b, // pass b[] unchanged
a[i] += // add either 1 or 9 to a[i]:
d / 5 < 5 / d // add 1 if d / 5 < 5 / d
|| 9 // otherwise, add 9
) // end of recursive call
: // else:
b // stop recursion and return b[]
$endgroup$
$begingroup$
d/6&1^d>0||9
->d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b)
. Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b
Try it online!
Commented
a => // a[] = initial combination
g = b => // b[] = target combination
b.some(x => // for each digit x in b[]:
d = // compute the difference d:
x - // between x
(a[++i] %= 10), // and the corresponding digit in a[]
// we apply a mod 10, because it may have exceed 9
// during the previous iteration
i = -1 // start with i = -1
) ? // end of some(); if it's truthy:
a + `n` + // append a[] followed by a line feed
g( // followed by the result of a recursive call:
b, // pass b[] unchanged
a[i] += // add either 1 or 9 to a[i]:
d / 5 < 5 / d // add 1 if d / 5 < 5 / d
|| 9 // otherwise, add 9
) // end of recursive call
: // else:
b // stop recursion and return b[]
$endgroup$
JavaScript (ES6), 73 72 70 bytes
Saved 2 bytes thanks to @tsh
Takes input as 2 arrays of digits in curried syntax (a)(b)
. Returns a string.
a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+`
`+g(b,a[i]+=d/5<5/d||9):b
Try it online!
Commented
a => // a[] = initial combination
g = b => // b[] = target combination
b.some(x => // for each digit x in b[]:
d = // compute the difference d:
x - // between x
(a[++i] %= 10), // and the corresponding digit in a[]
// we apply a mod 10, because it may have exceed 9
// during the previous iteration
i = -1 // start with i = -1
) ? // end of some(); if it's truthy:
a + `n` + // append a[] followed by a line feed
g( // followed by the result of a recursive call:
b, // pass b[] unchanged
a[i] += // add either 1 or 9 to a[i]:
d / 5 < 5 / d // add 1 if d / 5 < 5 / d
|| 9 // otherwise, add 9
) // end of recursive call
: // else:
b // stop recursion and return b[]
edited 6 hours ago
answered 7 hours ago
ArnauldArnauld
91.2k7 gold badges106 silver badges372 bronze badges
91.2k7 gold badges106 silver badges372 bronze badges
$begingroup$
d/6&1^d>0||9
->d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
add a comment |
$begingroup$
d/6&1^d>0||9
->d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
$begingroup$
d/6&1^d>0||9
-> d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
$begingroup$
d/6&1^d>0||9
-> d/5>5/d?9:1
$endgroup$
– tsh
7 hours ago
add a comment |
$begingroup$
Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+%⁵
Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!
$endgroup$
add a comment |
$begingroup$
Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+%⁵
Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!
$endgroup$
add a comment |
$begingroup$
Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+%⁵
Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!
$endgroup$
Jelly, 30 bytes
_ż+¥⁵AÞḢṠxAƊ×€ʋ"JṬ€$$Ẏ;@W}+%⁵
Try it online!
A dyadic link taking as its left argument the unlock code and its right the current locked state, both as lists of integers.
This feels far too long!
answered 5 hours ago
Nick KennedyNick Kennedy
6,1071 gold badge9 silver badges15 bronze badges
6,1071 gold badge9 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;
Try it online!
My solution probably sucks, but that is the best I can think of for now!
$endgroup$
add a comment |
$begingroup$
PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;
Try it online!
My solution probably sucks, but that is the best I can think of for now!
$endgroup$
add a comment |
$begingroup$
PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;
Try it online!
My solution probably sucks, but that is the best I can think of for now!
$endgroup$
PHP, 114 bytes
for([,$a,$b]=$argv;$i<3;($x=$a[$i]-$b[$i])?(print$a._).$a[$i]=($y=$a[$i]+(5/$x>$x/5?-1:1))<0?9:$y%10:++$i);echo$b;
Try it online!
My solution probably sucks, but that is the best I can think of for now!
edited 5 hours ago
answered 6 hours ago
Night2Night2
2,4013 silver badges15 bronze badges
2,4013 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 48 bytes
θ≔EθIιθF³«≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζF↔櫧≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω
Try it online! Link is to verbose version of code. Explanation:
θ
Print the initial position.
≔EθIιθ
Change the initial position string into an array of numeric digits for calculation purposes.
F³«
Loop over each digit in turn.
≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζ
Calculate the number of rotations needed to unlock that digit. This is a number from -5
to 4
where -5
means 5 downward rotations and 4
means 4 upward rotations.
F↔ζ«
Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ
Update the digit according to the sign of the rotation.
⸿⪫θω
Output the digits as a string on a new line.
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 bytes
θ≔EθIιθF³«≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζF↔櫧≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω
Try it online! Link is to verbose version of code. Explanation:
θ
Print the initial position.
≔EθIιθ
Change the initial position string into an array of numeric digits for calculation purposes.
F³«
Loop over each digit in turn.
≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζ
Calculate the number of rotations needed to unlock that digit. This is a number from -5
to 4
where -5
means 5 downward rotations and 4
means 4 upward rotations.
F↔ζ«
Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ
Update the digit according to the sign of the rotation.
⸿⪫θω
Output the digits as a string on a new line.
$endgroup$
add a comment |
$begingroup$
Charcoal, 48 bytes
θ≔EθIιθF³«≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζF↔櫧≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω
Try it online! Link is to verbose version of code. Explanation:
θ
Print the initial position.
≔EθIιθ
Change the initial position string into an array of numeric digits for calculation purposes.
F³«
Loop over each digit in turn.
≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζ
Calculate the number of rotations needed to unlock that digit. This is a number from -5
to 4
where -5
means 5 downward rotations and 4
means 4 upward rotations.
F↔ζ«
Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ
Update the digit according to the sign of the rotation.
⸿⪫θω
Output the digits as a string on a new line.
$endgroup$
Charcoal, 48 bytes
θ≔EθIιθF³«≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζF↔櫧≔θι﹪⁺§θι÷ζ↔ζχ⸿⪫θω
Try it online! Link is to verbose version of code. Explanation:
θ
Print the initial position.
≔EθIιθ
Change the initial position string into an array of numeric digits for calculation purposes.
F³«
Loop over each digit in turn.
≔⁻﹪⁺⁻I§ηι§θι⁵χ⁵ζ
Calculate the number of rotations needed to unlock that digit. This is a number from -5
to 4
where -5
means 5 downward rotations and 4
means 4 upward rotations.
F↔ζ«
Loop over each rotation.
§≔θι﹪⁺§θι÷ζ↔ζχ
Update the digit according to the sign of the rotation.
⸿⪫θω
Output the digits as a string on a new line.
answered 4 hours ago
NeilNeil
88.1k8 gold badges46 silver badges186 bronze badges
88.1k8 gold badges46 silver badges186 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ
Try it online!
Full program.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ
Try it online!
Full program.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ
Try it online!
Full program.
$endgroup$
Jelly, 25 bytes
_æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ
Try it online!
Full program.
answered 2 hours ago
Erik the OutgolferErik the Outgolfer
35.9k4 gold badges30 silver badges113 bronze badges
35.9k4 gold badges30 silver badges113 bronze badges
add a comment |
add a comment |
$begingroup$
T-SQL 2012, 229 bytes
Not 100 % sql, but it is a full program, that works with the link
DECLARE @1 char(3)=##i##, @2 char(3)=##j##,@ INT=1PRINT @1
WHILE @<4IF substring(@1,@,1)=substring(@2,@,1)SET @+=1
ELSE
BEGIN
SET @1=stuff(@1,@,1,(9+substring(@1,@,1)+(9+substring(@1,@,1)-substring(@2,@,1))/5%2*2)%10)PRINT @1
END
Try it online
$endgroup$
add a comment |
$begingroup$
T-SQL 2012, 229 bytes
Not 100 % sql, but it is a full program, that works with the link
DECLARE @1 char(3)=##i##, @2 char(3)=##j##,@ INT=1PRINT @1
WHILE @<4IF substring(@1,@,1)=substring(@2,@,1)SET @+=1
ELSE
BEGIN
SET @1=stuff(@1,@,1,(9+substring(@1,@,1)+(9+substring(@1,@,1)-substring(@2,@,1))/5%2*2)%10)PRINT @1
END
Try it online
$endgroup$
add a comment |
$begingroup$
T-SQL 2012, 229 bytes
Not 100 % sql, but it is a full program, that works with the link
DECLARE @1 char(3)=##i##, @2 char(3)=##j##,@ INT=1PRINT @1
WHILE @<4IF substring(@1,@,1)=substring(@2,@,1)SET @+=1
ELSE
BEGIN
SET @1=stuff(@1,@,1,(9+substring(@1,@,1)+(9+substring(@1,@,1)-substring(@2,@,1))/5%2*2)%10)PRINT @1
END
Try it online
$endgroup$
T-SQL 2012, 229 bytes
Not 100 % sql, but it is a full program, that works with the link
DECLARE @1 char(3)=##i##, @2 char(3)=##j##,@ INT=1PRINT @1
WHILE @<4IF substring(@1,@,1)=substring(@2,@,1)SET @+=1
ELSE
BEGIN
SET @1=stuff(@1,@,1,(9+substring(@1,@,1)+(9+substring(@1,@,1)-substring(@2,@,1))/5%2*2)%10)PRINT @1
END
Try it online
answered 1 hour ago
t-clausen.dkt-clausen.dk
2,5645 silver badges14 bronze badges
2,5645 silver badges14 bronze badges
add a comment |
add a comment |
user2190035 is a new contributor. Be nice, and check out our Code of Conduct.
user2190035 is a new contributor. Be nice, and check out our Code of Conduct.
user2190035 is a new contributor. Be nice, and check out our Code of Conduct.
user2190035 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%2f190875%2funlock-your-lock%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$
May I change the order of two parameters?
$endgroup$
– tsh
8 hours ago
$begingroup$
May we update the digits in any order as long as it's optimal?
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@Arnauld No because I unlock my lock one by one :)
$endgroup$
– user2190035
7 hours ago
2
$begingroup$
Related
$endgroup$
– Luis Mendo
4 hours ago
2
$begingroup$
I'm not sure it's a good idea to put the (essentially useless) picture of a 4-digit lock from the other challenge on this 3-digit challenge. ¯_(ツ)_/¯
$endgroup$
– Arnauld
1 hour ago