• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Haly

One day I realized that sadness is just another word for not enough coffee.
At my school, tests were frequently split into two parts, a written part and a practical part. Practicals were done on the computers and submitted before the end of the test through our school's homework submission system.
 

usea

Member
feep, although I've never done it before, if mono supports the speech library (but unity doesn't), then yeah you should be able to do it no problem. .net has a concept of a managed process called an AppDomain. Usually a process has a single appdomain, but you can create other ones, tell it which libraries (.dlls) to load, and you can communicate between appdomains (not as simply as within an appdomain though). I did a cursory googling, and it seems that you can spawn new appdomains with unity without any issue. So I don't see why you couldn't write a mono library (dll) that used the speech dll, and load that at runtime in its own appdomain from unity. Then you'd have to communicate between the two appdomains and have the library do whatever stuff you need. It's all in-memory, not network communication or anything. Although a lot of resources will recommend network communication between them, but I doubt they need any kind of performance when doing so.

Some quick examples of spawning a new appdomain and loading an arbitrary library into it:
http://blogs.msdn.com/b/kirillosenk...applications-in-process-using-appdomains.aspx
http://stackoverflow.com/questions/3843421/how-to-call-a-method-of-a-class-from-another-appdomain
http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx
 

Feep

Banned
feep, although I've never done it before, if mono supports the speech library (but unity doesn't), then yeah you should be able to do it no problem. .net has a concept of a managed process called an AppDomain. Usually a process has a single appdomain, but you can create other ones, tell it which libraries (.dlls) to load, and you can communicate between appdomains (not as simply as within an appdomain though). I did a cursory googling, and found that you can spawn new appdomains with unity no problem. So I don't see why you couldn't write a mono library that used the speech dll, and load that at runtime in its own appdomain from unity.

Some quick examples of spawning a new appdomain and loading an arbitrary library into it:
http://blogs.msdn.com/b/kirillosenk...applications-in-process-using-appdomains.aspx
http://stackoverflow.com/questions/3843421/how-to-call-a-method-of-a-class-from-another-appdomain
http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx
Mono does not support System.Speech, but at this point I've resigned to having to completely change speech recognition engines if I port to another platform (or maybe by like August 2014 it'll support it). Still, thanks for the links! This looks promising.
 
This was a question on the first quiz in Intro to Comp Sci (6.00) at MIT (Spring 2011):

Code:
# Given 

def f(s):
    assert type(s) == str and len(s) > 0
    if len(s) == 1:
        return s
    else:
        return f(f(s[1:])) + s[0]

# what is the output of 

print f('mat')
print f('math')

Solve it on paper, of course. It's my understanding that the average grade for that quiz was... not very good.
 

Tomat

Wanna hear a good joke? Waste your time helping me! LOL!
This was a question on the first quiz in Intro to Comp Sci (6.00) at MIT (Spring 2011):

