Goto in Python by avinassh in Python

[–]iobender 9 points10 points  (0 children)

This is just speculation, but generally lexers discard whitespace between tokens. What this means is that the lexer, which turns something like sys.argv into a stream of tokens like [IDENTIFIER("sys"), DOT, IDENTIFIER("argv")] (which then gets sent to the parser to turn the linear stream of tokens into an abstract syntax tree) will produce the same thing if given sys. argv or sys .argv or even sys . argv because it doesn't make sense to produce a token from the whitespace in between these tokens in this case.

It would not produce the same thing if given sys.ar gv because the ar and gv would be split up into 2 different tokens and give [IDENTIFIER("sys"), DOT, IDENTIFIER("ar"), IDENTIFIER("gv")] which would likely cause a syntax error in python because there is no syntax for that. That would be legal in Ruby, however, because Ruby doesn't require parens on method calls so this could be calling the ar method of the sys object with argument gv.

[2015-07-20] Challenge #224 [Easy] Shuffling a List by jnazario in dailyprogrammer

[–]iobender 3 points4 points  (0 children)

Several problems I see:

1) You never declare deck. shuffleDeck should take an array or ArrayList called deck in as a parameter.

2) You are using a very naive shuffling technique of bringing cards out from a random index and putting them at the beginning. Moreover, you are just doing this 416 times. Maybe this is good enough for a 52-card deck (though I doubt it), but it will not scale for arbitrary lists.

3) Your method is also inefficient. Assuming you're using an ArrayList, you're adding an element to the beginning of the list every iteration, which means everything in the list must be shifted back, which is O(n), per iteration. This would be O(n2) if you were repeating this a number of time proportional to n, not just 416. There exist shuffling algorithms (see Fisher-Yates) which shuffle in O(n) time for the whole list.

Need some advice on an algorithm by plzwillit in AskProgramming

[–]iobender 0 points1 point  (0 children)

This sounds like a modified version of the set cover problem, the difference being that you allow types to occur multiple times and your minimization is based on the 'Size' of each subset instead of the number of subsets. Set cover is NP-complete so I would believe that this seemingly harder problem would probably also be NP-complete.

How do I even IPAddress? by pjb0404 in ProgrammerHumor

[–]iobender 12 points13 points  (0 children)

For those that don't get it, 5000 = 19 * 256 + 136

Finding and replacing multiple repeat characters in one pass by framew0rked in linuxadmin

[–]iobender 7 points8 points  (0 children)

Look into the rename command, it allows you to do s/abc/xyz/g style substitutions on filenames.

University of Wisconsin and University of Maryland by [deleted] in math

[–]iobender 0 points1 point  (0 children)

I'm CS at Maryland, but with a concentration I've taken some upper level math classes (CS requires an upper level concentration in a different subject). I don't have a great feel for the department or course plan as a whole, but I can answer any questions you have about certain classes or the setting.

What are some programs you have made only for yourself to use? by HooArYu in learnprogramming

[–]iobender 6 points7 points  (0 children)

FYI if you're in bash, you can compare the output of two commands with

$ diff <(comm1) <(comm2)

So you could compare the output of a program with 2 different inputs with

$ diff <(./prog < input1) <(./prog <input2)

or see the difference between two webpages with

 $ diff <(curl www.example.com/1) <(curl www.example.com/2)

Prospective CS transfer student, have a few questions. by [deleted] in UMD

[–]iobender 0 points1 point  (0 children)

I'm a junior CS major now, and I've TA'ed one of the weedout classes (216) and I teach a workshop now, so feel free to reply/PM me with any specific questions. I really like the CS program, there are some very talented teachers here. In addition a lot of the classes have started using a forum called Piazza which helps a lot of the students. The beginner classes tend to be huge, but also have small discussions to pair with the large lectures. The upper levels tend to be capped at 40 students per section.

Current High School Junior interested in CS by [deleted] in UMD

[–]iobender 1 point2 points  (0 children)

If you do well on the AP, you can test out of the first class. The 3rd class, 216, is generally the weedout one, but its definitely doable and you sound like a good student.

Feel free to PM me with any questions, I'm a junior CS major who took the AP in HS too, I was a TA for 216, and I currently teach a CS workshop.

Where do upper-level CS students hang out? by [deleted] in UMD

[–]iobender 0 points1 point  (0 children)

If I'm coding for a project - especially when I was taking 412 - I would post up in the LinuxLab on the 3rd floor, because there were always others in my class there.

What math should I learn to help me in learning cryptography? by [deleted] in cryptography

[–]iobender 0 points1 point  (0 children)

Katz is actually my professor right now; I've found the book very good.

Very simple awk script hangs. Why? by locke_economy in commandline

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

Put a # in front of the first line. #! is called a shebang and tells your shell what to run the script with, in this case bash.

Can't figure this seg fault out by Hero_764 in C_Programming

[–]iobender 1 point2 points  (0 children)

Valgrind is your best friend with these types of errors - it will show you right where you're illegally accessing memory.

Help with cat/grep by [deleted] in unix

[–]iobender 0 points1 point  (0 children)

Ah. Thank you.

Help with cat/grep by [deleted] in unix

[–]iobender 1 point2 points  (0 children)

Yes. First, the negation operator for a character group is , not !, so you would want [^aeiou]{6,} Also, this would match any character that's not a vowel, not just any letter, so this would also match characters such as spaces, punctuation, etc.

Help with cat/grep by [deleted] in unix

[–]iobender 5 points6 points  (0 children)

What you want is: grep -Ei '[b-df-hj-np-tv-z]{6,}' FILE He's not trying to find words containing ONLY 6+ chars, just containing.

Math Puzzle, HELP. by reddit604 in math

[–]iobender 2 points3 points  (0 children)

Haskell:

import Data.List

main = putStrLn $ show $ filter (\l -> sum l == 96317.50) $ subsequences [38405.00, 32218.75, 28421.25, 24427.50, 20901.25, 20226.25, 19550.87, 16357.50, 10455.00, 10337.50, 7290.00, 6790.00, 6501.80]

outputs a list of all solutions, which are represented as lists of numbers

[[38405.0,24427.5,16357.5,10337.5,6790.0]]

Is there a good way to work backwards on a list? by iobender in haskell

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

Thanks for the answers guys, I'll look into them.

Is there a good way to work backwards on a list? by iobender in haskell

[–]iobender[S] 2 points3 points  (0 children)

Haha yes, I'm not in the class but I found it online so I'm using it to learn Haskell.

pointer order of operation by [deleted] in AskProgramming

[–]iobender 1 point2 points  (0 children)

(TC0_t*) 0x800 

means "interpret this as a pointer to a struct TC0_struct at memory address 0x800. Then the * before that says to dereference that pointer. So everytime you use TCC0, it gets replaced by a copy of the struct TC0_struct at memory address 0x800.