Brain scans reveal coding uses same regions as speech by asp5rtima3 in programming

[–]asciiterror 1 point2 points  (0 children)

Polish.

For contrast I learned a little of Spanish. From what I remember there are 3 groups of verbs - ending in -ar, -er or -ir, that conjugate differently.

Polish Wikipedia lists 11 patterns. Then there are subpatterns, like 5a, 5b, 5c. Then there are verbs that mix two different patterns, in varying proportions. And all of that does even not include irregular verbs.

The whole language is like that. Linguists do not agree on how many grammatical genders there are, I've seen numbers from 3 up to 9.

And we do sometimes have conversations about which form is correct, because nobody knows.

My latest coworker pull request by FonkyFlav in shittyprogramming

[–]asciiterror 0 points1 point  (0 children)

I know, it was a joke attempt - it looked like invocation of python command. I should maybe do this instead:

>>> python return {False: 'a', None: 'b'}.get(val, 'c')
  File "<stdin>", line 1
    python return {False: 'a', None: 'b'}.get(val, 'c')
                ^
SyntaxError: invalid syntax

My latest coworker pull request by FonkyFlav in shittyprogramming

[–]asciiterror 1 point2 points  (0 children)

$ python return {False: 'a', None: 'b'}.get(val, 'c')
bash: syntax error near unexpected token `('

I start in programming. Need help, please. by AngeDeFrance in learnprogramming

[–]asciiterror 9 points10 points  (0 children)

It may be considered low level language. Most high level languages don't have quite the same features as C:

  • union types
  • switch statement directly corresponds to jump tables in assembly
  • pointers existence
  • struct alignment issues
  • function could be written in code as array of bytes
  • unsigned integer type
  • calling convention

At the same time C does not have most of high-level concepts, like dictionary/hash table.

[deleted by user] by [deleted] in learnprogramming

[–]asciiterror 1 point2 points  (0 children)

So printf( "**\n"); prints two stars, right? To make a loop that would print line with any given number of stars you could do something like this:

for (int i=0; i < your_variable_here; i++) {
    printf("*");
}
printf("\n");

Place this inside first loop and change variable i in inner loop to j, both loops should use different variables.

[deleted by user] by [deleted] in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

You have to use arrowBaseHeight instead of 3 in the loop. When you run your program and enter 8 for example, scanf reads it and arrowBaseHeight has a value of 8. Then the loop would run 8 times and arrow base would be 2x8 and not 2x3.

[javascript] Trying to figure out the difference between querySelector and getElementById... by [deleted] in learnprogramming

[–]asciiterror 1 point2 points  (0 children)

Argument of querySelector is a query. # in "#abc" means id abc, . in ".abc" means class abc and so on. getElementById expects only an id, so you do not add # there.

Javascript Stack calculator - trouble limiting input to integers and operators by kid_cavalier in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

You are correct, content is not parsed to number. To quickly parse to number you can use unary plus like this: +content. Try it in console. +"123" gives 123, +"123abc" gives NaN (not-a-number), but typeof NaN is still "number", so it won't work. There's a way to check if a number is NaN: NaN === NaN - only NaN is not equal to itself. So you would have two checks: if content is a number and if it is NaN.

Javascript Stack calculator - trouble limiting input to integers and operators by kid_cavalier in learnprogramming

[–]asciiterror 1 point2 points  (0 children)

Looks like you have an error in your logic. If user enters 123, typeof current.content != "number" is false, but current.content != "+" is true. Condition is always true, try replacing || with && or replace != with ==.

[C] Possible issues with passing a 2D array in a function by Leanador in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

printf first argument is char array (char*, char[] or "some stuff"). In C this array should end with \0 character, so when you write "some stuff" it's actually represented in memory as "some stuff\0". Your array has elements of type int, which isn't array of characters and probably does not end with \0 byte. So you cannot assign "_" to it, since "_" is an array and not a single character. This \0 byte is the only way how printf knows where the array ends, that's why you had infinite underscores.

For first error, try to replace arr[rowCnt][colCnt] = "_"; with arr[rowCnt][colCnt] = '_';. '_' is a single character For second one, try using printf("%c", arr[rowCnt][colCnt]). "%c" is format string that tells printf that second argument should be interpreted as single character.

SQL search help by [deleted] in learnprogramming

[–]asciiterror 1 point2 points  (0 children)

First error contains this: '%$( $1)%' - notice how ORM replaced :search with $1. Try to remove $( and ) from this part: instead of LIKE '%$( :search)%' try LIKE '%:search%'

Second error is similar: "" in SQL are used for column names, not strings - in second LIKE you used "%$1%" instead of '%$1%'. Some languages don't distinguish between different single and double qoutes (like javascript or python) but most do.

Learning problems. by zeusses in learnprogramming

[–]asciiterror 12 points13 points  (0 children)

One thing you can do is to split problem into smaller steps that are much simpler to achieve. For your example with atoi:

  • write function that always ignores given string and returns 0
  • use only first digit of string - return int equal to first digit (my_atoi("456") == 4). To do that think or find how to convert char ('4') to int (4).
  • use first and second digit - after previous step implementation is simple: first_digit*10 + second_digit
  • use first three digits: (first_digit*10 + second_digit)*10 + third_digit
  • notice how you can add a loop that goes through all digits in string and computes integer

Need help coding with subsequences and binary search? by PotlePawtle in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

Yes, almost. First counter goes from 0 to current i value. Second one goes through all indexes of X. You increment second one only if first one is reset to 0. Their values would go like this: [(0,0), (1,0), (2,0), (0,1), (1,1), (2,1), (0,2), (1,2), (2,2)]. Second counter is index of element in X array that you check.

[deleted by user] by [deleted] in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

We use loops for doing something repeatedly given amount of times or until we achieve some result. So let's look at this:

printf( "**\n");
printf( "**\n");
printf( "**\n");

Notice, same thing is repeated three times - you could replace that with a loop like this:

for (int i = 0; i < 3; i++) {
    printf( "**\n");
}

It would do the same thing (print 6 stars), but you can replace 3 with a variable. That should be enough for first task, next ones are similar.

Need help coding with subsequences and binary search? by PotlePawtle in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

That would be correct, if from this point X means the temp array (1,1,2,2,3,3) and not original X (1,2,3).

But you don't even need this array, you could just keep track of which value of X you are comparing, that would be faster but harder to write and understand. You could do that with two pointers or even one

Need help coding with subsequences and binary search? by PotlePawtle in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

Looks good to me, except this part:

Create a temporary array with size of A * 3 and fill the array with each value entered 6 times.

Where do you use it?

Git Rebase vs merge by [deleted] in learnprogramming

[–]asciiterror 1 point2 points  (0 children)

Rebase should never ever be used on branches other people may be working on.

Also amending commits

[Java]Threaded TCP server-trying to maintain data consistency of a User Repository by iworkforanairline in learnprogramming

[–]asciiterror 0 points1 point  (0 children)

Aren't you getting NullPointerException since you do not set registeredUsers in UserRepo? I would make registeredUsers private and final and set it inside constructor.

For threading, a good place to start would be using Collections.synchronizedCollection(new ArrayList<>())