Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

Kostya Kovalskyy

@Kostya Kovalskyy
About
Posts
10
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Ubuntu and Windows
    K Kostya Kovalskyy

    That's pretty cool. I will try that :)

    The Lounge linux question css sysadmin discussion

  • Ubuntu and Windows
    K Kostya Kovalskyy

    Definitely Ubuntu. It works much faster then Windows, which has about 1000 programs that start at startup. It looks much better and it is a lot more customizable. Plus, most of the stuff is free. And most of the programs I use work with Wine perfectly, so I only boot Windows when I want to play a brand new game (most of the games before 2008 work perfectly with wine), or I need Visual Studio. Now, even if I work on cross-platform program I rarely boot Windows, because MinGW works nice on Wine too :)

    The Lounge linux question css sysadmin discussion

  • Image Processing
    K Kostya Kovalskyy

    Try OpenCV. It's a really easy to use, and powerful library for C++.

    Algorithms csharp help question

  • Extreme Artificial Intelligence
    K Kostya Kovalskyy

    Not really. This "code" is kinda the same for the robot and a person:

    if self is touching("Hot Stove") feelHot();

    But for the person, the function feelHot will have several million, if not billion lines of code. Robot will have much much much less. In the function, the robot will probably have something that tells him to move away his hand and maybe inspect it for any damage, but that's it. The person, on the other, would actually feel the pain. Maybe they will start crying, maybe they will get ice or maybe do something else. It is impossible to predict. If you write a new genius sorting algorithm computer will not be aware of it. Other people may inspect it and find it really smart and cool but computer will just execute it faster than a slower algorithm. You can teach a 10 year old the basic math and he will probably be able to use the algorithm, and perform the operations specified there, but he will probably not be aware of how it works. Even the basic functions for human, have unimaginable complexity. For computer adding 2 numbers is just adding 2 numbers. But for humans, each number can also invoke specific memory, feeling, etc.

    Algorithms question

  • Extreme Artificial Intelligence
    K Kostya Kovalskyy

    No.

    Algorithms question

  • Challenge: the fastest way to filter doubled items from a list.
    K Kostya Kovalskyy

    You can put the strings that repeat often in the beginning of your unique string, so it will not have to iterate that many times through the loop. So it will be ordered by the amount it repeats instead of the order of original string. For example, for string string: one three two two three three unique string will be unique: three two one instead of unique: one three two because there is most threes in the string. But this will not always optimize, because there may be no most occurring string if they are completely at randomized. So for example, it would not work for random computer generated strings, but work for predictable user info. Edit: you can also order them by there length, for example if you have strings: reallyLongStringWhichIsReallyLong anotherString reallyLongStringWhichIsReallyLong shortString shortString ... Even through shortString and reallyLongString occur the same amount of times, it takes longer for computer to check if reallyLongString is in the front, so it would be more efficient to move this in the back of unique string. Also, how long will it take your function in C# to check this strings: "stuff", "str", "str", "morestuff", "str", "not unique", "evenMoreStuff", "stuff", "unique", "morestuff", "not unique"? In C++, it takes 0.124 seconds when I print results to the screen and 0.074 when I do not. in C++ with gcc:

    //0.124 and 0.074
    #include
    #include
    using namespace std;

    vector getUnique(vector listStr) {
    vector::iterator listIt;

    vector uniqueStr;
    vector::iterator uniqueIt;

    for (listIt = listStr.begin(); listIt < listStr.end(); listIt++) {
    bool exists = false;
    for (uniqueIt = uniqueStr.begin(); uniqueIt < uniqueStr.end(); uniqueIt++) {
    if (*listIt == *uniqueIt) {
    exists = true;
    break;
    }
    }
    if (!exists) uniqueStr.push_back(*listIt);
    }
    cout << "list: ";
    for (listIt = listStr.begin(); listIt < listStr.end(); listIt++) cout << " " << *listIt;
    cout << "\n\nunique list: ";
    for (uniqueIt = uniqueStr.begin(); uniqueIt < uniqueStr.end(); uniqueIt++) cout << " " << *uniqueIt;
    return uniqueStr;
    }

    int main() {
    vector str = {"stuff", "str", "str", "morestuff", "str", "not unique", "evenMoreStuff", "stuff", "unique", "morestuff", "not unique"};

    getUnique(str);
    return 0;
    }

    Clever Code learning csharp java help question

  • Care for belt, suspenders, and a spare rope?
    K Kostya Kovalskyy

    #define true false Never trust those booleans!

    The Weird and The Wonderful question

  • Missed Opportunity for Easter Egg
    K Kostya Kovalskyy

    If you want to only "subtly" mess it up, and work for most of other cases normally you can do this:

    #include

    class T {
    public:
    int a;
    T(int _a) : a(_a) {}
    bool operator==(const T &var) {
    if((a == 1 && var.a == 2) || (a == 2 && var.a == 1)) return true;
    else return a == var.a;
    }
    };

    using namespace std;

    int main() {
    #define int T //this is defined here because main returns int, and this causes error if defined earlier
    int a = 1, b = 2;
    if (a == b) cout << "this is evaluated";
    a = 4, b = 5;
    if (a == b) cout << "while this is not" << endl;
    return 0;
    }

    The Lounge com

  • Missed Opportunity for Easter Egg
    K Kostya Kovalskyy

    Even through it does not really "overload" it, it can still lead to a lot of confusion. In C++ you can also do something like this

    #include

    class T {
    public:
    int a;
    T(int _a) : a(_a) {}
    bool operator==(const T &var) {return true;}
    };

    using namespace std;

    int main() {
    #define int T //this is defined here because main returns int, and this causes error if defined earlier
    int a = 1, b = 2;
    if (a == b) {
    cout << "this is evaluated" << endl;
    }
    return 0;
    }
    }

    Of course, you can always put anything in the == operator so it would behave differently :)

    The Lounge com

  • Missed Opportunity for Easter Egg
    K Kostya Kovalskyy

    compiles on GCC

    #define if(X) if(1)

    using namespace std;

    int main()
    {
    if (1 == 2) {
    cout << "this is executed" << endl;
    }
    return 0;
    }

    this would compile on C compiler too, but I just hate using those printfs. But you were right about #defining numbers -- it's impossible. A define identifier name cannot start with a number. But you can overload almost anything else.

    The Lounge com
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups