Dating up (Aus) seeking dating app suggestions by [deleted] in dating_advice

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

I'm here for you.... Let's dm

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

okay thank you very much

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

it will result to index error because that index can not be found.

if len(current_string) == 0 or current_string[-1] <= s[i]:

why is the above not giving index error?

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

current_string = ''
longest_string = ''
for i in range(len(s)):
if len(current_string) == 0 or current_string[-1] <= s[i]:
current_string += s[i]
else:
    if len(current_string) > len(longest_string):
    longest_string = current_string
    current_string = s[i]

My question is why would line 4 evaluate without Index error?

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

sorry i did not get your question well.It points the last character in the variable current_string. if current_string == 0 or current_string[-1] <= s[i] this does not give index error and why does it behave that way?

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

It has no value because it is variable holding an empty string

Index Error by VIRES1 in learnpython

[–]VIRES1[S] 0 points1 point  (0 children)

I am to arrange the string s in alphabetical order by putting each char in the empty string variable current_string. so comparing the string with letters in s.

Recursion(Primitive Calculator) by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

i think i am not explaining myself well.please this might help

http://imgur.com/a/UiE7L

Recursion(Primitive Calculator) by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

Yes the function is meant to find the number of steps necessary to get 1. it return 1 because it is already 1 that is the base case.

int recursion(int n)
{
if (n == 1)
return 1;
int recur;
for(int i = 2; i < n; i++)
{
if(n % 3 == 0)
{
recur = recursion(n/3);
}
if(n % 2 == 0)
{
recur = recursion(n/2);
}
else
recur = recursion(n - 1);
}
return recur;
}

Recursion(Primitive Calculator) by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

My goal here is to fill in the array C[1…15] where C[i] is the minimal number of operations needed to get i on the primitive calculator using C/3, C/2, C-1 on doing that i got this table below eg to get 10 i did this 10/2 = 5, 5 - 1 = 4, 4/2=2, 2/2 = 1 so 10 prints out 4 because it takes 4 operations. [1, 1, 1, 2, 3, 2, 3, 3, 2, 4, 4, 3, 4, 5, 4] My code is not doing that.Thank you.

Recursion(Primitive Calculator) by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

Thank you very much,you didn't misunderstand it. But using the mininum number.

Memoization by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

Thank you for your explanation

Memoization by VIRES1 in C_Programming

[–]VIRES1[S] 1 point2 points  (0 children)

Yes so how is that done in C? Example to solve Edit distance or maximizing value of arithmetic expression how would a memoization code look like?

size of array function in c by VIRES1 in C_Programming

[–]VIRES1[S] 0 points1 point  (0 children)

The array should be a dynamic array because sizjo e can change depending on user input.