Jump to content

  • Log In with Google      Sign In   
  • Create Account

Álvaro

Member Since 07 Mar 2002
Offline Last Active Yesterday, 08:53 PM

#5144070 Why is the odd integer rootof a negative number undefined?

Posted by on 03 April 2014 - 06:14 AM

Good old Windows calculator:


Here's some advice on how to ask questions on these forums:
* Try to find the answer for yourself first. For instance, using Google. You do have an Internet connection, don't you?
* If you still can't find the answer, post enough detail that we know what the situation is, why you think it's wrong, etc.


Let me illustrate what "enough detail" means:
I tried to compute the cubic root of -27 in Windows Calculator [version blah] and I get an error message that would translate to "invalid value". Shouldn't the answer be -3? Is this a bug?


#5144067 Unknown string of numbers..

Posted by on 03 April 2014 - 05:48 AM

Alvaro, I still can't really code a program to generate this numbers in c++.


Here it is in C++:
 
#include <iostream>

bool check_histogram_of_digits_is_weakly_increasing(unsigned long x) {
  int histogram[10] = {0};
  
  do {
    histogram[x % 10]++;
    x /= 10;
  } while (x > 0);
  
  for (int i=0; i<9; ++i) {
    if (histogram[i] > histogram[i+1])
      return false;
  }
  
  return true;
}

int main() {
  for (int i=1; i<10000; ++i) {
    if (check_histogram_of_digits_is_weakly_increasing(i))
      std::cout << i << '\n';
  }
}

Why your method produce 9988?


Because its histogram of digits is (0,0,0,0,0,0,0,0,2,2), which is weakly increasing.


#5143929 Why is the odd integer rootof a negative number undefined?

Posted by on 02 April 2014 - 11:58 AM

 

Hey mathematicians, why is (odd integer) root of a negative number undefined behaviour?

  _____
³√-27 = -3 ?
-3 · -3 = 9
9 · -3 = -27
 

 

Is this becoming a hobby of yours? You ask why something is not the way it should be, but it actually IS the way it should be. You can initialize multi-dimensional arrays in C or C++ to zero by specifying only the first element, and the odd-integer root of a negative number is perfectly well defined.




#5143926 Unknown string of numbers..

Posted by on 02 April 2014 - 11:44 AM

 

Your method would produce 877, but that wasn't in the list.
All numbers should again not have two times the same number except for the nine.

 

 

If you quote from unrelated posts, you'll confuse everybody. In the post where I object to your method, I complain about 799. I was complaining about 877 for Nypyren's method.




#5143924 Unknown string of numbers..

Posted by on 02 April 2014 - 11:39 AM

Found it, thanks to DiegoSLTS observations...

 

Every time a new digit is added.

 

First you start with a nine, you can't swap anything there. Then you add a second digit and you allow numbers 8 and 9. Then you have three possibilities if every number should include at least one 9: 98, 89 and 99. After that you add another digit. The numbers allowed are 7, 8 and 9 like DiegoSLTS said. All numbers should again not have two times the same number except for the nine.

 

9

89 98 99

789 798 879 897 899 978 987 989 998 999

As you can see the numbers are grouped in terms of number of digits. The first number starts with the lowest digit first. The last number contains only nines. Aside from that I don't see the exact order inside a "digit group". But it looks like the order "prefers" lower digits first. Is this the pattern or is there also a pattern inside the groups?

 

Your method would produce 799, but that wasn't in the list.




#5143923 Unknown string of numbers..

Posted by on 02 April 2014 - 11:37 AM

 

Those are the numbers whose histograms of digits are weakly increasing.

perl -e 'NUMBER: for $n (1..1000) {%c=(); for $d (split "",$n){$c{$d}++}; for $d (1..9) {next NUMBER if $c{$d} < $c{$d-1}} print "$n\n"}'

Could you maybe provide the output too for people who don't have Perl installed? wink.png

 

9
89
98
99
789
798
879
897
899
978
987
989
998
999

 

 

If you loop till 10000, you get

9
89
98
99
789
798
879
897
899
978
987
989
998
999
6789
6798
6879
6897
6978
6987
7689
7698
7869
7896
7899
7968
7986
7989
7998
8679
8697
8769
8796
8799
8899
8967
8976
8979
8989
8997
8998
8999
9678
9687
9768
9786
9789
9798
9867
9876
9879
9889
9897
9898
9899
9978
9987
9988
9989
9998
9999



#5143922 Unknown string of numbers..

Posted by on 02 April 2014 - 11:36 AM

Outer loop seed = {9, 89, 789, 6789, ... 123456789, MAYBE 0123456789 }

 

Inner loop:  Take the digits you have available (for example with 789, you have the digits 7,8, and 9 to work with) and find the next higher integer with the same number of digits which uses only the digits you have available.  Terminate the inner loop when all digits are 9.

 

Your method would produce 877, but that wasn't in the list.




#5143918 Unknown string of numbers..

Posted by on 02 April 2014 - 11:31 AM

Those are the numbers whose histograms of digits are weakly increasing.

 

perl -e 'NUMBER: for $n (1..1000) {%c=(); for $d (split "",$n){$c{$d}++}; for $d (1..9) {next NUMBER if $c{$d} < $c{$d-1}} print "$n\n"}'



#5143893 Support Vector

Posted by on 02 April 2014 - 09:03 AM

 

Hi,

 

Is the following function for a support vector correct?

class Vector2
{
     public Vector2 SupportVector()
     {
         if (Math.Abs(X) > Math.Abs(Y))
             return new Vector2(X, 0);
         else
             return new Vector2(0, Y);
     }
}

 

I would call that function something like `LongestProjectionToCoordinateAxis'.




#5143644 \why can't I initialize a multidimensional C array with zeroes

Posted by on 01 April 2014 - 02:33 AM

Can anyone explain what the problem was with the original code? It works for me...


#5143600 \why can't I initialize a multidimensional C array with zeroes

Posted by on 31 March 2014 - 07:42 PM

Do you have a compiler error, or something?


#5143450 Array Problem in C

Posted by on 31 March 2014 - 06:06 AM

I understood that @op had a hard requirement of using C, so even though int const size = 20; was the right thing to do in C++, I went for #define. This exercise showed me my C has become rusty, and C++ has spoiled me...


Perhaps using the macro is more idiomatic in C, and using `const' is not as good a substitute as it is in C++. The reason this works in C99 is because a local array can have a size specified by a variable (a feature that the OP was already using). If I were to make the array global, it wouldn't have worked (but in C++ this would have been fine).


#5143448 a better computer

Posted by on 31 March 2014 - 06:02 AM

Why would we have a name for something that doesn't exist? Perhaps you should ask a theologian, because that doesn't seem to be an obstacle to them. smile.png

[EDIT: I probably deserve bad ratings for this post (my reputation points can go jump in the lake), but it should be noted that this thread belongs in the lounge and not in this forum.]


#5143359 Array Problem in C

Posted by on 30 March 2014 - 08:19 PM

  for(int g = 0; g < new_array_size; g++) {


Should be
  for(int g = 0; g < size; g++) {
EDIT: Why is that function called `binarySearch'? I can only imagine that you are in the early stages of putting together some code and this is just some test, and not really what you intend to do. But giving a function a name unrelated to what it does is extremely confusing and I wouldn't even do it during tests. I certainly wouldn't post it to a forum.


#5143355 what scale? metric or other

Posted by on 30 March 2014 - 08:09 PM

One clarification: Setting 1=1cm is perfectly "metric".
 
From the Wikipedia page on Metric System:

The centimetre gram second system of units (CGS) was the first coherent metric system, having been developed in the 1860s and promoted by Maxwell and Thomson. [...]


You seem to be confusing the metric system with the International System of Units.




PARTNERS