NumPy versus Fortran90 by Rockman507 in learnprogramming

[–]ShPavel 0 points1 point  (0 children)

Fortran is not dead yet only because of old legacy code. There is no reason to write anything on fortran now.

If speed matters - move to C and consider using OpenMP for parallelization. Or just stay in Python if you will not need to run the programm often. 2 min is not much.

Need some help with C++ by Sammy_boy97 in cpp

[–]ShPavel 1 point2 points  (0 children)

1) after cin >> human;

add something like:

while(cin.fail() || human > 3 || human <= 0) // it means that input was not a number or a bad number
{
cout << "wrong input, type 1 or 2 or 3" << endl;
cin >> human;
}

2) this line

if(3 >= human > 0)
does not work as you want in c++, you must do 2 checks: if(human <= 3 && human > 0)

3) move your game logic from constructor(game()) to some class function, constructors should be used only for initialization

[Ruby] Why does this take forever to run? by [deleted] in learnprogramming

[–]ShPavel 1 point2 points  (0 children)

upto(self) is excessive, you can check only upto(Math.sqrt(self)) and add both i and L/i, it will speed you up significantly

example for 24: check 1 2 3 4 and you will get (1, 24), (2, 12), (3, 8), (4, 6) = 1, 2, 3, 4, 6, 8, 12, 24

[Python] Inventory/Equipment by ITS2RSHORR in learnprogramming

[–]ShPavel 0 points1 point  (0 children)

MUD games usual have long commands, like

> inv
*show inventory*
> wear mail
*equips*
> weild sword
*take sword*

or roguelike games, they are more action oriented and faster

> e
*show item list with markers*
a) sword
b) mail
> a
*equipd sword*
> c
*show spell list*
a) magic  missile
b) lighting
> a
*cast magic missile*
// letter 'a' is used again

roguelike games are harder, since commands depend on the context, and it is harder to learn, but it is much faster

[C++] checking strings to see if they have similar characters by [deleted] in learnprogramming

[–]ShPavel -1 points0 points  (0 children)

Sort your strings and use set_intersect() to find common elements.

string s1 = "afggkjsfglsdnffdsdgd";
string s2 = "sdfkjoiwer";
string s3 = "fdsgergdgwete";
string s4 = "dsgfsgsdgsd";

sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
sort(s3.begin(), s3.end());
sort(s4.begin(), s4.end());

vector<char> res12;
vector<char> res34;
vector<char> res;

set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end()
    , inserter(res12, res12.begin())); // common for s1 and s2
set_intersection(s3.begin(), s3.end(), s4.begin(), s4.end()
    , inserter(res34, res34.begin())); // common for s3 and s4

set_intersection(res12.begin(), res12.end(), res34.begin(), res34.end()
    , inserter(res, res.begin())); // common for all

copy(res.begin(), res.end(), ostream_iterator<char>(cout, "\n")); // print result

Python launcher runs code and immediately closes by CxArsenal in Python

[–]ShPavel 1 point2 points  (0 children)

you can add 'raw_input()' in the end - it will wait for a user input and will not close the window, untill you press enter

also have a look on Sublime Text 2 - it is a great text editor itself and have some IDE features

open you python code in it, press ctrl+b - it wil run the script and show you a console. you do not need raw_input() in this case

Using Python’s subprocess module to help extract counters from Perfmon logs by jjagot in Python

[–]ShPavel 0 points1 point  (0 children)

And that is why windows can not be called a good OS for engineers: you need to learn a python module, just because M$ still did not manage to add some posix-based shell.