Convert a string of digits from words to an integerTips for golfing in JellyConvert RegexesWords within words...
Is it ok if I haven't decided my research topic when I first meet with a potential phd advisor?
Why did the Soviet Union not "grant" Inner Mongolia to Mongolia after World War Two?
I reverse the source code, you reverse the input!
Neural Network vs regression
Algorithm that generates orthogonal vectors: C++ implementation
Do interval ratios take overtones into account or solely the fundamental frequency?
What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?
Is there a concept of "peer review" in Rabbinical Judaism?
What would influence an alien race to map their planet in a way other than the traditional map of the Earth
What does it mean by "my days-of-the-week underwear only go to Thursday" in this context?
Received a package but didn't order it
What should I consider when deciding whether to delay an exam?
Designing a time thief proof safe
Do wheelchair-accessible aircraft exist?
If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to the Sun?
Youtube not blocked by iptables
New road bike: alloy dual pivot brakes work poorly
Align all symbols in a LaTeX equation
What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?
Medic abilities
Practicality of 30 year fixed mortgage at 55 years of age
Can my former employer sue me if I don't give them the photos I took (taking pictures was not part of my job description)?
Why does (inf + 0j)*1 evaluate to inf + nanj?
"until mine is on tight" is a idiom?
Convert a string of digits from words to an integer
Tips for golfing in JellyConvert RegexesWords within words within words within words . . .Stripping off extra spaces from a stringCount the crossing wordsWho's gonna win the football game?Actually Integer MetagolfHiccup a stringTelephone number in spoken wordsFix my stuttered words
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Convert a string containing digits as words into an integer, ignoring leading zeros.
Examples
"four two"
->42
.
"zero zero zero one"
->1
.
Assumptions
Submissions can assume that:
- The input string is comprised of space-separated digit words.
- All words are valid (in the range "zero".."nine") and lowercase. Behaviour for empty input is undefined.
- The input string always represents an unsigned number within the range of
int
and is never an empty string.
Scoring
Answers will be scored in bytes with fewer bytes being better.
code-golf string number conversion
New contributor
$endgroup$
|
show 3 more comments
$begingroup$
Convert a string containing digits as words into an integer, ignoring leading zeros.
Examples
"four two"
->42
.
"zero zero zero one"
->1
.
Assumptions
Submissions can assume that:
- The input string is comprised of space-separated digit words.
- All words are valid (in the range "zero".."nine") and lowercase. Behaviour for empty input is undefined.
- The input string always represents an unsigned number within the range of
int
and is never an empty string.
Scoring
Answers will be scored in bytes with fewer bytes being better.
code-golf string number conversion
New contributor
$endgroup$
2
$begingroup$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
1
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
At the risk of being pedantic, I'd like to point out that therange "zero".."nine"
is not fully specified.
$endgroup$
– Unrelated String
8 hours ago
|
show 3 more comments
$begingroup$
Convert a string containing digits as words into an integer, ignoring leading zeros.
Examples
"four two"
->42
.
"zero zero zero one"
->1
.
Assumptions
Submissions can assume that:
- The input string is comprised of space-separated digit words.
- All words are valid (in the range "zero".."nine") and lowercase. Behaviour for empty input is undefined.
- The input string always represents an unsigned number within the range of
int
and is never an empty string.
Scoring
Answers will be scored in bytes with fewer bytes being better.
code-golf string number conversion
New contributor
$endgroup$
Convert a string containing digits as words into an integer, ignoring leading zeros.
Examples
"four two"
->42
.
"zero zero zero one"
->1
.
Assumptions
Submissions can assume that:
- The input string is comprised of space-separated digit words.
- All words are valid (in the range "zero".."nine") and lowercase. Behaviour for empty input is undefined.
- The input string always represents an unsigned number within the range of
int
and is never an empty string.
Scoring
Answers will be scored in bytes with fewer bytes being better.
code-golf string number conversion
code-golf string number conversion
New contributor
New contributor
edited 8 hours ago
NemPlayer
1032 bronze badges
1032 bronze badges
New contributor
asked 8 hours ago
SparklerSparkler
1214 bronze badges
1214 bronze badges
New contributor
New contributor
2
$begingroup$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
1
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
At the risk of being pedantic, I'd like to point out that therange "zero".."nine"
is not fully specified.
$endgroup$
– Unrelated String
8 hours ago
|
show 3 more comments
2
$begingroup$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
1
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
At the risk of being pedantic, I'd like to point out that therange "zero".."nine"
is not fully specified.
$endgroup$
– Unrelated String
8 hours ago
2
2
$begingroup$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
2
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
2
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
1
1
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
2
$begingroup$
At the risk of being pedantic, I'd like to point out that the
range "zero".."nine"
is not fully specified.$endgroup$
– Unrelated String
8 hours ago
$begingroup$
At the risk of being pedantic, I'd like to point out that the
range "zero".."nine"
is not fully specified.$endgroup$
– Unrelated String
8 hours ago
|
show 3 more comments
12 Answers
12
active
oldest
votes
$begingroup$
Jelly, 19 17 bytes
Ḳµ7ị“*;nÄƲ]³Ṙ»i)Ḍ
A monadic Link accepting a list of characters which yields an integer.
Try it online!
Pretty much a port of my Python 2 answer.
Previous
ḲŒ¿€i@€“©¥q£½¤MÆÑ‘Ḍ
Try it online!
There is quite possibly a shorter way, but this is a way that first came to mind.
$endgroup$
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Python 3, 107, 91, 77, 90 bytes
-16 bytes by Sriotchilism O'Zaic
+13 bytes to remove leading zeroes
lambda s:int(''.join(map(lambda w:str('zeontwthfofisiseeini'.index(w[:2])//2),s.split())))
Try it online!
$endgroup$
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
$begingroup$
@movatica Your fix is incorrect. Thelstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.
$endgroup$
– NemPlayer
8 hours ago
|
show 3 more comments
$begingroup$
Retina 0.8.2, 46 bytes
T`zwuxg`E
on
1
th
3
fi
5
se
7
ni
9
D
^0+B
Try it online! Link includes test cases. Explanation:
T`zwuxg`E
The words zero
, two
, four
, six
and eight
uniquely contain the letters zwuxg
. Transliterate those to the even digits.
on
1
th
3
fi
5
se
7
ni
9
For the odd digits, just match the first two letters of each word individually.
D
Delete all remaining non-digit characters.
^0+B
Delete leading zeros (but leave at least one digit).
$endgroup$
add a comment
|
$begingroup$
Python 2, 71 70 bytes
-1 thanks to ovs (use find
in place of index
)
lambda s:int(''.join(`'rothuvsein'.find((w*3)[6])`for w in s.split()))
Try it online!
$endgroup$
add a comment
|
$begingroup$
JavaScript (ES6), 65 bytes
A port of Jonathan Allan's answer is 2 bytes shorter.
s=>s.split` `.map(s=>t+=['rothuvsein'.indexOf((s+s+s)[6])],t=0)|t
Try it online!
JavaScript (ES6), 70 67 bytes
Saved 3 bytes thanks to @ovs
s=>s.split` `.map(s=>o+='2839016547'[parseInt(s,36)%204%13],o='')|o
Try it online!
$endgroup$
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.
$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Perl 6, 35 32 bytes
{+uniparse 'SP'~S:g/<</,DIGIT /}
Try it online!
Explanation
{ } # Anonymous block
S:g/<</,DIGIT / # Insert ",DIGIT " at
# left word boundaries
'SP'~ # Prepend 'SP' for space
uniparse # Parse list of Unicode names into string
+ # Convert to integer
$endgroup$
add a comment
|
$begingroup$
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.='793251_8640'[crc32($w)%20%11];echo+$n;
Try it online!
Tried to get a solution which doesn't copy existing answers. I get cyclic redundancy checksum polynomial of 32-bit lengths (crc32) for each word and then do a mod 20 and mod 11 on it to get mixed up unique values from 0 to 10 (missing 6) for each digit. Then using that unique value I find the actual digit.
| Word | CRC32 | %20 | %11 | Equivalent digit |
|-------|------------|-----|-----|------------------|
| zero | 2883514770 | 10 | 10 | 0 |
| one | 2053932785 | 5 | 5 | 1 |
| two | 298486374 | 14 | 3 | 2 |
| three | 1187371253 | 13 | 2 | 3 |
| four | 2428593789 | 9 | 9 | 4 |
| five | 1018350795 | 15 | 4 | 5 |
| six | 1125590779 | 19 | 8 | 6 |
| seven | 2522131820 | 0 | 0 | 7 |
| eight | 1711947398 | 18 | 7 | 8 |
| nine | 2065529981 | 1 | 1 | 9 |
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.=strpos(d07bfe386c,md5($w)[21]);echo+$n;
Try it online!
Another alternative with same length, takes 22nd character in the md5
of the word (only character which gives a unique value for each word) and then uses that character to map to a digit.
$endgroup$
add a comment
|
$begingroup$
Jelly, 20 18 17 bytes
Ḳ7ị“*;nÄƲ]³Ṙ»iƲ€Ḍ
Try it online!
-2 bytes from running "rothuvsein" through user202729's string compressor.
-1 byte from stealing Jonathan Allan's zero-free enklact string, and putting it in a marginally differently structured program.
Ḳ Split the input on spaces,
Ʋ€ for each word
i find the 1-based index (defaulting to 0)
“*;nÄƲ]³Ṙ» in "othuvsein"
7ị of the element at modular index 7,
Ḍ and convert from decimal digits to integer.
$endgroup$
add a comment
|
$begingroup$
Clean, 88 bytes
import StdEnv,Text
$s=toInt{#i\n<-split" "s,c<-:"rothuvsein"&i<-['0'..]|c==(n+n+n).[6]}
Try it online!
Heavily based on Jonathan Allan's answer.
Uses a comprehension for indexing instead of indexOf
/ elemIndex
.
$endgroup$
add a comment
|
$begingroup$
Perl 6, 45 bytes
+*.words>>.&{+(1...*.uniname.comb(.uc))}.chrs
Try it online!
$endgroup$
add a comment
|
$begingroup$
C++ (gcc), 478 218 142 bytes
-(a lot) thanks to Jo King
int f(string s){char c[]="N02K8>IE;6";int i=0,n=0;while(s[i]){n=n*10-1;while((s[i]^s[i+1])+47!=c[++n%10]);while(s[i++]!=' '&&s[i]);}return n;}
Try it online!
New contributor
$endgroup$
add a comment
|
$begingroup$
J, 38 bytes
('be~mjPxw['i.[:u:70+1#.15|3&u:)&>@;:
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/4.0/"u003ecc by-sa 4.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
});
}
});
Sparkler 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%2f193357%2fconvert-a-string-of-digits-from-words-to-an-integer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Jelly, 19 17 bytes
Ḳµ7ị“*;nÄƲ]³Ṙ»i)Ḍ
A monadic Link accepting a list of characters which yields an integer.
Try it online!
Pretty much a port of my Python 2 answer.
Previous
ḲŒ¿€i@€“©¥q£½¤MÆÑ‘Ḍ
Try it online!
There is quite possibly a shorter way, but this is a way that first came to mind.
$endgroup$
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Jelly, 19 17 bytes
Ḳµ7ị“*;nÄƲ]³Ṙ»i)Ḍ
A monadic Link accepting a list of characters which yields an integer.
Try it online!
Pretty much a port of my Python 2 answer.
Previous
ḲŒ¿€i@€“©¥q£½¤MÆÑ‘Ḍ
Try it online!
There is quite possibly a shorter way, but this is a way that first came to mind.
$endgroup$
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Jelly, 19 17 bytes
Ḳµ7ị“*;nÄƲ]³Ṙ»i)Ḍ
A monadic Link accepting a list of characters which yields an integer.
Try it online!
Pretty much a port of my Python 2 answer.
Previous
ḲŒ¿€i@€“©¥q£½¤MÆÑ‘Ḍ
Try it online!
There is quite possibly a shorter way, but this is a way that first came to mind.
$endgroup$
Jelly, 19 17 bytes
Ḳµ7ị“*;nÄƲ]³Ṙ»i)Ḍ
A monadic Link accepting a list of characters which yields an integer.
Try it online!
Pretty much a port of my Python 2 answer.
Previous
ḲŒ¿€i@€“©¥q£½¤MÆÑ‘Ḍ
Try it online!
There is quite possibly a shorter way, but this is a way that first came to mind.
edited 8 hours ago
answered 8 hours ago
Jonathan AllanJonathan Allan
60.6k5 gold badges44 silver badges188 bronze badges
60.6k5 gold badges44 silver badges188 bronze badges
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
$begingroup$
Removing zero from the enklact string to avoid decrementing, because not found is zero anyhow... clever!
$endgroup$
– Unrelated String
7 hours ago
1
1
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Ah I see you did the same method, nice.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Python 3, 107, 91, 77, 90 bytes
-16 bytes by Sriotchilism O'Zaic
+13 bytes to remove leading zeroes
lambda s:int(''.join(map(lambda w:str('zeontwthfofisiseeini'.index(w[:2])//2),s.split())))
Try it online!
$endgroup$
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
$begingroup$
@movatica Your fix is incorrect. Thelstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.
$endgroup$
– NemPlayer
8 hours ago
|
show 3 more comments
$begingroup$
Python 3, 107, 91, 77, 90 bytes
-16 bytes by Sriotchilism O'Zaic
+13 bytes to remove leading zeroes
lambda s:int(''.join(map(lambda w:str('zeontwthfofisiseeini'.index(w[:2])//2),s.split())))
Try it online!
$endgroup$
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
$begingroup$
@movatica Your fix is incorrect. Thelstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.
$endgroup$
– NemPlayer
8 hours ago
|
show 3 more comments
$begingroup$
Python 3, 107, 91, 77, 90 bytes
-16 bytes by Sriotchilism O'Zaic
+13 bytes to remove leading zeroes
lambda s:int(''.join(map(lambda w:str('zeontwthfofisiseeini'.index(w[:2])//2),s.split())))
Try it online!
$endgroup$
Python 3, 107, 91, 77, 90 bytes
-16 bytes by Sriotchilism O'Zaic
+13 bytes to remove leading zeroes
lambda s:int(''.join(map(lambda w:str('zeontwthfofisiseeini'.index(w[:2])//2),s.split())))
Try it online!
edited 8 hours ago
answered 8 hours ago
movaticamovatica
6056 bronze badges
6056 bronze badges
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
$begingroup$
@movatica Your fix is incorrect. Thelstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.
$endgroup$
– NemPlayer
8 hours ago
|
show 3 more comments
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
$begingroup$
@movatica Your fix is incorrect. Thelstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.
$endgroup$
– NemPlayer
8 hours ago
5
5
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
It's shorter if you just use the first two characters
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
$begingroup$
Nice one! That way, I can even drop the delimiter completely :)
$endgroup$
– movatica
8 hours ago
1
1
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
With the updates to the challenge this is no longer valid since it includes leading zeros. :(
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
2
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
$begingroup$
Here is a slightly better fix
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
1
1
$begingroup$
@movatica Your fix is incorrect. The
lstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.$endgroup$
– NemPlayer
8 hours ago
$begingroup$
@movatica Your fix is incorrect. The
lstrip
method strips every character in the string which is given as it's argument, so "eight two" becomes "ight two", as "e" gets stripped. Also, "zero zero zero" should print out "0", not give out an error.$endgroup$
– NemPlayer
8 hours ago
|
show 3 more comments
$begingroup$
Retina 0.8.2, 46 bytes
T`zwuxg`E
on
1
th
3
fi
5
se
7
ni
9
D
^0+B
Try it online! Link includes test cases. Explanation:
T`zwuxg`E
The words zero
, two
, four
, six
and eight
uniquely contain the letters zwuxg
. Transliterate those to the even digits.
on
1
th
3
fi
5
se
7
ni
9
For the odd digits, just match the first two letters of each word individually.
D
Delete all remaining non-digit characters.
^0+B
Delete leading zeros (but leave at least one digit).
$endgroup$
add a comment
|
$begingroup$
Retina 0.8.2, 46 bytes
T`zwuxg`E
on
1
th
3
fi
5
se
7
ni
9
D
^0+B
Try it online! Link includes test cases. Explanation:
T`zwuxg`E
The words zero
, two
, four
, six
and eight
uniquely contain the letters zwuxg
. Transliterate those to the even digits.
on
1
th
3
fi
5
se
7
ni
9
For the odd digits, just match the first two letters of each word individually.
D
Delete all remaining non-digit characters.
^0+B
Delete leading zeros (but leave at least one digit).
$endgroup$
add a comment
|
$begingroup$
Retina 0.8.2, 46 bytes
T`zwuxg`E
on
1
th
3
fi
5
se
7
ni
9
D
^0+B
Try it online! Link includes test cases. Explanation:
T`zwuxg`E
The words zero
, two
, four
, six
and eight
uniquely contain the letters zwuxg
. Transliterate those to the even digits.
on
1
th
3
fi
5
se
7
ni
9
For the odd digits, just match the first two letters of each word individually.
D
Delete all remaining non-digit characters.
^0+B
Delete leading zeros (but leave at least one digit).
$endgroup$
Retina 0.8.2, 46 bytes
T`zwuxg`E
on
1
th
3
fi
5
se
7
ni
9
D
^0+B
Try it online! Link includes test cases. Explanation:
T`zwuxg`E
The words zero
, two
, four
, six
and eight
uniquely contain the letters zwuxg
. Transliterate those to the even digits.
on
1
th
3
fi
5
se
7
ni
9
For the odd digits, just match the first two letters of each word individually.
D
Delete all remaining non-digit characters.
^0+B
Delete leading zeros (but leave at least one digit).
answered 8 hours ago
NeilNeil
89.2k8 gold badges46 silver badges188 bronze badges
89.2k8 gold badges46 silver badges188 bronze badges
add a comment
|
add a comment
|
$begingroup$
Python 2, 71 70 bytes
-1 thanks to ovs (use find
in place of index
)
lambda s:int(''.join(`'rothuvsein'.find((w*3)[6])`for w in s.split()))
Try it online!
$endgroup$
add a comment
|
$begingroup$
Python 2, 71 70 bytes
-1 thanks to ovs (use find
in place of index
)
lambda s:int(''.join(`'rothuvsein'.find((w*3)[6])`for w in s.split()))
Try it online!
$endgroup$
add a comment
|
$begingroup$
Python 2, 71 70 bytes
-1 thanks to ovs (use find
in place of index
)
lambda s:int(''.join(`'rothuvsein'.find((w*3)[6])`for w in s.split()))
Try it online!
$endgroup$
Python 2, 71 70 bytes
-1 thanks to ovs (use find
in place of index
)
lambda s:int(''.join(`'rothuvsein'.find((w*3)[6])`for w in s.split()))
Try it online!
edited 7 hours ago
answered 8 hours ago
Jonathan AllanJonathan Allan
60.6k5 gold badges44 silver badges188 bronze badges
60.6k5 gold badges44 silver badges188 bronze badges
add a comment
|
add a comment
|
$begingroup$
JavaScript (ES6), 65 bytes
A port of Jonathan Allan's answer is 2 bytes shorter.
s=>s.split` `.map(s=>t+=['rothuvsein'.indexOf((s+s+s)[6])],t=0)|t
Try it online!
JavaScript (ES6), 70 67 bytes
Saved 3 bytes thanks to @ovs
s=>s.split` `.map(s=>o+='2839016547'[parseInt(s,36)%204%13],o='')|o
Try it online!
$endgroup$
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.
$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
JavaScript (ES6), 65 bytes
A port of Jonathan Allan's answer is 2 bytes shorter.
s=>s.split` `.map(s=>t+=['rothuvsein'.indexOf((s+s+s)[6])],t=0)|t
Try it online!
JavaScript (ES6), 70 67 bytes
Saved 3 bytes thanks to @ovs
s=>s.split` `.map(s=>o+='2839016547'[parseInt(s,36)%204%13],o='')|o
Try it online!
$endgroup$
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.
$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
JavaScript (ES6), 65 bytes
A port of Jonathan Allan's answer is 2 bytes shorter.
s=>s.split` `.map(s=>t+=['rothuvsein'.indexOf((s+s+s)[6])],t=0)|t
Try it online!
JavaScript (ES6), 70 67 bytes
Saved 3 bytes thanks to @ovs
s=>s.split` `.map(s=>o+='2839016547'[parseInt(s,36)%204%13],o='')|o
Try it online!
$endgroup$
JavaScript (ES6), 65 bytes
A port of Jonathan Allan's answer is 2 bytes shorter.
s=>s.split` `.map(s=>t+=['rothuvsein'.indexOf((s+s+s)[6])],t=0)|t
Try it online!
JavaScript (ES6), 70 67 bytes
Saved 3 bytes thanks to @ovs
s=>s.split` `.map(s=>o+='2839016547'[parseInt(s,36)%204%13],o='')|o
Try it online!
edited 7 hours ago
answered 8 hours ago
ArnauldArnauld
93.1k7 gold badges110 silver badges379 bronze badges
93.1k7 gold badges110 silver badges379 bronze badges
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.
$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.
$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.$endgroup$
– ovs
7 hours ago
$begingroup$
'2839016547'[parseInt(s,36)%204%13]
is 3 bytes shorter.$endgroup$
– ovs
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
FWIW Unrelated String managed to post the method first.
$endgroup$
– Jonathan Allan
7 hours ago
add a comment
|
$begingroup$
Perl 6, 35 32 bytes
{+uniparse 'SP'~S:g/<</,DIGIT /}
Try it online!
Explanation
{ } # Anonymous block
S:g/<</,DIGIT / # Insert ",DIGIT " at
# left word boundaries
'SP'~ # Prepend 'SP' for space
uniparse # Parse list of Unicode names into string
+ # Convert to integer
$endgroup$
add a comment
|
$begingroup$
Perl 6, 35 32 bytes
{+uniparse 'SP'~S:g/<</,DIGIT /}
Try it online!
Explanation
{ } # Anonymous block
S:g/<</,DIGIT / # Insert ",DIGIT " at
# left word boundaries
'SP'~ # Prepend 'SP' for space
uniparse # Parse list of Unicode names into string
+ # Convert to integer
$endgroup$
add a comment
|
$begingroup$
Perl 6, 35 32 bytes
{+uniparse 'SP'~S:g/<</,DIGIT /}
Try it online!
Explanation
{ } # Anonymous block
S:g/<</,DIGIT / # Insert ",DIGIT " at
# left word boundaries
'SP'~ # Prepend 'SP' for space
uniparse # Parse list of Unicode names into string
+ # Convert to integer
$endgroup$
Perl 6, 35 32 bytes
{+uniparse 'SP'~S:g/<</,DIGIT /}
Try it online!
Explanation
{ } # Anonymous block
S:g/<</,DIGIT / # Insert ",DIGIT " at
# left word boundaries
'SP'~ # Prepend 'SP' for space
uniparse # Parse list of Unicode names into string
+ # Convert to integer
edited 5 hours ago
answered 6 hours ago
nwellnhofnwellnhof
8,4001 gold badge12 silver badges30 bronze badges
8,4001 gold badge12 silver badges30 bronze badges
add a comment
|
add a comment
|
$begingroup$
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.='793251_8640'[crc32($w)%20%11];echo+$n;
Try it online!
Tried to get a solution which doesn't copy existing answers. I get cyclic redundancy checksum polynomial of 32-bit lengths (crc32) for each word and then do a mod 20 and mod 11 on it to get mixed up unique values from 0 to 10 (missing 6) for each digit. Then using that unique value I find the actual digit.
| Word | CRC32 | %20 | %11 | Equivalent digit |
|-------|------------|-----|-----|------------------|
| zero | 2883514770 | 10 | 10 | 0 |
| one | 2053932785 | 5 | 5 | 1 |
| two | 298486374 | 14 | 3 | 2 |
| three | 1187371253 | 13 | 2 | 3 |
| four | 2428593789 | 9 | 9 | 4 |
| five | 1018350795 | 15 | 4 | 5 |
| six | 1125590779 | 19 | 8 | 6 |
| seven | 2522131820 | 0 | 0 | 7 |
| eight | 1711947398 | 18 | 7 | 8 |
| nine | 2065529981 | 1 | 1 | 9 |
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.=strpos(d07bfe386c,md5($w)[21]);echo+$n;
Try it online!
Another alternative with same length, takes 22nd character in the md5
of the word (only character which gives a unique value for each word) and then uses that character to map to a digit.
$endgroup$
add a comment
|
$begingroup$
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.='793251_8640'[crc32($w)%20%11];echo+$n;
Try it online!
Tried to get a solution which doesn't copy existing answers. I get cyclic redundancy checksum polynomial of 32-bit lengths (crc32) for each word and then do a mod 20 and mod 11 on it to get mixed up unique values from 0 to 10 (missing 6) for each digit. Then using that unique value I find the actual digit.
| Word | CRC32 | %20 | %11 | Equivalent digit |
|-------|------------|-----|-----|------------------|
| zero | 2883514770 | 10 | 10 | 0 |
| one | 2053932785 | 5 | 5 | 1 |
| two | 298486374 | 14 | 3 | 2 |
| three | 1187371253 | 13 | 2 | 3 |
| four | 2428593789 | 9 | 9 | 4 |
| five | 1018350795 | 15 | 4 | 5 |
| six | 1125590779 | 19 | 8 | 6 |
| seven | 2522131820 | 0 | 0 | 7 |
| eight | 1711947398 | 18 | 7 | 8 |
| nine | 2065529981 | 1 | 1 | 9 |
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.=strpos(d07bfe386c,md5($w)[21]);echo+$n;
Try it online!
Another alternative with same length, takes 22nd character in the md5
of the word (only character which gives a unique value for each word) and then uses that character to map to a digit.
$endgroup$
add a comment
|
$begingroup$
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.='793251_8640'[crc32($w)%20%11];echo+$n;
Try it online!
Tried to get a solution which doesn't copy existing answers. I get cyclic redundancy checksum polynomial of 32-bit lengths (crc32) for each word and then do a mod 20 and mod 11 on it to get mixed up unique values from 0 to 10 (missing 6) for each digit. Then using that unique value I find the actual digit.
| Word | CRC32 | %20 | %11 | Equivalent digit |
|-------|------------|-----|-----|------------------|
| zero | 2883514770 | 10 | 10 | 0 |
| one | 2053932785 | 5 | 5 | 1 |
| two | 298486374 | 14 | 3 | 2 |
| three | 1187371253 | 13 | 2 | 3 |
| four | 2428593789 | 9 | 9 | 4 |
| five | 1018350795 | 15 | 4 | 5 |
| six | 1125590779 | 19 | 8 | 6 |
| seven | 2522131820 | 0 | 0 | 7 |
| eight | 1711947398 | 18 | 7 | 8 |
| nine | 2065529981 | 1 | 1 | 9 |
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.=strpos(d07bfe386c,md5($w)[21]);echo+$n;
Try it online!
Another alternative with same length, takes 22nd character in the md5
of the word (only character which gives a unique value for each word) and then uses that character to map to a digit.
$endgroup$
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.='793251_8640'[crc32($w)%20%11];echo+$n;
Try it online!
Tried to get a solution which doesn't copy existing answers. I get cyclic redundancy checksum polynomial of 32-bit lengths (crc32) for each word and then do a mod 20 and mod 11 on it to get mixed up unique values from 0 to 10 (missing 6) for each digit. Then using that unique value I find the actual digit.
| Word | CRC32 | %20 | %11 | Equivalent digit |
|-------|------------|-----|-----|------------------|
| zero | 2883514770 | 10 | 10 | 0 |
| one | 2053932785 | 5 | 5 | 1 |
| two | 298486374 | 14 | 3 | 2 |
| three | 1187371253 | 13 | 2 | 3 |
| four | 2428593789 | 9 | 9 | 4 |
| five | 1018350795 | 15 | 4 | 5 |
| six | 1125590779 | 19 | 8 | 6 |
| seven | 2522131820 | 0 | 0 | 7 |
| eight | 1711947398 | 18 | 7 | 8 |
| nine | 2065529981 | 1 | 1 | 9 |
PHP, 74 bytes
foreach(explode(' ',$argn)as$w)$n.=strpos(d07bfe386c,md5($w)[21]);echo+$n;
Try it online!
Another alternative with same length, takes 22nd character in the md5
of the word (only character which gives a unique value for each word) and then uses that character to map to a digit.
edited 2 hours ago
answered 2 hours ago
Night2Night2
3,0643 silver badges21 bronze badges
3,0643 silver badges21 bronze badges
add a comment
|
add a comment
|
$begingroup$
Jelly, 20 18 17 bytes
Ḳ7ị“*;nÄƲ]³Ṙ»iƲ€Ḍ
Try it online!
-2 bytes from running "rothuvsein" through user202729's string compressor.
-1 byte from stealing Jonathan Allan's zero-free enklact string, and putting it in a marginally differently structured program.
Ḳ Split the input on spaces,
Ʋ€ for each word
i find the 1-based index (defaulting to 0)
“*;nÄƲ]³Ṙ» in "othuvsein"
7ị of the element at modular index 7,
Ḍ and convert from decimal digits to integer.
$endgroup$
add a comment
|
$begingroup$
Jelly, 20 18 17 bytes
Ḳ7ị“*;nÄƲ]³Ṙ»iƲ€Ḍ
Try it online!
-2 bytes from running "rothuvsein" through user202729's string compressor.
-1 byte from stealing Jonathan Allan's zero-free enklact string, and putting it in a marginally differently structured program.
Ḳ Split the input on spaces,
Ʋ€ for each word
i find the 1-based index (defaulting to 0)
“*;nÄƲ]³Ṙ» in "othuvsein"
7ị of the element at modular index 7,
Ḍ and convert from decimal digits to integer.
$endgroup$
add a comment
|
$begingroup$
Jelly, 20 18 17 bytes
Ḳ7ị“*;nÄƲ]³Ṙ»iƲ€Ḍ
Try it online!
-2 bytes from running "rothuvsein" through user202729's string compressor.
-1 byte from stealing Jonathan Allan's zero-free enklact string, and putting it in a marginally differently structured program.
Ḳ Split the input on spaces,
Ʋ€ for each word
i find the 1-based index (defaulting to 0)
“*;nÄƲ]³Ṙ» in "othuvsein"
7ị of the element at modular index 7,
Ḍ and convert from decimal digits to integer.
$endgroup$
Jelly, 20 18 17 bytes
Ḳ7ị“*;nÄƲ]³Ṙ»iƲ€Ḍ
Try it online!
-2 bytes from running "rothuvsein" through user202729's string compressor.
-1 byte from stealing Jonathan Allan's zero-free enklact string, and putting it in a marginally differently structured program.
Ḳ Split the input on spaces,
Ʋ€ for each word
i find the 1-based index (defaulting to 0)
“*;nÄƲ]³Ṙ» in "othuvsein"
7ị of the element at modular index 7,
Ḍ and convert from decimal digits to integer.
edited 7 hours ago
answered 8 hours ago
Unrelated StringUnrelated String
3,7872 gold badges3 silver badges21 bronze badges
3,7872 gold badges3 silver badges21 bronze badges
add a comment
|
add a comment
|
$begingroup$
Clean, 88 bytes
import StdEnv,Text
$s=toInt{#i\n<-split" "s,c<-:"rothuvsein"&i<-['0'..]|c==(n+n+n).[6]}
Try it online!
Heavily based on Jonathan Allan's answer.
Uses a comprehension for indexing instead of indexOf
/ elemIndex
.
$endgroup$
add a comment
|
$begingroup$
Clean, 88 bytes
import StdEnv,Text
$s=toInt{#i\n<-split" "s,c<-:"rothuvsein"&i<-['0'..]|c==(n+n+n).[6]}
Try it online!
Heavily based on Jonathan Allan's answer.
Uses a comprehension for indexing instead of indexOf
/ elemIndex
.
$endgroup$
add a comment
|
$begingroup$
Clean, 88 bytes
import StdEnv,Text
$s=toInt{#i\n<-split" "s,c<-:"rothuvsein"&i<-['0'..]|c==(n+n+n).[6]}
Try it online!
Heavily based on Jonathan Allan's answer.
Uses a comprehension for indexing instead of indexOf
/ elemIndex
.
$endgroup$
Clean, 88 bytes
import StdEnv,Text
$s=toInt{#i\n<-split" "s,c<-:"rothuvsein"&i<-['0'..]|c==(n+n+n).[6]}
Try it online!
Heavily based on Jonathan Allan's answer.
Uses a comprehension for indexing instead of indexOf
/ elemIndex
.
answered 6 hours ago
ΟurousΟurous
7,5961 gold badge11 silver badges36 bronze badges
7,5961 gold badge11 silver badges36 bronze badges
add a comment
|
add a comment
|
$begingroup$
Perl 6, 45 bytes
+*.words>>.&{+(1...*.uniname.comb(.uc))}.chrs
Try it online!
$endgroup$
add a comment
|
$begingroup$
Perl 6, 45 bytes
+*.words>>.&{+(1...*.uniname.comb(.uc))}.chrs
Try it online!
$endgroup$
add a comment
|
$begingroup$
Perl 6, 45 bytes
+*.words>>.&{+(1...*.uniname.comb(.uc))}.chrs
Try it online!
$endgroup$
Perl 6, 45 bytes
+*.words>>.&{+(1...*.uniname.comb(.uc))}.chrs
Try it online!
answered 8 hours ago
Jo KingJo King
31.6k4 gold badges73 silver badges141 bronze badges
31.6k4 gold badges73 silver badges141 bronze badges
add a comment
|
add a comment
|
$begingroup$
C++ (gcc), 478 218 142 bytes
-(a lot) thanks to Jo King
int f(string s){char c[]="N02K8>IE;6";int i=0,n=0;while(s[i]){n=n*10-1;while((s[i]^s[i+1])+47!=c[++n%10]);while(s[i++]!=' '&&s[i]);}return n;}
Try it online!
New contributor
$endgroup$
add a comment
|
$begingroup$
C++ (gcc), 478 218 142 bytes
-(a lot) thanks to Jo King
int f(string s){char c[]="N02K8>IE;6";int i=0,n=0;while(s[i]){n=n*10-1;while((s[i]^s[i+1])+47!=c[++n%10]);while(s[i++]!=' '&&s[i]);}return n;}
Try it online!
New contributor
$endgroup$
add a comment
|
$begingroup$
C++ (gcc), 478 218 142 bytes
-(a lot) thanks to Jo King
int f(string s){char c[]="N02K8>IE;6";int i=0,n=0;while(s[i]){n=n*10-1;while((s[i]^s[i+1])+47!=c[++n%10]);while(s[i++]!=' '&&s[i]);}return n;}
Try it online!
New contributor
$endgroup$
C++ (gcc), 478 218 142 bytes
-(a lot) thanks to Jo King
int f(string s){char c[]="N02K8>IE;6";int i=0,n=0;while(s[i]){n=n*10-1;while((s[i]^s[i+1])+47!=c[++n%10]);while(s[i++]!=' '&&s[i]);}return n;}
Try it online!
New contributor
edited 3 hours ago
New contributor
answered 8 hours ago
SparklerSparkler
1214 bronze badges
1214 bronze badges
New contributor
New contributor
add a comment
|
add a comment
|
$begingroup$
J, 38 bytes
('be~mjPxw['i.[:u:70+1#.15|3&u:)&>@;:
Try it online!
$endgroup$
add a comment
|
$begingroup$
J, 38 bytes
('be~mjPxw['i.[:u:70+1#.15|3&u:)&>@;:
Try it online!
$endgroup$
add a comment
|
$begingroup$
J, 38 bytes
('be~mjPxw['i.[:u:70+1#.15|3&u:)&>@;:
Try it online!
$endgroup$
J, 38 bytes
('be~mjPxw['i.[:u:70+1#.15|3&u:)&>@;:
Try it online!
answered 1 hour ago
JonahJonah
5,0672 gold badges13 silver badges23 bronze badges
5,0672 gold badges13 silver badges23 bronze badges
add a comment
|
add a comment
|
Sparkler is a new contributor. Be nice, and check out our Code of Conduct.
Sparkler is a new contributor. Be nice, and check out our Code of Conduct.
Sparkler is a new contributor. Be nice, and check out our Code of Conduct.
Sparkler 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%2f193357%2fconvert-a-string-of-digits-from-words-to-an-integer%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$
Welcome to the site. There are a couple of things that we usually expect from questions that are missing here. The most important would be an objective scoring criterion which all challenges must have.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
Aside from that this question is very sparse on specification. You should specify exactly what is required of submissions without ambiguity. One sentence and an example just isn't up to our clarity standards for challenges.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
On top of what has been said already, we have a sandbox where users can post their challenges before posting them to main. That way you will miss less information when making posts. If you look at other recent posts on the site with a reasonably positive reception I think you will see that both your question and solution aren't quite in line with what we do here.
$endgroup$
– FryAmTheEggman
8 hours ago
1
$begingroup$
To handle the scoring criterion it would be the absolute minimum. You really should put a sentence in the body of the question though. E.g. "Answers will be scored in bytes with fewer bytes being better". There is technically more than one way to score code-golf, but bytes is overwhelmingly the most popular.
$endgroup$
– Sriotchilism O'Zaic
8 hours ago
2
$begingroup$
At the risk of being pedantic, I'd like to point out that the
range "zero".."nine"
is not fully specified.$endgroup$
– Unrelated String
8 hours ago