Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Question

Commonmark migration
Source Link

#How many atoms in the hydrocarbon?

How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for mEthane but not methane, and ETHAnE but not ETHANE, and Propane but not propane. The inputs methene and methyne may give undefined output since those are not real chemicals.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

Examples

##Rules

Possible Input -> Possible Output
Methane -> 1 4
propane -> 3 8
Heptyne -> 7 12
Decene -> 10 20

Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

#How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for mEthane but not methane, and ETHAnE but not ETHANE, and Propane but not propane. The inputs methene and methyne may give undefined output since those are not real chemicals.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

##Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for mEthane but not methane, and ETHAnE but not ETHANE, and Propane but not propane. The inputs methene and methyne may give undefined output since those are not real chemicals.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

Examples

Possible Input -> Possible Output
Methane -> 1 4
propane -> 3 8
Heptyne -> 7 12
Decene -> 10 20

Rules

  • No standard loopholes.
  • Shortest code in bytes wins.
added 146 characters in body
Source Link
79037662
  • 3k
  • 12
  • 22

#How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for MethanemEthane but not methane, and ethaneETHAnE but not EthaneETHANE, and Propane but not propane. The inputs methene and methyne may give undefined output since those are not real chemicals.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

##Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

#How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for Methane but not methane, and ethane but not Ethane.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

##Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

#How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for mEthane but not methane, and ETHAnE but not ETHANE, and Propane but not propane. The inputs methene and methyne may give undefined output since those are not real chemicals.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

##Rules

  • No standard loopholes.
  • Shortest code in bytes wins.
Became Hot Network Question
Tweeted twitter.com/StackCodeGolf/status/1202694218591981587
Source Link
79037662
  • 3k
  • 12
  • 22

How many atoms in the hydrocarbon?

#How many atoms in the hydrocarbon?

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \2ドルn+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \2ドルn\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \2ドルn-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1 <-> meth
2 <-> eth
3 <-> prop
4 <-> but
5 <-> pent
6 <-> hex
7 <-> hept
8 <-> oct
9 <-> non
10 <-> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

##Challenge

Your task is to write a function or program that receives a string or list of characters representing the name of a hydrocarbon, and produces or outputs the number of carbon and hydrogen atoms in a molecule of that hydrocarbon.

For each of the 30 hydrocarbon names, the code must accept at least one possible capitalization of that name. For example, it is fine if your code works for Methane but not methane, and ethane but not Ethane.

The input and output can be in any convenient format. You don't need to label which number represents carbon and which represents hydrogen, just keep the order of the numbers consistent.

You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

##Examples Possible Input -> Possible Output Methane -> 1 4 propane -> 3 8 Heptyne -> 7 12 Decene -> 10 20

##Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

AltStyle によって変換されたページ (->オリジナル) /