How many syllables in that number?
up vote
8
down vote
favorite
I'd love to take a number and know how many syllables are in it, when spoken in English.
Let's limit this to positive integers which are less than one thousand.
I'm British, so we're going to follow the hundreds column with an 'and' when there are any non-zero digits after it.
The Challenge
- Write some code which will accept a positive integer lower than 1000 and output the number of syllables in the words which represent that number in British English.
- It DOES NOT need to generate the words to represent the numbers, only the number of syllables they contain.
- It's code golf, attempt to achieve this in the fewest bytes.
- Use any language you like.
- The standard loopholes are forbidden.
Test Cases
| N | In words | Syllables |
| 1 | one | 1 |
| 2 | two | 1 |
| 3 | three | 1 |
| 4 | four | 1 |
| 5 | five | 1 |
| 6 | six | 1 |
| 7 | sev-en | 2 |
| 8 | eight | 1 |
| 9 | nine | 1 |
| 10 | ten | 1 |
| 11 | el-ev-en | 3 |
| 12 | twelve | 1 |
| 13 | thir-teen | 2 |
| 14 | four-teen | 2 |
| 17 | se-ven-teen | 3 |
| 20 | twen-ty | 2 |
| 21 | twen-ty one | 3 |
| 42 | four-ty two | 3 |
| 73 | sev-en-ty three | 4 |
| 77 | sev-en-ty sev-en | 5 |
| 100 | one hund-red | 3 |
| 110 | one hund-red and ten | 5 |
| 111 | one hund-red and el-ev-en | 7 |
| 555 | five hund-red and fif-ty five | 7 |
| 700 | sev-en hund-red | 4 |
| 770 | sev-en hund-red and sev-en-ty | 8 |
| 777 | sev-en hund-red and sev-en-ty sev-en | 10 |
| 999 | nine hund-red and nine-ty nine | 7 |
code-golf natural-language
add a comment |
up vote
8
down vote
favorite
I'd love to take a number and know how many syllables are in it, when spoken in English.
Let's limit this to positive integers which are less than one thousand.
I'm British, so we're going to follow the hundreds column with an 'and' when there are any non-zero digits after it.
The Challenge
- Write some code which will accept a positive integer lower than 1000 and output the number of syllables in the words which represent that number in British English.
- It DOES NOT need to generate the words to represent the numbers, only the number of syllables they contain.
- It's code golf, attempt to achieve this in the fewest bytes.
- Use any language you like.
- The standard loopholes are forbidden.
Test Cases
| N | In words | Syllables |
| 1 | one | 1 |
| 2 | two | 1 |
| 3 | three | 1 |
| 4 | four | 1 |
| 5 | five | 1 |
| 6 | six | 1 |
| 7 | sev-en | 2 |
| 8 | eight | 1 |
| 9 | nine | 1 |
| 10 | ten | 1 |
| 11 | el-ev-en | 3 |
| 12 | twelve | 1 |
| 13 | thir-teen | 2 |
| 14 | four-teen | 2 |
| 17 | se-ven-teen | 3 |
| 20 | twen-ty | 2 |
| 21 | twen-ty one | 3 |
| 42 | four-ty two | 3 |
| 73 | sev-en-ty three | 4 |
| 77 | sev-en-ty sev-en | 5 |
| 100 | one hund-red | 3 |
| 110 | one hund-red and ten | 5 |
| 111 | one hund-red and el-ev-en | 7 |
| 555 | five hund-red and fif-ty five | 7 |
| 700 | sev-en hund-red | 4 |
| 770 | sev-en hund-red and sev-en-ty | 8 |
| 777 | sev-en hund-red and sev-en-ty sev-en | 10 |
| 999 | nine hund-red and nine-ty nine | 7 |
code-golf natural-language
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
I'd love to take a number and know how many syllables are in it, when spoken in English.
Let's limit this to positive integers which are less than one thousand.
I'm British, so we're going to follow the hundreds column with an 'and' when there are any non-zero digits after it.
The Challenge
- Write some code which will accept a positive integer lower than 1000 and output the number of syllables in the words which represent that number in British English.
- It DOES NOT need to generate the words to represent the numbers, only the number of syllables they contain.
- It's code golf, attempt to achieve this in the fewest bytes.
- Use any language you like.
- The standard loopholes are forbidden.
Test Cases
| N | In words | Syllables |
| 1 | one | 1 |
| 2 | two | 1 |
| 3 | three | 1 |
| 4 | four | 1 |
| 5 | five | 1 |
| 6 | six | 1 |
| 7 | sev-en | 2 |
| 8 | eight | 1 |
| 9 | nine | 1 |
| 10 | ten | 1 |
| 11 | el-ev-en | 3 |
| 12 | twelve | 1 |
| 13 | thir-teen | 2 |
| 14 | four-teen | 2 |
| 17 | se-ven-teen | 3 |
| 20 | twen-ty | 2 |
| 21 | twen-ty one | 3 |
| 42 | four-ty two | 3 |
| 73 | sev-en-ty three | 4 |
| 77 | sev-en-ty sev-en | 5 |
| 100 | one hund-red | 3 |
| 110 | one hund-red and ten | 5 |
| 111 | one hund-red and el-ev-en | 7 |
| 555 | five hund-red and fif-ty five | 7 |
| 700 | sev-en hund-red | 4 |
| 770 | sev-en hund-red and sev-en-ty | 8 |
| 777 | sev-en hund-red and sev-en-ty sev-en | 10 |
| 999 | nine hund-red and nine-ty nine | 7 |
code-golf natural-language
I'd love to take a number and know how many syllables are in it, when spoken in English.
Let's limit this to positive integers which are less than one thousand.
I'm British, so we're going to follow the hundreds column with an 'and' when there are any non-zero digits after it.
The Challenge
- Write some code which will accept a positive integer lower than 1000 and output the number of syllables in the words which represent that number in British English.
- It DOES NOT need to generate the words to represent the numbers, only the number of syllables they contain.
- It's code golf, attempt to achieve this in the fewest bytes.
- Use any language you like.
- The standard loopholes are forbidden.
Test Cases
| N | In words | Syllables |
| 1 | one | 1 |
| 2 | two | 1 |
| 3 | three | 1 |
| 4 | four | 1 |
| 5 | five | 1 |
| 6 | six | 1 |
| 7 | sev-en | 2 |
| 8 | eight | 1 |
| 9 | nine | 1 |
| 10 | ten | 1 |
| 11 | el-ev-en | 3 |
| 12 | twelve | 1 |
| 13 | thir-teen | 2 |
| 14 | four-teen | 2 |
| 17 | se-ven-teen | 3 |
| 20 | twen-ty | 2 |
| 21 | twen-ty one | 3 |
| 42 | four-ty two | 3 |
| 73 | sev-en-ty three | 4 |
| 77 | sev-en-ty sev-en | 5 |
| 100 | one hund-red | 3 |
| 110 | one hund-red and ten | 5 |
| 111 | one hund-red and el-ev-en | 7 |
| 555 | five hund-red and fif-ty five | 7 |
| 700 | sev-en hund-red | 4 |
| 770 | sev-en hund-red and sev-en-ty | 8 |
| 777 | sev-en hund-red and sev-en-ty sev-en | 10 |
| 999 | nine hund-red and nine-ty nine | 7 |
code-golf natural-language
code-golf natural-language
edited 1 hour ago
asked 2 hours ago
AJFaraday
3,18142853
3,18142853
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago
add a comment |
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago
add a comment |
4 Answers
4
active
oldest
votes
up vote
5
down vote
Python 2, 112 bytes
f=lambda n:n>99and f(n/100)+3+f(n%100)-(n%100<1)or n>19and f(n/10)+1+f(n%10)or([0]+[1]*6+[2,1,1,1,3,1]+[2]*7)[n]
Try it online!
You can golfand f(n/10)+1
toand-~f(n/10)
to save a byte.
– Kevin Cruijssen
1 hour ago
2
Also, your[2]*7
part will fail for17
, since that should be 3 instead of 2 (sev-en-teen
).
– Kevin Cruijssen
1 hour ago
add a comment |
up vote
3
down vote
05AB1E, 34 bytes
т%UεĀy7Q>*}`Iт@3*X_(X20@X12Q(X11QO
Try it online or verify all [1,999]
test cases.
Explanation:
With all checks mentioned it will result in 1 for truthy and 0 for falsey.
т% # Take modulo-100 of the (implicit) input
# i.e. 710 → 10
U # Pop and store it in variable `X`
ε } # Map each digit of the (implicit) input to:
y7Q # Check if the digit is 7
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
> # Increase that result by 1
# i.e. 1 → 2
# i.e. 0 → 1
Ā # Trutify the digit (0 if 0; 1 otherwise)
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
* # And multiply them with each other
# i.e. 2 and 1 → 2
# i.e. 0 and 0 → 0
# i.e. [7,1,0] → [2,1,0]
` # And push all mapped digits to the stack
Iт@ # Check if the input is larger than or equal to 100
# i.e. 710 → 1 (truthy)
3* # Multiply that result by 3 (for 'hund-red and')
# i.e. 1 → 3
X_ # Check if variable `X` is 0
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'and')
# i.e. 0 → 0
X20@ # Check if variable `X` is larger than or equal to 20 (for '-ty')
# i.e. 10 → 0 (falsey)
X12Q # Check if variable `X` is exactly 12
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'teen')
# i.e. 0 → 0
X11Q # Check if variable `X` is exactly 11 (for 'el-ev-en' minus 'one one')
# i.e. 10 → 0 (falsey)
O # Sum everything on the stack (and output implicitly)
# i.e. [2,1,0,3,0,0,0,0] → 6
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally hadI
(input) instead ofX
(input mod 100) when checking if it's larger than 20 for the +1 ofty
.
– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..>
(check if input is larger than 100) has been replaced with@
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..
– Kevin Cruijssen
1 hour ago
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
|
show 2 more comments
up vote
3
down vote
JavaScript (ES6), 90 bytes
n=>(s='01111112111312222322',n>99&&+s[n/100|0]+2+!!(n%=100))+~~(s[n]||+s[n/10&7]-~s[n%10])
Try it online!
add a comment |
up vote
0
down vote
Jelly, 28 25 23 bytes
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ
Try it online!
How it works
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ Main link. Argument: n (integer in [1, ..., 999])
9 Set the return value to 9.
Ḋ Dequeue; yield [2, 3, 4, 5, 6, 7, 8, 9].
Ż Zero; yield [0, 2, 3, 4, 5, 6, 7, 8, 9].
;2 Concat 2, yield [0, 2, 3, 4, 5, 6, 7, 8, 9, 2].
+⁵ Add 10; yield [10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
Ż Zero; yield [0, 10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
%ȷ2$ Yield n % 1e2.
ċ Count the occurrences of the modulus in the array.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
Ṡ Take the sign of each decimal digit (0 or 1).
Ḅ Convert the array of signs from base 2 to integer.
ạ Compute the abs. difference of the results to both sides.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
ċ7 Count the number of 7's.
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
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',
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%2f177586%2fhow-many-syllables-in-that-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Python 2, 112 bytes
f=lambda n:n>99and f(n/100)+3+f(n%100)-(n%100<1)or n>19and f(n/10)+1+f(n%10)or([0]+[1]*6+[2,1,1,1,3,1]+[2]*7)[n]
Try it online!
You can golfand f(n/10)+1
toand-~f(n/10)
to save a byte.
– Kevin Cruijssen
1 hour ago
2
Also, your[2]*7
part will fail for17
, since that should be 3 instead of 2 (sev-en-teen
).
– Kevin Cruijssen
1 hour ago
add a comment |
up vote
5
down vote
Python 2, 112 bytes
f=lambda n:n>99and f(n/100)+3+f(n%100)-(n%100<1)or n>19and f(n/10)+1+f(n%10)or([0]+[1]*6+[2,1,1,1,3,1]+[2]*7)[n]
Try it online!
You can golfand f(n/10)+1
toand-~f(n/10)
to save a byte.
– Kevin Cruijssen
1 hour ago
2
Also, your[2]*7
part will fail for17
, since that should be 3 instead of 2 (sev-en-teen
).
– Kevin Cruijssen
1 hour ago
add a comment |
up vote
5
down vote
up vote
5
down vote
Python 2, 112 bytes
f=lambda n:n>99and f(n/100)+3+f(n%100)-(n%100<1)or n>19and f(n/10)+1+f(n%10)or([0]+[1]*6+[2,1,1,1,3,1]+[2]*7)[n]
Try it online!
Python 2, 112 bytes
f=lambda n:n>99and f(n/100)+3+f(n%100)-(n%100<1)or n>19and f(n/10)+1+f(n%10)or([0]+[1]*6+[2,1,1,1,3,1]+[2]*7)[n]
Try it online!
answered 1 hour ago
TFeld
14.1k21240
14.1k21240
You can golfand f(n/10)+1
toand-~f(n/10)
to save a byte.
– Kevin Cruijssen
1 hour ago
2
Also, your[2]*7
part will fail for17
, since that should be 3 instead of 2 (sev-en-teen
).
– Kevin Cruijssen
1 hour ago
add a comment |
You can golfand f(n/10)+1
toand-~f(n/10)
to save a byte.
– Kevin Cruijssen
1 hour ago
2
Also, your[2]*7
part will fail for17
, since that should be 3 instead of 2 (sev-en-teen
).
– Kevin Cruijssen
1 hour ago
You can golf
and f(n/10)+1
to and-~f(n/10)
to save a byte.– Kevin Cruijssen
1 hour ago
You can golf
and f(n/10)+1
to and-~f(n/10)
to save a byte.– Kevin Cruijssen
1 hour ago
2
2
Also, your
[2]*7
part will fail for 17
, since that should be 3 instead of 2 (sev-en-teen
).– Kevin Cruijssen
1 hour ago
Also, your
[2]*7
part will fail for 17
, since that should be 3 instead of 2 (sev-en-teen
).– Kevin Cruijssen
1 hour ago
add a comment |
up vote
3
down vote
05AB1E, 34 bytes
т%UεĀy7Q>*}`Iт@3*X_(X20@X12Q(X11QO
Try it online or verify all [1,999]
test cases.
Explanation:
With all checks mentioned it will result in 1 for truthy and 0 for falsey.
т% # Take modulo-100 of the (implicit) input
# i.e. 710 → 10
U # Pop and store it in variable `X`
ε } # Map each digit of the (implicit) input to:
y7Q # Check if the digit is 7
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
> # Increase that result by 1
# i.e. 1 → 2
# i.e. 0 → 1
Ā # Trutify the digit (0 if 0; 1 otherwise)
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
* # And multiply them with each other
# i.e. 2 and 1 → 2
# i.e. 0 and 0 → 0
# i.e. [7,1,0] → [2,1,0]
` # And push all mapped digits to the stack
Iт@ # Check if the input is larger than or equal to 100
# i.e. 710 → 1 (truthy)
3* # Multiply that result by 3 (for 'hund-red and')
# i.e. 1 → 3
X_ # Check if variable `X` is 0
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'and')
# i.e. 0 → 0
X20@ # Check if variable `X` is larger than or equal to 20 (for '-ty')
# i.e. 10 → 0 (falsey)
X12Q # Check if variable `X` is exactly 12
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'teen')
# i.e. 0 → 0
X11Q # Check if variable `X` is exactly 11 (for 'el-ev-en' minus 'one one')
# i.e. 10 → 0 (falsey)
O # Sum everything on the stack (and output implicitly)
# i.e. [2,1,0,3,0,0,0,0] → 6
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally hadI
(input) instead ofX
(input mod 100) when checking if it's larger than 20 for the +1 ofty
.
– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..>
(check if input is larger than 100) has been replaced with@
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..
– Kevin Cruijssen
1 hour ago
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
|
show 2 more comments
up vote
3
down vote
05AB1E, 34 bytes
т%UεĀy7Q>*}`Iт@3*X_(X20@X12Q(X11QO
Try it online or verify all [1,999]
test cases.
Explanation:
With all checks mentioned it will result in 1 for truthy and 0 for falsey.
т% # Take modulo-100 of the (implicit) input
# i.e. 710 → 10
U # Pop and store it in variable `X`
ε } # Map each digit of the (implicit) input to:
y7Q # Check if the digit is 7
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
> # Increase that result by 1
# i.e. 1 → 2
# i.e. 0 → 1
Ā # Trutify the digit (0 if 0; 1 otherwise)
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
* # And multiply them with each other
# i.e. 2 and 1 → 2
# i.e. 0 and 0 → 0
# i.e. [7,1,0] → [2,1,0]
` # And push all mapped digits to the stack
Iт@ # Check if the input is larger than or equal to 100
# i.e. 710 → 1 (truthy)
3* # Multiply that result by 3 (for 'hund-red and')
# i.e. 1 → 3
X_ # Check if variable `X` is 0
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'and')
# i.e. 0 → 0
X20@ # Check if variable `X` is larger than or equal to 20 (for '-ty')
# i.e. 10 → 0 (falsey)
X12Q # Check if variable `X` is exactly 12
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'teen')
# i.e. 0 → 0
X11Q # Check if variable `X` is exactly 11 (for 'el-ev-en' minus 'one one')
# i.e. 10 → 0 (falsey)
O # Sum everything on the stack (and output implicitly)
# i.e. [2,1,0,3,0,0,0,0] → 6
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally hadI
(input) instead ofX
(input mod 100) when checking if it's larger than 20 for the +1 ofty
.
– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..>
(check if input is larger than 100) has been replaced with@
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..
– Kevin Cruijssen
1 hour ago
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
|
show 2 more comments
up vote
3
down vote
up vote
3
down vote
05AB1E, 34 bytes
т%UεĀy7Q>*}`Iт@3*X_(X20@X12Q(X11QO
Try it online or verify all [1,999]
test cases.
Explanation:
With all checks mentioned it will result in 1 for truthy and 0 for falsey.
т% # Take modulo-100 of the (implicit) input
# i.e. 710 → 10
U # Pop and store it in variable `X`
ε } # Map each digit of the (implicit) input to:
y7Q # Check if the digit is 7
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
> # Increase that result by 1
# i.e. 1 → 2
# i.e. 0 → 1
Ā # Trutify the digit (0 if 0; 1 otherwise)
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
* # And multiply them with each other
# i.e. 2 and 1 → 2
# i.e. 0 and 0 → 0
# i.e. [7,1,0] → [2,1,0]
` # And push all mapped digits to the stack
Iт@ # Check if the input is larger than or equal to 100
# i.e. 710 → 1 (truthy)
3* # Multiply that result by 3 (for 'hund-red and')
# i.e. 1 → 3
X_ # Check if variable `X` is 0
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'and')
# i.e. 0 → 0
X20@ # Check if variable `X` is larger than or equal to 20 (for '-ty')
# i.e. 10 → 0 (falsey)
X12Q # Check if variable `X` is exactly 12
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'teen')
# i.e. 0 → 0
X11Q # Check if variable `X` is exactly 11 (for 'el-ev-en' minus 'one one')
# i.e. 10 → 0 (falsey)
O # Sum everything on the stack (and output implicitly)
# i.e. [2,1,0,3,0,0,0,0] → 6
05AB1E, 34 bytes
т%UεĀy7Q>*}`Iт@3*X_(X20@X12Q(X11QO
Try it online or verify all [1,999]
test cases.
Explanation:
With all checks mentioned it will result in 1 for truthy and 0 for falsey.
т% # Take modulo-100 of the (implicit) input
# i.e. 710 → 10
U # Pop and store it in variable `X`
ε } # Map each digit of the (implicit) input to:
y7Q # Check if the digit is 7
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
> # Increase that result by 1
# i.e. 1 → 2
# i.e. 0 → 1
Ā # Trutify the digit (0 if 0; 1 otherwise)
# i.e. 7 → 1 (truthy)
# i.e. 0 → 0 (falsey)
* # And multiply them with each other
# i.e. 2 and 1 → 2
# i.e. 0 and 0 → 0
# i.e. [7,1,0] → [2,1,0]
` # And push all mapped digits to the stack
Iт@ # Check if the input is larger than or equal to 100
# i.e. 710 → 1 (truthy)
3* # Multiply that result by 3 (for 'hund-red and')
# i.e. 1 → 3
X_ # Check if variable `X` is 0
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'and')
# i.e. 0 → 0
X20@ # Check if variable `X` is larger than or equal to 20 (for '-ty')
# i.e. 10 → 0 (falsey)
X12Q # Check if variable `X` is exactly 12
# i.e. 10 → 0 (falsey)
( # And negate that (to remove 'teen')
# i.e. 0 → 0
X11Q # Check if variable `X` is exactly 11 (for 'el-ev-en' minus 'one one')
# i.e. 10 → 0 (falsey)
O # Sum everything on the stack (and output implicitly)
# i.e. [2,1,0,3,0,0,0,0] → 6
edited 1 hour ago
answered 1 hour ago
Kevin Cruijssen
35.3k554186
35.3k554186
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally hadI
(input) instead ofX
(input mod 100) when checking if it's larger than 20 for the +1 ofty
.
– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..>
(check if input is larger than 100) has been replaced with@
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..
– Kevin Cruijssen
1 hour ago
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
|
show 2 more comments
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally hadI
(input) instead ofX
(input mod 100) when checking if it's larger than 20 for the +1 ofty
.
– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..>
(check if input is larger than 100) has been replaced with@
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..
– Kevin Cruijssen
1 hour ago
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
This fails the 700 test case. 'Seven Hundred' has 4 syllables, this returns 5.
– AJFaraday
1 hour ago
@AJFaraday Should be fixed now. Accidentally had
I
(input) instead of X
(input mod 100) when checking if it's larger than 20 for the +1 of ty
.– Kevin Cruijssen
1 hour ago
@AJFaraday Should be fixed now. Accidentally had
I
(input) instead of X
(input mod 100) when checking if it's larger than 20 for the +1 of ty
.– Kevin Cruijssen
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
I'm so sorry, it returns 0 for 'one hundred'
– AJFaraday
1 hour ago
@AJFaraday Fixed again..
>
(check if input is larger than 100) has been replaced with @
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..– Kevin Cruijssen
1 hour ago
@AJFaraday Fixed again..
>
(check if input is larger than 100) has been replaced with @
(check if input is larger than or equal to 100). Maybe I should have checked some more test cases myself more carefully before posting.. Sorry about that..– Kevin Cruijssen
1 hour ago
2
2
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
By the way, loving the top hat on a rubix cube!
– AJFaraday
1 hour ago
|
show 2 more comments
up vote
3
down vote
JavaScript (ES6), 90 bytes
n=>(s='01111112111312222322',n>99&&+s[n/100|0]+2+!!(n%=100))+~~(s[n]||+s[n/10&7]-~s[n%10])
Try it online!
add a comment |
up vote
3
down vote
JavaScript (ES6), 90 bytes
n=>(s='01111112111312222322',n>99&&+s[n/100|0]+2+!!(n%=100))+~~(s[n]||+s[n/10&7]-~s[n%10])
Try it online!
add a comment |
up vote
3
down vote
up vote
3
down vote
JavaScript (ES6), 90 bytes
n=>(s='01111112111312222322',n>99&&+s[n/100|0]+2+!!(n%=100))+~~(s[n]||+s[n/10&7]-~s[n%10])
Try it online!
JavaScript (ES6), 90 bytes
n=>(s='01111112111312222322',n>99&&+s[n/100|0]+2+!!(n%=100))+~~(s[n]||+s[n/10&7]-~s[n%10])
Try it online!
edited 1 hour ago
answered 1 hour ago
Arnauld
71.5k688299
71.5k688299
add a comment |
add a comment |
up vote
0
down vote
Jelly, 28 25 23 bytes
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ
Try it online!
How it works
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ Main link. Argument: n (integer in [1, ..., 999])
9 Set the return value to 9.
Ḋ Dequeue; yield [2, 3, 4, 5, 6, 7, 8, 9].
Ż Zero; yield [0, 2, 3, 4, 5, 6, 7, 8, 9].
;2 Concat 2, yield [0, 2, 3, 4, 5, 6, 7, 8, 9, 2].
+⁵ Add 10; yield [10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
Ż Zero; yield [0, 10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
%ȷ2$ Yield n % 1e2.
ċ Count the occurrences of the modulus in the array.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
Ṡ Take the sign of each decimal digit (0 or 1).
Ḅ Convert the array of signs from base 2 to integer.
ạ Compute the abs. difference of the results to both sides.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
ċ7 Count the number of 7's.
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
add a comment |
up vote
0
down vote
Jelly, 28 25 23 bytes
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ
Try it online!
How it works
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ Main link. Argument: n (integer in [1, ..., 999])
9 Set the return value to 9.
Ḋ Dequeue; yield [2, 3, 4, 5, 6, 7, 8, 9].
Ż Zero; yield [0, 2, 3, 4, 5, 6, 7, 8, 9].
;2 Concat 2, yield [0, 2, 3, 4, 5, 6, 7, 8, 9, 2].
+⁵ Add 10; yield [10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
Ż Zero; yield [0, 10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
%ȷ2$ Yield n % 1e2.
ċ Count the occurrences of the modulus in the array.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
Ṡ Take the sign of each decimal digit (0 or 1).
Ḅ Convert the array of signs from base 2 to integer.
ạ Compute the abs. difference of the results to both sides.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
ċ7 Count the number of 7's.
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Jelly, 28 25 23 bytes
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ
Try it online!
How it works
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ Main link. Argument: n (integer in [1, ..., 999])
9 Set the return value to 9.
Ḋ Dequeue; yield [2, 3, 4, 5, 6, 7, 8, 9].
Ż Zero; yield [0, 2, 3, 4, 5, 6, 7, 8, 9].
;2 Concat 2, yield [0, 2, 3, 4, 5, 6, 7, 8, 9, 2].
+⁵ Add 10; yield [10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
Ż Zero; yield [0, 10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
%ȷ2$ Yield n % 1e2.
ċ Count the occurrences of the modulus in the array.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
Ṡ Take the sign of each decimal digit (0 or 1).
Ḅ Convert the array of signs from base 2 to integer.
ạ Compute the abs. difference of the results to both sides.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
ċ7 Count the number of 7's.
Jelly, 28 25 23 bytes
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ
Try it online!
How it works
9ḊŻ;2+⁵Żċ%ȷ2$ạDṠḄƊ+Dċ7Ɗ Main link. Argument: n (integer in [1, ..., 999])
9 Set the return value to 9.
Ḋ Dequeue; yield [2, 3, 4, 5, 6, 7, 8, 9].
Ż Zero; yield [0, 2, 3, 4, 5, 6, 7, 8, 9].
;2 Concat 2, yield [0, 2, 3, 4, 5, 6, 7, 8, 9, 2].
+⁵ Add 10; yield [10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
Ż Zero; yield [0, 10, 12, 13, 14, 15, 16, 17, 18, 19, 12].
%ȷ2$ Yield n % 1e2.
ċ Count the occurrences of the modulus in the array.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
Ṡ Take the sign of each decimal digit (0 or 1).
Ḅ Convert the array of signs from base 2 to integer.
ạ Compute the abs. difference of the results to both sides.
Ɗ Combine the three links to the left into a monadic chain.
D Decimal; convert n to its array of digits in base 10.
ċ7 Count the number of 7's.
edited 4 mins ago
answered 41 mins ago
Dennis♦
185k32295734
185k32295734
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
add a comment |
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
I'm so sorry! 17 should have 3 syllables, you're showing up 2.
– AJFaraday
39 mins ago
1
1
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
Shoot, I tested against the output of another answer...
– Dennis♦
39 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
I think it's correct now. I actually special-cased 17 before.
– Dennis♦
37 mins ago
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).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f177586%2fhow-many-syllables-in-that-number%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
Can we take input as a string or an array of digits?
– Dennis♦
15 mins ago