Solve it on paper, of course. It's my understanding that the average grade for that quiz was... not very good.
I have no clue. Can't even figure out what it's telling me :(
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Wow, they don't joke around. Double recursion on the first quiz lol.
 
This was a question on the first quiz in Intro to Comp Sci (6.00) at MIT (Spring 2011):

Code:
# Given 

def f(s):
    assert type(s) == str and len(s) > 0
    if len(s) == 1:
        return s
    else:
        return f(f(s[1:])) + s[0]

# what is the output of 

print f('mat')
print f('math')

Solve it on paper, of course. It's my understanding that the average grade for that quiz was... not very good.

I can only assume it does something regarding changing positions of letters in the string?

Duuno what f(s[1:]) does so... More specifically the s[1:]. But then again I haven't used python all that much (read not at all)
 

Feep

Banned
Code:
# Given 

def f(s):
    assert type(s) == str and len(s) > 0
    if len(s) == 1:
        return s
    else:
        return f(f(s[1:])) + s[0]

# what is the output of 

print f('mat')
print f('math')
Step by step. For 'mat':

return f(f('at')) + 'm'

return f( f(f('t') + 'a' ) + 'm'

return f('ta') + 'm'

(Trick: sending in 'at' resulted in 'ta', we now know that it reverses a two-letter sequence)

'atm'

(Trick: sending in 'mat' resulted in a transpose to 'atm')

For 'math':

return f(f('ath')) + 'm'

return f('tha') + 'm'

'hatm'

Someone may correct me if I'm wrong.
 

Kalnos

Banned
I can only assume it does something regarding changing positions of letters in the string?

Duuno what f(s[1:]) does so... More specifically the s[1:]. But then again I haven't used python all that much (read not at all)

IIRC s[1] refers to a point in the string and : cuts it at that point.
 
I have no clue. Can't even figure out what it's telling me :(

On the offhand chance you're not familiar with Python, it would be this in C#:


Code:
string F(string s)
{
    if (string.IsNullOrEmpty(s)) 
        throw new ArgumentException("s is not valid");

    if (s.Length == 1) 
        return s;
    else
        return F(F(s.Substring(1)) + s.Substring(0, 1); 
        // Substring(1) takes from index 1 to end of string, fyi
}
 

Tomat

Wanna hear a good joke? Waste your time helping me! LOL!
On the offhand chance you're not familiar with Python, it would be this in C#:


Code:
string F(string s)
{
    if (string.IsNullOrEmpty(s)) 
        throw new ArgumentException("s is not valid");

    if (s.Length == 1) 
        return s;
    else
        return F(F(s.Substring(1)) + s.Substring(0, 1);
}
Much better, thanks. Guess I should consider learning Python this summer.
 
IIRC s[1] refers to a point in the string and : cuts it at that point.

On the offhand chance you're not familiar with Python, it would be this in C#:


Code:
string F(string s)
{
    if (string.IsNullOrEmpty(s)) 
        throw new ArgumentException("s is not valid");

    if (s.Length == 1) 
        return s;
    else
        return F(F(s.Substring(1)) + s.Substring(0, 1); 
       // Substring(1) takes from index 1 to end of string, fyi
}

Perfect thanks.

Step by step. For 'mat':

return f(f('at')) + 'm'

return f( f(f('t') + 'a' ) + 'm'

return f('ta') + 'm'

(Trick: sending in 'at' resulted in 'ta', we now know that it reverses a two-letter sequence)

'atm'

(Trick: sending in 'mat' resulted in a transpose to 'atm')

For 'math':

return f(f('ath')) + 'm'

return f('tha') + 'm'

'hatm'

Someone may correct me if I'm wrong.

typed it in and got

Code:
atm
hatm

so yes.
 
Yes, feep has it right. To confirm your steps further, solve for "cream" and "farmer"

reamc
merarf

If you truly want to earn some Randolph Freelander bonus points, solve for "the rain in spain falls mainly on the plain"

I have no earthly idea. some padding to make it long
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I lost track somewhere around f(f(f(f('em')+'r')+'a') + 'f'
 

Feep

Banned
I lost track somewhere around f(f(f(f('em')+'r')+'a') + 'f'
This is inefficient! See my example above...once you "solve" for a certain number of letters, you don't need to redo the steps. f('ab') becomes 'ba'. f('abc') becomes 'bca'. f('abcd') becomes 'dbca'.

So, to solve for cream, you just move c to the end and do the "four letter" procedure twice. It so happens that the "four letter" procedure twice does nothing (f(f('abcd')) = 'abcd'), so "cream" becomes "reamc".

For "farmer", you move f to the end and to the "five letter" procedure twice. So:

f(f('armer')) + 'f'
f('rmera') + 'f'
'merarf'

Easy!
 

squidyj

Member
I can't stand these exams, I don't want to read and study any more of these gibberish slides(i don't mean I'm having trouble understanding the concepts, I mean so poorly explained and written that it becomes a sort of code you can only read once you already know what it's supposed to say) I'm pretty sure the algorithm in the slides for 3 colour problem is wrong, and I think the algorithm posted for knapsack is wrong too.

The practice problems can be equally incomprehensible. GAH.
 

6.8

Member
Aren't you allowed to use pseud-code when you doe white board stuff? That would seem pretty easy to me.
It really depends. I just do pseudo then move to code to cover my bases.

It's not that I can't do it. I just have to condition myself for it. I like the comfort of a compiler.
 
I can't stand these exams, I don't want to read and study any more of these gibberish slides(i don't mean I'm having trouble understanding the concepts, I mean so poorly explained and written that it becomes a sort of code you can only read once you already know what it's supposed to say) I'm pretty sure the algorithm in the slides for 3 colour problem is wrong, and I think the algorithm posted for knapsack is wrong too.

The practice problems can be equally incomprehensible. GAH.

Your class' slides or what are you talking about?
 

Feep

Banned
feep, although I've never done it before, if mono supports the speech library (but unity doesn't), then yeah you should be able to do it no problem. .net has a concept of a managed process called an AppDomain. Usually a process has a single appdomain, but you can create other ones, tell it which libraries (.dlls) to load, and you can communicate between appdomains (not as simply as within an appdomain though). I did a cursory googling, and it seems that you can spawn new appdomains with unity without any issue. So I don't see why you couldn't write a mono library (dll) that used the speech dll, and load that at runtime in its own appdomain from unity. Then you'd have to communicate between the two appdomains and have the library do whatever stuff you need. It's all in-memory, not network communication or anything. Although a lot of resources will recommend network communication between them, but I doubt they need any kind of performance when doing so.

Some quick examples of spawning a new appdomain and loading an arbitrary library into it:
http://blogs.msdn.com/b/kirillosenk...applications-in-process-using-appdomains.aspx
http://stackoverflow.com/questions/3843421/how-to-call-a-method-of-a-class-from-another-appdomain
http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx
Back to this...because two appdomains spawn inside the same process, I would have to create a new thread to run the voice recognition stuff simultaneously with the main program, right? Should I just use Process.Start() instead, and use pipes for cross-process communication?
 

usea

Member
Back to this...because two appdomains spawn inside the same process, I would have to create a new thread to run the voice recognition stuff simultaneously with the main program, right? Should I just use Process.Start() instead, and use pipes for cross-process communication?
It doesn't have to be in a separate thread. You can call stuff in the second appdomain from the first one, and the calls will be on the executing thread.

Some overview pages:
Application Domain wiki article
Application Domains (msdn)
Application Domains and Threads (msdn)

They're basically just a separately managed memory area in the same process. You can't directly call code in a separate domain, but you can do it via marshalling.
 
This was a question on the first quiz in Intro to Comp Sci (6.00) at MIT (Spring 2011):

Code:
# Given 

def f(s):
    assert type(s) == str and len(s) > 0
    if len(s) == 1:
        return s
    else:
        return f(f(s[1:])) + s[0]

# what is the output of 

print f('mat')
print f('math')

Solve it on paper, of course. It's my understanding that the average grade for that quiz was... not very good.

This would make a decent whiteboard question at a job interview. Personally, I'd use something like this to get accustomed to writing/talking through recursive problems.
 

Feep

Banned
I'd love to help you out with this Feep (especially since I assume this is for There Came an Echo?) but I don't think I have the time. Do you just want to call existing functions in the windows SAPI or do you need a more robust interface?
It is for TCAE.

I'm messing around with separate processes/AppDomains now. I've made some good progress...almost got it, I think...
 

Slavik81

Member
Is there some way to translate this to C/C++ or should I just learn C#? Would love to get better at recursion.
I haven't tested this, but I believe it's equivalent.
Code:
#include <iostream>
#include <string>
#include <cassert>

// Given 
std::string f(std::string s) {
   assert(s.size() > 0);
   if(s.size() ==  1) 
      return s;
   else 
      return f(f(s.substr(1))) + s[0];
}

// what is the output of 
int main() {
   std::cout << f("mat") << std::endl;
   std::cout << f("math") << std::endl;
}
 

robox

Member
rant: trying to land another job after getting laid off a few weeks back. can't get anything, and only blaming myself. getting frustrated and depressed for being too dumb. thinking i should take a step back and brush up instead of rushing into tech interviews where i've just been fumbling around.
 
I haven't tested this, but I believe it's equivalent.
Code:
#include <iostream>
#include <string>
#include <cassert>

// Given 
std::string f(std::string s) {
   assert(s.size() > 0);
   if(s.size() ==  1) 
      return s;
   else 
      return f(f(s.substr(1))) + s[0];
}

// what is the output of 
int main() {
   std::cout << f("mat") << std::endl;
   std::cout << f("math") << std::endl;
}

I can confirm it works splendidly.

Interestingly enough the word 'test' results in 'test'

lSWbaQ3.png


[edited for argv[1] instead of a string literal]
 
I haven't tested this, but I believe it's equivalent.
Code:
#include <iostream>
#include <string>
#include <cassert>

// Given 
std::string f(std::string s) {
   assert(s.size() > 0);
   if(s.size() ==  1) 
      return s;
   else 
      return f(f(s.substr(1))) + s[0];
}

// what is the output of 
int main() {
   std::cout << f("mat") << std::endl;
   std::cout << f("math") << std::endl;
}

Thank you so much. You guys are the best.
 
Who wants to talk about ruby on rails? Its the only thing I want to work in but at work I have to do .net and C# and my network class is in C :(. I love ruby.
 

moka

Member
Who wants to talk about ruby on rails? Its the only thing I want to work in but at work I have to do .net and C# and my network class is in C :(. I love ruby.

I've been thinking about signing up to one of the Ruby on Rails classes there are out there. It's what all the cool kids are doing nowadays and from what I've seen, can be utilised to produce powerful applications.

I'm fairly good with PHP but I could do with learning something new. May give it a shot just as soon as my exams are over.
 

Magni

Member
Who wants to talk about ruby on rails? Its the only thing I want to work in but at work I have to do .net and C# and my network class is in C :(. I love ruby.

I'm a software engineering student, and almost my classes/projects are in C or Java, but last semester I did an 8-month co-op in a startup on a Rails app. It's so hard going back to Java (I have a JEE course this semester, so Rails only more verbose and uglier and slower to code) after Ruby.
 
rant: trying to land another job after getting laid off a few weeks back. can't get anything, and only blaming myself. getting frustrated and depressed for being too dumb. thinking i should take a step back and brush up instead of rushing into tech interviews where i've just been fumbling around.

Get a whiteboard if possible and practice practice practice. If that's not possible, pen and paper practice. Think of any possible interviewer questions you can, also search on-line.

Good luck.
 
rant: trying to land another job after getting laid off a few weeks back. can't get anything, and only blaming myself. getting frustrated and depressed for being too dumb. thinking i should take a step back and brush up instead of rushing into tech interviews where i've just been fumbling around.

Get a whiteboard if possible and practice practice practice. If that's not possible, pen and paper practice. Think of any possible interviewer questions you can, also search on-line.

Good luck.

This, and I highly recommend buying this if you can.

http://www.amazon.com/dp/098478280X/?tag=neogaf0e-20

there are some really good examples from places like google, facebook, microsoft, etc.
 

Aleph

Member
Yeah new milestone in minor project.

Homogeneous line clipping took way more work to implement a good enough working version. And it still has some bordercases where it falls short :(



/sucks at math and reading :(

Looks interesting, are you learning Direct3D/OpenGL by any chance?

Edit:

Wanted to share an interesting exercise I saw at data structure and algorithms class: create a class Queue<T> (in Java) that only uses (the minimum possible amount of) stacks in it's implementation (that is, you can't have any other variables). Implement the methods: add(T element), remove(), isEmpty(). Once you figure it out it's very easy.
 
Wanted to share an interesting exercise I saw at data structure and algorithms class: create a class Queue<T> (in Java) that only uses (the minimum possible amount of) stacks in it's implementation (that is, you can't have any other variables). Implement the methods: add(T element), remove(), isEmpty(). Once you figure it out it's very easy.

I vaguely remember doing something like that earlier in the semester. I believe you can maintain it by utilizing 2 stacks and adding(pushing) and removing(popping) were dependent on which stack you were using.

I could be mixing it up with something else. We covered it under stacks (at the very beginning) and not queues (and my brain is fried from a quiz I just took for a similar class on red-black trees).
 
I've been thinking about signing up to one of the Ruby on Rails classes there are out there. It's what all the cool kids are doing nowadays and from what I've seen, can be utilised to produce powerful applications.

I'm fairly good with PHP but I could do with learning something new. May give it a shot just as soon as my exams are over.

Ruby on Rails is awesome. I would suggest learning ruby before moving onto rails. Helps with the whole learning process. Rails is a lot different than pure ruby.

I'm a software engineering student, and almost my classes/projects are in C or Java, but last semester I did an 8-month co-op in a startup on a Rails app. It's so hard going back to Java (I have a JEE course this semester, so Rails only more verbose and uglier and slower to code) after Ruby.

I haven't done Java in years and from what I can remember it is ugly as sin.

It spoiled me. I can't go back to anything else now. Even Python looks ugly to me (but I can handle it).

I like Python but I can see where it looks uglier. They are both useful I just really enjoy the breadth and depth of ruby. Its just fun to use.
 
Yeah new milestone in minor project.

Homogeneous line clipping took way more work to implement a good enough working version. And it still has some bordercases where it falls short :(

/sucks at math and reading :(

Software renderer? Very cool for a school project. I remember having trouble getting the line clipped perfectly which lead to me writing to some random memory outside of the frame buffer -> crash
 

hateradio

The Most Dangerous Yes Man
Python would be much nicer if it were more syntactic, or if objects just had built in methods to make it a bit more like other OO languages. (ie len(something) vs something.length)

Who wants to talk about ruby on rails? Its the only thing I want to work in but at work I have to do .net and C# and my network class is in C :(. I love ruby.
Ruby's awesome, and Rails is quite useful. I don't think there's an easier way to build a unique, custom web application without it. I guess you should try to check out C#'s MVC and Entity stuff though.



Recently I've been getting into Scala, which is like writing Ruby on a different level.

Ruby's really easy to understand and use, but I feel like I need to learn more about Scala to apply it properly. But there are a few areas where I can see some of Ruby's inefficiencies and where Scala's ability to use types and compile can come in handy. Not to mention that it can pair up with Java without any pain. (I'm not sure about its status with C#.)

. . . which reminds me, anyone here use SBT?
 

Chris R

Member
Been messing around with PHP and Ruby since asp.net has been giving me fits when it comes to RESTful stuff (400/401 errors everywhere :<)

They are pretty cool though, I'm thinking of continuing to use them on my own to build up my skills with them. Is there anything like Code Academy for PHP? The Ruby stuff has seemed alright so far.
 

soco

Member
Been messing around with PHP and Ruby since asp.net has been giving me fits when it comes to RESTful stuff (400/401 errors everywhere :<)

They are pretty cool though, I'm thinking of continuing to use them on my own to build up my skills with them. Is there anything like Code Academy for PHP? The Ruby stuff has seemed alright so far.

I'd really suggest you at least check out python. I've stuck with PHP for years, but I'm now switching all of my web dev stuff to python & django stuff. Django + TastyPie makes simple REST apis a piece of cake.
 

squidyj

Member
Looks interesting, are you learning Direct3D/OpenGL by any chance?

Edit:

Wanted to share an interesting exercise I saw at data structure and algorithms class: create a class Queue<T> (in Java) that only uses (the minimum possible amount of) stacks in it's implementation (that is, you can't have any other variables). Implement the methods: add(T element), remove(), isEmpty(). Once you figure it out it's very easy.

I would probably have 2 stacks, you add on one stack and you remove from the other, if the remove stack is empty and the add stack is not you pop all of the values off the add stack and push them onto the remove stack, thus reversing their order.

for each element added you would wind up pushing it onto the add stack once, popping it from the add stack once, pushing it onto the remove stack once and popping it from the remove stack once, it's not ideal but at least the complexity is fine.
 
Top Bottom