Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/644895876008255488
deleted 19 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

##Problem definition:

Once upon a time in a strange situation, people called a number ugly if it was divisible by any ofHere's the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be uglychallenge: \$-14\$ and \$-39\$ are examples of such numbers.

Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be ugly: \$-14\$ and \$-39\$ are examples of such numbers.

##Input Sample:Input Sample:

##Output Sample:Output Sample:

Is the code understandable? How can it be improved? Here's the challenge.

##Problem definition:

Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be ugly: \$-14\$ and \$-39\$ are examples of such numbers.

##Input Sample:

##Output Sample:

Is the code understandable? How can it be improved? Here's the challenge.

Here's the challenge:

Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be ugly: \$-14\$ and \$-39\$ are examples of such numbers.

Input Sample:

Output Sample:

Is the code understandable? How can it be improved?

added challenge description
Source Link
Quill
  • 12.1k
  • 5
  • 41
  • 94

Here ##Problem definition:

Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is anugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be ugly: \$-14\$ and \$-39\$ are examples of such numbers.

One day on your free time, you are gazing at a string of digits, something like:

123456

You are amused by how many possibilities there are if you are allowed to insert plus or minus signs between the digits. For example you can make:

1 + 234 - 5 + 6 = 236

which is ugly. Or:

123 + 4 - 56 = 71

which is not ugly.

It is easy to count the number of challenge I trydifferent ways you can play with the digits: Between each two adjacent digits you may choose put a plus sign, a minus sign, or nothing. Therefore, if you start with N digits there are \$3^{N-1}\$ expressions you can make. Note that it is fine to solvehave leading zeros for a number. If the string is '01023', then '01023', '0+1-02+3' and '01-023' are legal expressions.

 

IsYour task is simple: Among the \$3^{N-1}\$ expressions, count how many of them evaluate to an ugly number.

##Input Sample:

Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each test case will be a single line containing a non-empty string of decimal digits. The string in each test case will be non-empty and will contain only characters '\$0\$' through '\$9\$'. Each string is no more than 13 characters long. E.g.

1
9
011
12345

##Output Sample:

Print out the number of expressions that evaluate to an ugly number for each test case, each one on a new line. E.g.

0
1
6
64

Is the code understandable? How can the codeit be improved? Here's the challenge.

Here is an example of challenge I try to solve.

Is this understandable? How can the code be improved?

##Problem definition:

Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the one-digit primes (\$2\$, \$3\$, \$5\$ or \$7\$). Thus, \$14\$ is ugly, but \$13\$ is fine. \$39\$ is ugly, but \$121\$ is not. Note that \$0\$ is ugly. Also note that negative numbers can also be ugly: \$-14\$ and \$-39\$ are examples of such numbers.

One day on your free time, you are gazing at a string of digits, something like:

123456

You are amused by how many possibilities there are if you are allowed to insert plus or minus signs between the digits. For example you can make:

1 + 234 - 5 + 6 = 236

which is ugly. Or:

123 + 4 - 56 = 71

which is not ugly.

It is easy to count the number of different ways you can play with the digits: Between each two adjacent digits you may choose put a plus sign, a minus sign, or nothing. Therefore, if you start with N digits there are \$3^{N-1}\$ expressions you can make. Note that it is fine to have leading zeros for a number. If the string is '01023', then '01023', '0+1-02+3' and '01-023' are legal expressions.

 

Your task is simple: Among the \$3^{N-1}\$ expressions, count how many of them evaluate to an ugly number.

##Input Sample:

Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each test case will be a single line containing a non-empty string of decimal digits. The string in each test case will be non-empty and will contain only characters '\$0\$' through '\$9\$'. Each string is no more than 13 characters long. E.g.

1
9
011
12345

##Output Sample:

Print out the number of expressions that evaluate to an ugly number for each test case, each one on a new line. E.g.

0
1
6
64

Is the code understandable? How can it be improved? Here's the challenge.

deleted 277 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Ugly_Numbers Challengechallenge

I'm learning C++ programming and I do like to solve any typesHere is an example of challenges/exercises, and since I have huge desire to become betterchallenge I decidedtry to post some of my solved challenges here, so that I can find out how my coding style issolve.

Is itthis understandable, how? How can the code be improved? And anything you think that may be helpful. Here is an example of challenge I try to solve.

Ugly_Numbers Challenge

I'm learning C++ programming and I do like to solve any types of challenges/exercises, and since I have huge desire to become better I decided to post some of my solved challenges here, so that I can find out how my coding style is.

Is it understandable, how can the code be improved? And anything you think that may be helpful. Here is an example of challenge I try to solve.

Ugly_Numbers challenge

Here is an example of challenge I try to solve.

Is this understandable? How can the code be improved?

Rollback to Revision 5
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
deleted 243 characters in body
Source Link
lightning_missile
  • 2.8k
  • 2
  • 24
  • 42
Loading
added 12 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
edited tags
Link
Mast
  • 13.9k
  • 12
  • 57
  • 128
Loading
Fixed code indentation.
Source Link
Mast
  • 13.9k
  • 12
  • 57
  • 128
Loading
deleted 61 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312
Loading
Source Link
Loading