How frustrating is my movie?
$begingroup$
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requires navigating a keyboard that looks like this:
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 1 2 3 4
5 6 7 8 9 0
Your task is to take as input a movie title and calculate how "frustrating" it is to type that movie title. The frustration number of a particular string is the number of letters that require moving right from the letter before them. We don't care how far right they are, since if we start moving right we pretty much instantly go to the end of the line, and we don't care about up, down or leftwards movement because they are easy.
For example if we wanted to type in
keyboard
- We start at
k
for free.
e
is just abovek
so we don't need to move right.
y
is all the way left so no need to move right.
b
however is on the next column rightwards so we need to move right to get to it.
o
is on the next column over so we have to move rightwards to get to it.
a
is back in the first column so we move left to get to it.
r
is all the way on the right so we move right to it.
d
is two columns to the left ofr
's column.
The characters that need to move to the right are bor
meaning that this is frustration 3.
Additional rules
This is a code-golf challenge so your answers will be scored in bytes with fewer bytes being better. The input will always consist of alphanumeric characters, you can support either capital or lowercase letters and you only need to support one. The input will never be empty.
Testcases
keyboard -> 3
2001aspaceodyssey -> 6
sorrytobotheryou -> 8
thinblueline -> 5
blast2 -> 3
code-golf string
$endgroup$
|
show 1 more comment
$begingroup$
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requires navigating a keyboard that looks like this:
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 1 2 3 4
5 6 7 8 9 0
Your task is to take as input a movie title and calculate how "frustrating" it is to type that movie title. The frustration number of a particular string is the number of letters that require moving right from the letter before them. We don't care how far right they are, since if we start moving right we pretty much instantly go to the end of the line, and we don't care about up, down or leftwards movement because they are easy.
For example if we wanted to type in
keyboard
- We start at
k
for free.
e
is just abovek
so we don't need to move right.
y
is all the way left so no need to move right.
b
however is on the next column rightwards so we need to move right to get to it.
o
is on the next column over so we have to move rightwards to get to it.
a
is back in the first column so we move left to get to it.
r
is all the way on the right so we move right to it.
d
is two columns to the left ofr
's column.
The characters that need to move to the right are bor
meaning that this is frustration 3.
Additional rules
This is a code-golf challenge so your answers will be scored in bytes with fewer bytes being better. The input will always consist of alphanumeric characters, you can support either capital or lowercase letters and you only need to support one. The input will never be empty.
Testcases
keyboard -> 3
2001aspaceodyssey -> 6
sorrytobotheryou -> 8
thinblueline -> 5
blast2 -> 3
code-golf string
$endgroup$
2
$begingroup$
Suggested test case:"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)
$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
1
$begingroup$
Suggested test case:90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17
|
show 1 more comment
$begingroup$
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requires navigating a keyboard that looks like this:
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 1 2 3 4
5 6 7 8 9 0
Your task is to take as input a movie title and calculate how "frustrating" it is to type that movie title. The frustration number of a particular string is the number of letters that require moving right from the letter before them. We don't care how far right they are, since if we start moving right we pretty much instantly go to the end of the line, and we don't care about up, down or leftwards movement because they are easy.
For example if we wanted to type in
keyboard
- We start at
k
for free.
e
is just abovek
so we don't need to move right.
y
is all the way left so no need to move right.
b
however is on the next column rightwards so we need to move right to get to it.
o
is on the next column over so we have to move rightwards to get to it.
a
is back in the first column so we move left to get to it.
r
is all the way on the right so we move right to it.
d
is two columns to the left ofr
's column.
The characters that need to move to the right are bor
meaning that this is frustration 3.
Additional rules
This is a code-golf challenge so your answers will be scored in bytes with fewer bytes being better. The input will always consist of alphanumeric characters, you can support either capital or lowercase letters and you only need to support one. The input will never be empty.
Testcases
keyboard -> 3
2001aspaceodyssey -> 6
sorrytobotheryou -> 8
thinblueline -> 5
blast2 -> 3
code-golf string
$endgroup$
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requires navigating a keyboard that looks like this:
a b c d e f
g h i j k l
m n o p q r
s t u v w x
y z 1 2 3 4
5 6 7 8 9 0
Your task is to take as input a movie title and calculate how "frustrating" it is to type that movie title. The frustration number of a particular string is the number of letters that require moving right from the letter before them. We don't care how far right they are, since if we start moving right we pretty much instantly go to the end of the line, and we don't care about up, down or leftwards movement because they are easy.
For example if we wanted to type in
keyboard
- We start at
k
for free.
e
is just abovek
so we don't need to move right.
y
is all the way left so no need to move right.
b
however is on the next column rightwards so we need to move right to get to it.
o
is on the next column over so we have to move rightwards to get to it.
a
is back in the first column so we move left to get to it.
r
is all the way on the right so we move right to it.
d
is two columns to the left ofr
's column.
The characters that need to move to the right are bor
meaning that this is frustration 3.
Additional rules
This is a code-golf challenge so your answers will be scored in bytes with fewer bytes being better. The input will always consist of alphanumeric characters, you can support either capital or lowercase letters and you only need to support one. The input will never be empty.
Testcases
keyboard -> 3
2001aspaceodyssey -> 6
sorrytobotheryou -> 8
thinblueline -> 5
blast2 -> 3
code-golf string
code-golf string
edited Nov 24 '18 at 17:38
Wît Wisarhd
asked Nov 24 '18 at 16:30
Wît WisarhdWît Wisarhd
34k10156366
34k10156366
2
$begingroup$
Suggested test case:"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)
$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
1
$begingroup$
Suggested test case:90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17
|
show 1 more comment
2
$begingroup$
Suggested test case:"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)
$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
1
$begingroup$
Suggested test case:90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17
2
2
$begingroup$
Suggested test case:
"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case:
"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
1
1
$begingroup$
Suggested test case:
90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Suggested test case:
90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17
|
show 1 more comment
14 Answers
14
active
oldest
votes
$begingroup$
JavaScript (Node.js), 61 55 54 bytes
Saved 1 byte thanks to @nwellnhof
Takes input as an array of characters.
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
Try it online!
How?
For all characters but digits greater than $0$, the 0-indexed column $x$ is given by:
$$x=(c-1)bmod 6$$
where $c$ is the ASCII code of the character.
For positive digits $n$, we need to do instead:
$$x=(n+1)bmod 6$$
Examples:
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 = 4 mod 6 = 4
Commented
s => // s = input string (as array)
s.map(p = // initialize p to a non-numeric value
c => // for each character c in s:
r += // update the result r:
p > ( // compare p with
p = ( // the new value of p defined as:
+c ? // if c is a positive digit:
~c // -(int(c) + 1)
: // else:
1-Buffer(c)[0] // -(ord(c) - 1)
) % 6 // apply modulo 6
), // yields 1 if the previous value is greater than the new one
r = 0 // start with r = 0
) | r // end of map(); return r
$endgroup$
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
$begingroup$
@Shaggy It won't. See my suggested test case"blast2"
.
$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,"234"
.
$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
|
show 2 more comments
$begingroup$
Jelly, 11 bytes
⁾04yO‘%6<ƝS
A monadic Link accepting a list of (uppercase) characters.
Try it online!
How?
First replaces any '0'
s with '4'
s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by 6
to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
⁾04yO‘%6<ƝS - Link: list of characters e.g. "BLAST20"
⁾04 - list of characters = ['0', '4']
y - translate "BLAST24"
O - ordinals [66,76,65,83,84,50,52]
‘ - increment [67,77,66,84,85,51,53]
6 - literal six
% - modulo [ 1, 5, 0, 0, 1, 3, 5]
Ɲ - neighbourly:
< - less than? [ 1, 0, 0, 1, 1, 1 ]
S - sum 4
$endgroup$
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
add a comment |
$begingroup$
Perl 6, 45 39 bytes
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
Try it online!
Works with uppercase letters. (2-ord(c))%46%6
computes the reversed x coordinate.
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 32 31 bytes
+/>':(+6 6#,/"a10"+!'26 9 1)?0+
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 85 bytes
import StdEnv
(s=sum[1\a<-s&b<-tl s|b>a])o map(e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 56 bytes
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
Try it online!
Preliminary naive version, will be golfed.
$endgroup$
add a comment |
$begingroup$
Japt -x
, 14 bytes
®rT4 c Ä u6Ãä<
Try it online!
Port of this Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
®rT4 c Ä u6Ãä< :
® Ã :Map each character through:
rT4 : Replace 0 with 4
c : Get the char-code
Ä : Increment it
u6 : Modulo 6
ä< :Replace with 1 if you had to move right, 0 otherwise
:Implicitly sum and output
$endgroup$
add a comment |
$begingroup$
Java (OpenJDK 8), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
Try it online!
Explained
t -> { // Lambda taking a char array as input
int a=9, // Initialise last column value
c=0; // Initialise frustration count
for(int d:t) // Loop through all chars in title
c+= // increment the frustration count if...
a< // The last column is smaller than the current column
(a= // Set last column to current column
(--d+ // Decrement ascii value of char
(d/48==1 // If ascii decremented ascii value is between 48 and 95
?2:0) // increment by 2 (1 total) or 0 (-1 total)
)%6) // Mod 6 to retrieve column index
?1:0; // Increment if to right hand side
return c; // return calculated frustration count
}
$endgroup$
add a comment |
$begingroup$
05AB1E, 12 11 bytes
-1 byte thanks to @Kevin Cruijssen
¾4:Ç>6%¥1@O
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation:
¾4:Ç>6%¥1@O //full program
¾4: //replace all '0's with '4's
Ç //get ASCII code points
> //increment
6% //modulo 6
¥ //get deltas
1@ //is >= 1
O //sum
Try it online!
$endgroup$
1
$begingroup$
0'4
can be¾4
to save a byte (relevant 05AB1E tip).
$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
add a comment |
$begingroup$
Retina 0.8.2, 46 bytes
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);11
Try it online! Link includes test cases. Explanation:
T`l1-90`1-61-61-61-61-61-6
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
.
;$&$*
Convert each column number to unary.
&`;(1+);11
Count the number of columns that are followed by a larger (i.e. rightwards) column. The &`
allows the matches to overlap.
$endgroup$
add a comment |
$begingroup$
Python 2, 84 bytes
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
Try it online!
$endgroup$
add a comment |
$begingroup$
Mathematica, 102 bytes
Differences[Last@@Join[Alphabet,ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
$endgroup$
add a comment |
$begingroup$
PHP, 74 81 77 bytes
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
Run as pipe with -nR
or try it online.
$endgroup$
add a comment |
$begingroup$
C (gcc), 82 79 77 bytes
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This function will only support lowercase inputs
Ungolfed and commented:
o; //Used for output
c(i){ //Calculates the column of given character
i+= //Correct i to get the correct column
i<60 //If i is a digit...
& i>48 //... but not '0'
?1 //Then move it one column on the right
:5; //Else move it five columns on the right
i%=6; //Get the column number
}
f(char*s){ // The actual "frustrating" function
for( //Loop for each character
o=0; //reinitialize output
*++s; //move to next character / while this is not ''
o+=c(*s)>c(s[-1]) //Increment if current character is on the right of the previous one
);
o=o; // Outputs result
}
If my function is allowed to accept wide character strings, it can be reduced to 76 bytes with:
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This version just accept input as int*
instead of char*
Edits:
- Golfed 3 bytes in the calculation of the column (function
c
) - Golfed 2 bytes thanks to ceilingcat
$endgroup$
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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
});
}
});
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%2f176492%2fhow-frustrating-is-my-movie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (Node.js), 61 55 54 bytes
Saved 1 byte thanks to @nwellnhof
Takes input as an array of characters.
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
Try it online!
How?
For all characters but digits greater than $0$, the 0-indexed column $x$ is given by:
$$x=(c-1)bmod 6$$
where $c$ is the ASCII code of the character.
For positive digits $n$, we need to do instead:
$$x=(n+1)bmod 6$$
Examples:
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 = 4 mod 6 = 4
Commented
s => // s = input string (as array)
s.map(p = // initialize p to a non-numeric value
c => // for each character c in s:
r += // update the result r:
p > ( // compare p with
p = ( // the new value of p defined as:
+c ? // if c is a positive digit:
~c // -(int(c) + 1)
: // else:
1-Buffer(c)[0] // -(ord(c) - 1)
) % 6 // apply modulo 6
), // yields 1 if the previous value is greater than the new one
r = 0 // start with r = 0
) | r // end of map(); return r
$endgroup$
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
$begingroup$
@Shaggy It won't. See my suggested test case"blast2"
.
$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,"234"
.
$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
|
show 2 more comments
$begingroup$
JavaScript (Node.js), 61 55 54 bytes
Saved 1 byte thanks to @nwellnhof
Takes input as an array of characters.
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
Try it online!
How?
For all characters but digits greater than $0$, the 0-indexed column $x$ is given by:
$$x=(c-1)bmod 6$$
where $c$ is the ASCII code of the character.
For positive digits $n$, we need to do instead:
$$x=(n+1)bmod 6$$
Examples:
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 = 4 mod 6 = 4
Commented
s => // s = input string (as array)
s.map(p = // initialize p to a non-numeric value
c => // for each character c in s:
r += // update the result r:
p > ( // compare p with
p = ( // the new value of p defined as:
+c ? // if c is a positive digit:
~c // -(int(c) + 1)
: // else:
1-Buffer(c)[0] // -(ord(c) - 1)
) % 6 // apply modulo 6
), // yields 1 if the previous value is greater than the new one
r = 0 // start with r = 0
) | r // end of map(); return r
$endgroup$
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
$begingroup$
@Shaggy It won't. See my suggested test case"blast2"
.
$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,"234"
.
$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
|
show 2 more comments
$begingroup$
JavaScript (Node.js), 61 55 54 bytes
Saved 1 byte thanks to @nwellnhof
Takes input as an array of characters.
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
Try it online!
How?
For all characters but digits greater than $0$, the 0-indexed column $x$ is given by:
$$x=(c-1)bmod 6$$
where $c$ is the ASCII code of the character.
For positive digits $n$, we need to do instead:
$$x=(n+1)bmod 6$$
Examples:
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 = 4 mod 6 = 4
Commented
s => // s = input string (as array)
s.map(p = // initialize p to a non-numeric value
c => // for each character c in s:
r += // update the result r:
p > ( // compare p with
p = ( // the new value of p defined as:
+c ? // if c is a positive digit:
~c // -(int(c) + 1)
: // else:
1-Buffer(c)[0] // -(ord(c) - 1)
) % 6 // apply modulo 6
), // yields 1 if the previous value is greater than the new one
r = 0 // start with r = 0
) | r // end of map(); return r
$endgroup$
JavaScript (Node.js), 61 55 54 bytes
Saved 1 byte thanks to @nwellnhof
Takes input as an array of characters.
s=>s.map(p=c=>r+=p>(p=(+c?~c:1-Buffer(c)[0])%6),r=0)|r
Try it online!
How?
For all characters but digits greater than $0$, the 0-indexed column $x$ is given by:
$$x=(c-1)bmod 6$$
where $c$ is the ASCII code of the character.
For positive digits $n$, we need to do instead:
$$x=(n+1)bmod 6$$
Examples:
"a" --> (97 - 1) mod 6 = 96 mod 6 = 0
"b" --> (98 - 1) mod 6 = 97 mod 6 = 1
"0" --> (48 - 1) mod 6 = 47 mod 6 = 5
"3" --> ( 3 + 1) mod 6 = 4 mod 6 = 4
Commented
s => // s = input string (as array)
s.map(p = // initialize p to a non-numeric value
c => // for each character c in s:
r += // update the result r:
p > ( // compare p with
p = ( // the new value of p defined as:
+c ? // if c is a positive digit:
~c // -(int(c) + 1)
: // else:
1-Buffer(c)[0] // -(ord(c) - 1)
) % 6 // apply modulo 6
), // yields 1 if the previous value is greater than the new one
r = 0 // start with r = 0
) | r // end of map(); return r
edited Nov 24 '18 at 20:55
answered Nov 24 '18 at 16:47
ArnauldArnauld
73.1k689307
73.1k689307
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
$begingroup$
@Shaggy It won't. See my suggested test case"blast2"
.
$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,"234"
.
$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
|
show 2 more comments
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
$begingroup$
@Shaggy It won't. See my suggested test case"blast2"
.
$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,"234"
.
$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
$begingroup$
It seems to work without the ternary for 46 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 17:51
1
1
$begingroup$
@Shaggy It won't. See my suggested test case
"blast2"
.$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
@Shaggy It won't. See my suggested test case
"blast2"
.$endgroup$
– Arnauld
Nov 24 '18 at 17:52
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
$begingroup$
Ah. In that case: 53 bytes
$endgroup$
– Shaggy
Nov 24 '18 at 18:29
1
1
$begingroup$
@Shaggy A bitwise OR would fail for, say,
"234"
.$endgroup$
– Arnauld
Nov 24 '18 at 18:33
$begingroup$
@Shaggy A bitwise OR would fail for, say,
"234"
.$endgroup$
– Arnauld
Nov 24 '18 at 18:33
3
3
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
$begingroup$
Less whiskey is never the answer!
$endgroup$
– Shaggy
Nov 24 '18 at 18:58
|
show 2 more comments
$begingroup$
Jelly, 11 bytes
⁾04yO‘%6<ƝS
A monadic Link accepting a list of (uppercase) characters.
Try it online!
How?
First replaces any '0'
s with '4'
s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by 6
to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
⁾04yO‘%6<ƝS - Link: list of characters e.g. "BLAST20"
⁾04 - list of characters = ['0', '4']
y - translate "BLAST24"
O - ordinals [66,76,65,83,84,50,52]
‘ - increment [67,77,66,84,85,51,53]
6 - literal six
% - modulo [ 1, 5, 0, 0, 1, 3, 5]
Ɲ - neighbourly:
< - less than? [ 1, 0, 0, 1, 1, 1 ]
S - sum 4
$endgroup$
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
add a comment |
$begingroup$
Jelly, 11 bytes
⁾04yO‘%6<ƝS
A monadic Link accepting a list of (uppercase) characters.
Try it online!
How?
First replaces any '0'
s with '4'
s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by 6
to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
⁾04yO‘%6<ƝS - Link: list of characters e.g. "BLAST20"
⁾04 - list of characters = ['0', '4']
y - translate "BLAST24"
O - ordinals [66,76,65,83,84,50,52]
‘ - increment [67,77,66,84,85,51,53]
6 - literal six
% - modulo [ 1, 5, 0, 0, 1, 3, 5]
Ɲ - neighbourly:
< - less than? [ 1, 0, 0, 1, 1, 1 ]
S - sum 4
$endgroup$
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
add a comment |
$begingroup$
Jelly, 11 bytes
⁾04yO‘%6<ƝS
A monadic Link accepting a list of (uppercase) characters.
Try it online!
How?
First replaces any '0'
s with '4'
s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by 6
to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
⁾04yO‘%6<ƝS - Link: list of characters e.g. "BLAST20"
⁾04 - list of characters = ['0', '4']
y - translate "BLAST24"
O - ordinals [66,76,65,83,84,50,52]
‘ - increment [67,77,66,84,85,51,53]
6 - literal six
% - modulo [ 1, 5, 0, 0, 1, 3, 5]
Ɲ - neighbourly:
< - less than? [ 1, 0, 0, 1, 1, 1 ]
S - sum 4
$endgroup$
Jelly, 11 bytes
⁾04yO‘%6<ƝS
A monadic Link accepting a list of (uppercase) characters.
Try it online!
How?
First replaces any '0'
s with '4'
s (so the rest of the code treats them as being in the rightmost column). Then casts to ordinals, adds one and modulo's by 6
to get 0-based column indices. Then compares neighbours with is-less-than and sums the result.
⁾04yO‘%6<ƝS - Link: list of characters e.g. "BLAST20"
⁾04 - list of characters = ['0', '4']
y - translate "BLAST24"
O - ordinals [66,76,65,83,84,50,52]
‘ - increment [67,77,66,84,85,51,53]
6 - literal six
% - modulo [ 1, 5, 0, 0, 1, 3, 5]
Ɲ - neighbourly:
< - less than? [ 1, 0, 0, 1, 1, 1 ]
S - sum 4
edited Nov 24 '18 at 18:05
answered Nov 24 '18 at 17:21
Jonathan AllanJonathan Allan
51.1k534166
51.1k534166
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
add a comment |
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
$begingroup$
Oh my, this is art.
$endgroup$
– Erik the Outgolfer
Nov 24 '18 at 21:07
add a comment |
$begingroup$
Perl 6, 45 39 bytes
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
Try it online!
Works with uppercase letters. (2-ord(c))%46%6
computes the reversed x coordinate.
$endgroup$
add a comment |
$begingroup$
Perl 6, 45 39 bytes
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
Try it online!
Works with uppercase letters. (2-ord(c))%46%6
computes the reversed x coordinate.
$endgroup$
add a comment |
$begingroup$
Perl 6, 45 39 bytes
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
Try it online!
Works with uppercase letters. (2-ord(c))%46%6
computes the reversed x coordinate.
$endgroup$
Perl 6, 45 39 bytes
{sum .[1..*]Z<$_}o{(2 X-.ords)X%46 X%6}
Try it online!
Works with uppercase letters. (2-ord(c))%46%6
computes the reversed x coordinate.
edited Nov 25 '18 at 11:13
answered Nov 24 '18 at 20:13
nwellnhofnwellnhof
6,53511125
6,53511125
add a comment |
add a comment |
$begingroup$
K (ngn/k), 32 31 bytes
+/>':(+6 6#,/"a10"+!'26 9 1)?0+
Try it online!
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 32 31 bytes
+/>':(+6 6#,/"a10"+!'26 9 1)?0+
Try it online!
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 32 31 bytes
+/>':(+6 6#,/"a10"+!'26 9 1)?0+
Try it online!
$endgroup$
K (ngn/k), 32 31 bytes
+/>':(+6 6#,/"a10"+!'26 9 1)?0+
Try it online!
edited Nov 24 '18 at 20:53
answered Nov 24 '18 at 20:44
ngnngn
6,96112559
6,96112559
add a comment |
add a comment |
$begingroup$
Clean, 85 bytes
import StdEnv
(s=sum[1\a<-s&b<-tl s|b>a])o map(e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 85 bytes
import StdEnv
(s=sum[1\a<-s&b<-tl s|b>a])o map(e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 85 bytes
import StdEnv
(s=sum[1\a<-s&b<-tl s|b>a])o map(e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
Try it online!
$endgroup$
Clean, 85 bytes
import StdEnv
(s=sum[1\a<-s&b<-tl s|b>a])o map(e=(toInt e+if(e-'1'>'/')1 -1)rem 6)
Try it online!
answered Nov 25 '18 at 21:26
ΟurousΟurous
6,55211033
6,55211033
add a comment |
add a comment |
$begingroup$
Ruby, 56 bytes
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
Try it online!
Preliminary naive version, will be golfed.
$endgroup$
add a comment |
$begingroup$
Ruby, 56 bytes
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
Try it online!
Preliminary naive version, will be golfed.
$endgroup$
add a comment |
$begingroup$
Ruby, 56 bytes
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
Try it online!
Preliminary naive version, will be golfed.
$endgroup$
Ruby, 56 bytes
->s{w=9;s.count{|c|w<w=[*?a..?z,*?1..?9,?0].index(c)%6}}
Try it online!
Preliminary naive version, will be golfed.
answered Nov 26 '18 at 15:02
G BG B
7,7061328
7,7061328
add a comment |
add a comment |
$begingroup$
Japt -x
, 14 bytes
®rT4 c Ä u6Ãä<
Try it online!
Port of this Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
®rT4 c Ä u6Ãä< :
® Ã :Map each character through:
rT4 : Replace 0 with 4
c : Get the char-code
Ä : Increment it
u6 : Modulo 6
ä< :Replace with 1 if you had to move right, 0 otherwise
:Implicitly sum and output
$endgroup$
add a comment |
$begingroup$
Japt -x
, 14 bytes
®rT4 c Ä u6Ãä<
Try it online!
Port of this Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
®rT4 c Ä u6Ãä< :
® Ã :Map each character through:
rT4 : Replace 0 with 4
c : Get the char-code
Ä : Increment it
u6 : Modulo 6
ä< :Replace with 1 if you had to move right, 0 otherwise
:Implicitly sum and output
$endgroup$
add a comment |
$begingroup$
Japt -x
, 14 bytes
®rT4 c Ä u6Ãä<
Try it online!
Port of this Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
®rT4 c Ä u6Ãä< :
® Ã :Map each character through:
rT4 : Replace 0 with 4
c : Get the char-code
Ä : Increment it
u6 : Modulo 6
ä< :Replace with 1 if you had to move right, 0 otherwise
:Implicitly sum and output
$endgroup$
Japt -x
, 14 bytes
®rT4 c Ä u6Ãä<
Try it online!
Port of this Jelly answer. Takes input as an array of characters, with letters uppercase.
Explanation:
®rT4 c Ä u6Ãä< :
® Ã :Map each character through:
rT4 : Replace 0 with 4
c : Get the char-code
Ä : Increment it
u6 : Modulo 6
ä< :Replace with 1 if you had to move right, 0 otherwise
:Implicitly sum and output
edited Nov 26 '18 at 15:05
answered Nov 25 '18 at 19:36
Kamil DrakariKamil Drakari
3,091416
3,091416
add a comment |
add a comment |
$begingroup$
Java (OpenJDK 8), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
Try it online!
Explained
t -> { // Lambda taking a char array as input
int a=9, // Initialise last column value
c=0; // Initialise frustration count
for(int d:t) // Loop through all chars in title
c+= // increment the frustration count if...
a< // The last column is smaller than the current column
(a= // Set last column to current column
(--d+ // Decrement ascii value of char
(d/48==1 // If ascii decremented ascii value is between 48 and 95
?2:0) // increment by 2 (1 total) or 0 (-1 total)
)%6) // Mod 6 to retrieve column index
?1:0; // Increment if to right hand side
return c; // return calculated frustration count
}
$endgroup$
add a comment |
$begingroup$
Java (OpenJDK 8), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
Try it online!
Explained
t -> { // Lambda taking a char array as input
int a=9, // Initialise last column value
c=0; // Initialise frustration count
for(int d:t) // Loop through all chars in title
c+= // increment the frustration count if...
a< // The last column is smaller than the current column
(a= // Set last column to current column
(--d+ // Decrement ascii value of char
(d/48==1 // If ascii decremented ascii value is between 48 and 95
?2:0) // increment by 2 (1 total) or 0 (-1 total)
)%6) // Mod 6 to retrieve column index
?1:0; // Increment if to right hand side
return c; // return calculated frustration count
}
$endgroup$
add a comment |
$begingroup$
Java (OpenJDK 8), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
Try it online!
Explained
t -> { // Lambda taking a char array as input
int a=9, // Initialise last column value
c=0; // Initialise frustration count
for(int d:t) // Loop through all chars in title
c+= // increment the frustration count if...
a< // The last column is smaller than the current column
(a= // Set last column to current column
(--d+ // Decrement ascii value of char
(d/48==1 // If ascii decremented ascii value is between 48 and 95
?2:0) // increment by 2 (1 total) or 0 (-1 total)
)%6) // Mod 6 to retrieve column index
?1:0; // Increment if to right hand side
return c; // return calculated frustration count
}
$endgroup$
Java (OpenJDK 8), 73 bytes
Not a bad solution for Java! That zero being on the right-hand side cost me several bytes.
t->{int a=9,c=0;for(int d:t)c+=a<(a=(--d+(d/48==1?2:0))%6)?1:0;return c;}
Try it online!
Explained
t -> { // Lambda taking a char array as input
int a=9, // Initialise last column value
c=0; // Initialise frustration count
for(int d:t) // Loop through all chars in title
c+= // increment the frustration count if...
a< // The last column is smaller than the current column
(a= // Set last column to current column
(--d+ // Decrement ascii value of char
(d/48==1 // If ascii decremented ascii value is between 48 and 95
?2:0) // increment by 2 (1 total) or 0 (-1 total)
)%6) // Mod 6 to retrieve column index
?1:0; // Increment if to right hand side
return c; // return calculated frustration count
}
answered Nov 26 '18 at 17:34
Luke StevensLuke Stevens
744214
744214
add a comment |
add a comment |
$begingroup$
05AB1E, 12 11 bytes
-1 byte thanks to @Kevin Cruijssen
¾4:Ç>6%¥1@O
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation:
¾4:Ç>6%¥1@O //full program
¾4: //replace all '0's with '4's
Ç //get ASCII code points
> //increment
6% //modulo 6
¥ //get deltas
1@ //is >= 1
O //sum
Try it online!
$endgroup$
1
$begingroup$
0'4
can be¾4
to save a byte (relevant 05AB1E tip).
$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
add a comment |
$begingroup$
05AB1E, 12 11 bytes
-1 byte thanks to @Kevin Cruijssen
¾4:Ç>6%¥1@O
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation:
¾4:Ç>6%¥1@O //full program
¾4: //replace all '0's with '4's
Ç //get ASCII code points
> //increment
6% //modulo 6
¥ //get deltas
1@ //is >= 1
O //sum
Try it online!
$endgroup$
1
$begingroup$
0'4
can be¾4
to save a byte (relevant 05AB1E tip).
$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
add a comment |
$begingroup$
05AB1E, 12 11 bytes
-1 byte thanks to @Kevin Cruijssen
¾4:Ç>6%¥1@O
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation:
¾4:Ç>6%¥1@O //full program
¾4: //replace all '0's with '4's
Ç //get ASCII code points
> //increment
6% //modulo 6
¥ //get deltas
1@ //is >= 1
O //sum
Try it online!
$endgroup$
05AB1E, 12 11 bytes
-1 byte thanks to @Kevin Cruijssen
¾4:Ç>6%¥1@O
Another port of Jonathan Allan's Jelly answer. Takes input in uppercase.
Explanation:
¾4:Ç>6%¥1@O //full program
¾4: //replace all '0's with '4's
Ç //get ASCII code points
> //increment
6% //modulo 6
¥ //get deltas
1@ //is >= 1
O //sum
Try it online!
edited Nov 28 '18 at 14:35
answered Nov 26 '18 at 15:04
CowabungholeCowabunghole
1,065419
1,065419
1
$begingroup$
0'4
can be¾4
to save a byte (relevant 05AB1E tip).
$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
add a comment |
1
$begingroup$
0'4
can be¾4
to save a byte (relevant 05AB1E tip).
$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
1
1
$begingroup$
0'4
can be ¾4
to save a byte (relevant 05AB1E tip).$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
$begingroup$
0'4
can be ¾4
to save a byte (relevant 05AB1E tip).$endgroup$
– Kevin Cruijssen
Nov 28 '18 at 9:06
add a comment |
$begingroup$
Retina 0.8.2, 46 bytes
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);11
Try it online! Link includes test cases. Explanation:
T`l1-90`1-61-61-61-61-61-6
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
.
;$&$*
Convert each column number to unary.
&`;(1+);11
Count the number of columns that are followed by a larger (i.e. rightwards) column. The &`
allows the matches to overlap.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 46 bytes
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);11
Try it online! Link includes test cases. Explanation:
T`l1-90`1-61-61-61-61-61-6
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
.
;$&$*
Convert each column number to unary.
&`;(1+);11
Count the number of columns that are followed by a larger (i.e. rightwards) column. The &`
allows the matches to overlap.
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 46 bytes
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);11
Try it online! Link includes test cases. Explanation:
T`l1-90`1-61-61-61-61-61-6
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
.
;$&$*
Convert each column number to unary.
&`;(1+);11
Count the number of columns that are followed by a larger (i.e. rightwards) column. The &`
allows the matches to overlap.
$endgroup$
Retina 0.8.2, 46 bytes
T`l1-90`1-61-61-61-61-61-6
.
;$&$*
&`;(1+);11
Try it online! Link includes test cases. Explanation:
T`l1-90`1-61-61-61-61-61-6
List the alphabet and digits in the order on the OSK and map each one to a (1-indexed) column number.
.
;$&$*
Convert each column number to unary.
&`;(1+);11
Count the number of columns that are followed by a larger (i.e. rightwards) column. The &`
allows the matches to overlap.
answered Nov 24 '18 at 20:49
NeilNeil
79.8k744177
79.8k744177
add a comment |
add a comment |
$begingroup$
Python 2, 84 bytes
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 84 bytes
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 84 bytes
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
Try it online!
$endgroup$
Python 2, 84 bytes
def f(s,k=6):j=(ord(s[0])+('0'<s[0]<':')*2-1)%6;return(j>k)+(~-len(s)and f(s[1:],j))
Try it online!
edited Nov 25 '18 at 6:20
answered Nov 25 '18 at 4:42
Chas BrownChas Brown
4,8491522
4,8491522
add a comment |
add a comment |
$begingroup$
Mathematica, 102 bytes
Differences[Last@@Join[Alphabet,ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
$endgroup$
add a comment |
$begingroup$
Mathematica, 102 bytes
Differences[Last@@Join[Alphabet,ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
$endgroup$
add a comment |
$begingroup$
Mathematica, 102 bytes
Differences[Last@@Join[Alphabet,ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
$endgroup$
Mathematica, 102 bytes
Differences[Last@@Join[Alphabet,ToString/@Range@9,{"0"}]~Partition~6~Position~#&/@#]~Count~_?(#>0&)&
Pure function. Takes a list of characters as input and returns a number as output. This is a pretty naive solution, golfing suggestions welcome.
answered Nov 25 '18 at 15:24
LegionMammal978LegionMammal978
15.1k41852
15.1k41852
add a comment |
add a comment |
$begingroup$
PHP, 74 81 77 bytes
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
Run as pipe with -nR
or try it online.
$endgroup$
add a comment |
$begingroup$
PHP, 74 81 77 bytes
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
Run as pipe with -nR
or try it online.
$endgroup$
add a comment |
$begingroup$
PHP, 74 81 77 bytes
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
Run as pipe with -nR
or try it online.
$endgroup$
PHP, 74 81 77 bytes
for(;$o=ord($argn[$i]);$i++&&$f+=$p<$x,$p=$x)$x=(--$o/48^1?$o:$o+2)%6;echo$f;
Run as pipe with -nR
or try it online.
edited Nov 29 '18 at 13:21
answered Nov 29 '18 at 12:41
TitusTitus
13k11238
13k11238
add a comment |
add a comment |
$begingroup$
C (gcc), 82 79 77 bytes
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This function will only support lowercase inputs
Ungolfed and commented:
o; //Used for output
c(i){ //Calculates the column of given character
i+= //Correct i to get the correct column
i<60 //If i is a digit...
& i>48 //... but not '0'
?1 //Then move it one column on the right
:5; //Else move it five columns on the right
i%=6; //Get the column number
}
f(char*s){ // The actual "frustrating" function
for( //Loop for each character
o=0; //reinitialize output
*++s; //move to next character / while this is not ''
o+=c(*s)>c(s[-1]) //Increment if current character is on the right of the previous one
);
o=o; // Outputs result
}
If my function is allowed to accept wide character strings, it can be reduced to 76 bytes with:
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This version just accept input as int*
instead of char*
Edits:
- Golfed 3 bytes in the calculation of the column (function
c
) - Golfed 2 bytes thanks to ceilingcat
$endgroup$
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
add a comment |
$begingroup$
C (gcc), 82 79 77 bytes
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This function will only support lowercase inputs
Ungolfed and commented:
o; //Used for output
c(i){ //Calculates the column of given character
i+= //Correct i to get the correct column
i<60 //If i is a digit...
& i>48 //... but not '0'
?1 //Then move it one column on the right
:5; //Else move it five columns on the right
i%=6; //Get the column number
}
f(char*s){ // The actual "frustrating" function
for( //Loop for each character
o=0; //reinitialize output
*++s; //move to next character / while this is not ''
o+=c(*s)>c(s[-1]) //Increment if current character is on the right of the previous one
);
o=o; // Outputs result
}
If my function is allowed to accept wide character strings, it can be reduced to 76 bytes with:
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This version just accept input as int*
instead of char*
Edits:
- Golfed 3 bytes in the calculation of the column (function
c
) - Golfed 2 bytes thanks to ceilingcat
$endgroup$
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
add a comment |
$begingroup$
C (gcc), 82 79 77 bytes
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This function will only support lowercase inputs
Ungolfed and commented:
o; //Used for output
c(i){ //Calculates the column of given character
i+= //Correct i to get the correct column
i<60 //If i is a digit...
& i>48 //... but not '0'
?1 //Then move it one column on the right
:5; //Else move it five columns on the right
i%=6; //Get the column number
}
f(char*s){ // The actual "frustrating" function
for( //Loop for each character
o=0; //reinitialize output
*++s; //move to next character / while this is not ''
o+=c(*s)>c(s[-1]) //Increment if current character is on the right of the previous one
);
o=o; // Outputs result
}
If my function is allowed to accept wide character strings, it can be reduced to 76 bytes with:
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This version just accept input as int*
instead of char*
Edits:
- Golfed 3 bytes in the calculation of the column (function
c
) - Golfed 2 bytes thanks to ceilingcat
$endgroup$
C (gcc), 82 79 77 bytes
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(char*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This function will only support lowercase inputs
Ungolfed and commented:
o; //Used for output
c(i){ //Calculates the column of given character
i+= //Correct i to get the correct column
i<60 //If i is a digit...
& i>48 //... but not '0'
?1 //Then move it one column on the right
:5; //Else move it five columns on the right
i%=6; //Get the column number
}
f(char*s){ // The actual "frustrating" function
for( //Loop for each character
o=0; //reinitialize output
*++s; //move to next character / while this is not ''
o+=c(*s)>c(s[-1]) //Increment if current character is on the right of the previous one
);
o=o; // Outputs result
}
If my function is allowed to accept wide character strings, it can be reduced to 76 bytes with:
o;c(i){i+=i<60&i>48?1:5;i%=6;}f(int*s){for(o=0;*++s;o+=c(*s)>c(s[-1]));o=o;}
Try it online!
This version just accept input as int*
instead of char*
Edits:
- Golfed 3 bytes in the calculation of the column (function
c
) - Golfed 2 bytes thanks to ceilingcat
edited Dec 4 '18 at 8:28
answered Nov 26 '18 at 16:24
AnnyoAnnyo
1313
1313
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
add a comment |
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
$begingroup$
And there, 77 bytes
$endgroup$
– Rogem
Nov 26 '18 at 16:59
add a comment |
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%2f176492%2fhow-frustrating-is-my-movie%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
2
$begingroup$
Suggested test case:
"blast2" -> 3
(not a real movie, but some answers have problems with such test cases)$endgroup$
– Arnauld
Nov 24 '18 at 17:37
$begingroup$
Suggested test case: one consisting of only digits, such as 5 -> 0
$endgroup$
– lirtosiast
Nov 24 '18 at 18:01
1
$begingroup$
Suggested test case:
90 -> 1
$endgroup$
– nwellnhof
Nov 24 '18 at 20:46
$begingroup$
Can we assume the input string will be non-empty?
$endgroup$
– Chas Brown
Nov 25 '18 at 4:06
$begingroup$
@ChasBrown That is covered in the question.
$endgroup$
– Wît Wisarhd
Nov 25 '18 at 4:17