|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On February 16 2013 19:42 tec27 wrote: ...
Programming skill is the single most important thing for being hired by any software company. Any theoretical stuff you actually need will come up naturally and you can learn it then; no point in wasting your time learning things just because you might need them "some day". Here's my advice to anyone still in school wondering how they should spend their time: Skip all of your classes,
....
I don't necessarily think you are wrong in this statement, but I'm not sure it holds for everyone. "Useless Theoretical knowledge" is tricky to value properly. It depends as always on context. For instance, I spent a semester on learning compilers, context free languages and such. While it didn't help me at the time, a few years later suddenly the pieces fell together. It changed my whole viewpoint at some of our projects at work, how I can solve certain problems. This would never have happened if I'd follow the get rich quick scheme. Why would I ever need to be able to build my own compiler, now I know.
Is this worth two or three years at the University, perhaps not. Does it make me more easily employed, perhaps not. But I know that I wouldn't want to be without the knowledge. It doesn't make me a better person, but it made me a better programmer. So I would rather say, if you're to continue at the University make sure you understand the classes you're taking, rather than just passing the exams. Getting a piece of paper that you cannot back up with understanding is a waste. Try to get some real life experience as well, because the clock ticks at different speeds in academics and in business.
|
Dude. Why should we do your internet searching for you? You know, you also could actually try to learn something and create the algorithm yourself.
|
On February 16 2013 21:23 supereddie wrote:Dude. Why should we do your internet searching for you? You know, you also could actually try to learn something and create the algorithm yourself.
Dude. I tried before asking. Not everyone is brilliant in programming, you know.
|
Then you need to be more specific about what you've tried and where you've become stuck, instead of asking generic questions.
|
On February 16 2013 21:46 darkness wrote:Show nested quote +On February 16 2013 21:23 supereddie wrote:Dude. Why should we do your internet searching for you? You know, you also could actually try to learn something and create the algorithm yourself. Dude. I tried before asking. Not everyone is brilliant in programming, you know. It's not about being knowledgeable or wise enough: it's about trying things yourself and not being lazy if you wish to do something. If you come up with a problem then, people can help, most likely not like this.
|
All this discussion about CS degrees seems very much to depend on personality, and the balance of theoretical vs. practical you need while learning.
I hated college because learning for the sake of learning just doesn't suit me; I like to build real products. After dropping out from several different colleges and feeling miserable I just went for a quick 1-year degree (not even in CS, was Automation) then got a job and felt much better. But now, a few years down the road, I find myself learning on my own the CS basics that I never studied in college, because I feel that there might be a big potential there to make me a better programmer. I'm currently reading a book about algorithms and data structures and enjoying it much more than I ever would have in college, because I can now see directly how what I learn could help me in my daily job.
If on the other hand you're more like the guy a few posts above who can stomach learning all about compilers, and only finding out a few years later how to actually make use of it (I'm genuinely happy for you :D), then a CS degree seems a great option. Sadly, I haven't had a great track record using this strat, spent two years doing 5hrs math + 3 hrs physics daily and the returns I've got on it in real life so far have been abysmal and I've forgotten most of it by now so future returns are even less likely.
|
Hyrule19174 Posts
|
Sure! I had to make it output a string, because that was the only way to make it work with a potentially infinite series but still contain a decimal point.
import Data.Char (intToDigit)
toListOfDigits :: Int -> [Int] -> [Int] toListOfDigits 0 [] = [0] toListOfDigits 0 xs = xs toListOfDigits x xs = toListOfDigits (quot x 10) ((mod x 10) : xs)
longDiv :: Int -> Int -> [Char] longDiv divisor dividend = dropWhile (=='0') $ longDiv2 divisor (toListOfDigits dividend []) 0
longDiv2 :: Int -> [Int] -> Int -> [Char] longDiv2 _ [] 0 = [] longDiv2 divisor [] remainder = '.' : fractionalLongDiv2 divisor remainder longDiv2 divisor (x:xs) remainder = (intToDigit $ quot y divisor) : longDiv2 divisor xs (mod y divisor) where y = (10 * remainder) + x
fractionalLongDiv2 :: Int -> Int -> [Char] fractionalLongDiv2 _ 0 = [] fractionalLongDiv2 divisor remainder = (intToDigit $ quot y divisor) : fractionalLongDiv2 divisor (mod y divisor) where y = 10 * remainder
Note, this code will happily continue to calculate infinite series, but because it is calculating lazily, you can tell it to stop any time you want.
longDiv 3 1 <-- will keep calculating .333333333... etc forever take 5 $ longDiv 3 1 <--- will return .3333
If you want a specific number of decimal places, you could do this:
decimalPlaces Int -> [Char] -> [Char] decimalPlaces y str = a ++ (take (y + 1) b) where (a, b) = span (/='.') str
That way,
decimalPlaces 5 $ longDiv 3 8 <--- will return "2.66666"
There's probably a smarter way to do all this, but I'm pretty new to Haskell so that'll have to do for now.
Hope this helps!
|
@Matoo- If I were you I would try to worry less about the direct returns of the education you've got so far, and more on the fact that you've made it through that amount of math, which I know I wouldn't. And the knowledge isn't gone, it's just dormant. It'll creep up on you one day, it'll be there lurking and sneaking. Just you wait ...
--
The other thing about University is the other, you know, social aspect. You can have fun learning with friends, meeting new people, chasing girls, growing up and so on. Rather than spending time arguing with that smug bastard in the cubicle next door who is full of himself, and has a better salary than me. Not to mention the boss who's ...
(Of course it could be the other way around too, avoiding those stupid class mates, and instead hang down the strip club with my ample heaps of money).
|
On February 16 2013 22:38 carlfish wrote:+ Show Spoiler +Sure! I had to make it output a string, because that was the only way to make it work with a potentially infinite series but still contain a decimal point. import Data.Char (intToDigit)
toListOfDigits :: Int -> [Int] -> [Int] toListOfDigits 0 [] = [0] toListOfDigits 0 xs = xs toListOfDigits x xs = toListOfDigits (quot x 10) ((mod x 10) : xs)
longDiv :: Int -> Int -> [Char] longDiv divisor dividend = dropWhile (=='0') $ longDiv2 divisor (toListOfDigits dividend [] 0
longDiv2 :: Int -> [Int] -> Int -> [Char] longDiv2 _ [] 0 = [] longDiv2 divisor [] remainder = '.' : fractionalLongDiv2 divisor remainder longDiv2 divisor (x:xs) remainder = (intToDigit $ quot y divisor) : longDiv2 divisor xs (mod y divisor) where y = (10 * remainder) + x
fractionalLongDiv2 :: Int -> Int -> [Char] fractionalLongDiv2 _ 0 = [] fractionalLongDiv2 divisor remainder = (intToDigit $ quot y divisor) : fractionalLongDiv2 divisor (mod y divisor) where y = 10 * remainder
Note, this code will happily continue to calculate infinite series, but because it is calculating lazily, you can tell it to stop any time you want. longDiv 3 1 <-- will keep calculating .333333333... etc forever take 5 $ longDiv 3 1 <--- will return .3333
If you want a specific number of decimal places, you could do this: decimalPlaces Int -> [Char] -> [Char] decimalPlaces y str = a ++ (take (y + 1) b) where (a, b) = span (/='.') str
That way, decimalPlaces 5 $ longDiv 3 8 <--- will return "2.66666"
There's probably a smarter way to do all this, but I'm pretty new to Haskell so that'll have to do for now. Hope this helps!
Thanks. I haven't compiled a Haskell program before, but I've written:
ghc -o test test.hs
I got an error tho:
[1 of 1] Compiling Main ( test.hs, test.o )
test.hs:16:1: parse error (possibly incorrect indentation)
Is there anything that I did wrong or is it just code?
|
On February 16 2013 23:32 darkness wrote:Show nested quote +On February 16 2013 22:38 carlfish wrote:+ Show Spoiler +Sure! I had to make it output a string, because that was the only way to make it work with a potentially infinite series but still contain a decimal point. import Data.Char (intToDigit)
toListOfDigits :: Int -> [Int] -> [Int] toListOfDigits 0 [] = [0] toListOfDigits 0 xs = xs toListOfDigits x xs = toListOfDigits (quot x 10) ((mod x 10) : xs)
longDiv :: Int -> Int -> [Char] longDiv divisor dividend = dropWhile (=='0') $ longDiv2 divisor (toListOfDigits dividend [] 0
longDiv2 :: Int -> [Int] -> Int -> [Char] longDiv2 _ [] 0 = [] longDiv2 divisor [] remainder = '.' : fractionalLongDiv2 divisor remainder longDiv2 divisor (x:xs) remainder = (intToDigit $ quot y divisor) : longDiv2 divisor xs (mod y divisor) where y = (10 * remainder) + x
fractionalLongDiv2 :: Int -> Int -> [Char] fractionalLongDiv2 _ 0 = [] fractionalLongDiv2 divisor remainder = (intToDigit $ quot y divisor) : fractionalLongDiv2 divisor (mod y divisor) where y = 10 * remainder
Note, this code will happily continue to calculate infinite series, but because it is calculating lazily, you can tell it to stop any time you want. longDiv 3 1 <-- will keep calculating .333333333... etc forever take 5 $ longDiv 3 1 <--- will return .3333
If you want a specific number of decimal places, you could do this: decimalPlaces Int -> [Char] -> [Char] decimalPlaces y str = a ++ (take (y + 1) b) where (a, b) = span (/='.') str
That way, decimalPlaces 5 $ longDiv 3 8 <--- will return "2.66666"
There's probably a smarter way to do all this, but I'm pretty new to Haskell so that'll have to do for now. Hope this helps! Thanks. I haven't compiled a Haskell program before, but I've written: ghc -o test test.hs I got an error tho: [1 of 1] Compiling Main ( test.hs, test.o ) test.hs:16:1: parse error (possibly incorrect indentation) Is there anything that I did wrong or is it just code?
I'm guessing it could possibly be the indentation on line 16 of test.hs
|
On February 17 2013 01:10 JeanLuc wrote:Show nested quote +On February 16 2013 23:32 darkness wrote:On February 16 2013 22:38 carlfish wrote:+ Show Spoiler +Sure! I had to make it output a string, because that was the only way to make it work with a potentially infinite series but still contain a decimal point. import Data.Char (intToDigit)
toListOfDigits :: Int -> [Int] -> [Int] toListOfDigits 0 [] = [0] toListOfDigits 0 xs = xs toListOfDigits x xs = toListOfDigits (quot x 10) ((mod x 10) : xs)
longDiv :: Int -> Int -> [Char] longDiv divisor dividend = dropWhile (=='0') $ longDiv2 divisor (toListOfDigits dividend [] 0
longDiv2 :: Int -> [Int] -> Int -> [Char] longDiv2 _ [] 0 = [] longDiv2 divisor [] remainder = '.' : fractionalLongDiv2 divisor remainder longDiv2 divisor (x:xs) remainder = (intToDigit $ quot y divisor) : longDiv2 divisor xs (mod y divisor) where y = (10 * remainder) + x
fractionalLongDiv2 :: Int -> Int -> [Char] fractionalLongDiv2 _ 0 = [] fractionalLongDiv2 divisor remainder = (intToDigit $ quot y divisor) : fractionalLongDiv2 divisor (mod y divisor) where y = 10 * remainder
Note, this code will happily continue to calculate infinite series, but because it is calculating lazily, you can tell it to stop any time you want. longDiv 3 1 <-- will keep calculating .333333333... etc forever take 5 $ longDiv 3 1 <--- will return .3333
If you want a specific number of decimal places, you could do this: decimalPlaces Int -> [Char] -> [Char] decimalPlaces y str = a ++ (take (y + 1) b) where (a, b) = span (/='.') str
That way, decimalPlaces 5 $ longDiv 3 8 <--- will return "2.66666"
There's probably a smarter way to do all this, but I'm pretty new to Haskell so that'll have to do for now. Hope this helps! Thanks. I haven't compiled a Haskell program before, but I've written: ghc -o test test.hs I got an error tho: [1 of 1] Compiling Main ( test.hs, test.o ) test.hs:16:1: parse error (possibly incorrect indentation) Is there anything that I did wrong or is it just code? I'm guessing it could possibly be the indentation on line 16 of test.hs
Wow that's a pretty wild guess but I'm gonna go ahead with him on this one.
|
On February 16 2013 23:32 darkness wrote:Show nested quote +On February 16 2013 22:38 carlfish wrote:+ Show Spoiler +Sure! I had to make it output a string, because that was the only way to make it work with a potentially infinite series but still contain a decimal point. import Data.Char (intToDigit)
toListOfDigits :: Int -> [Int] -> [Int] toListOfDigits 0 [] = [0] toListOfDigits 0 xs = xs toListOfDigits x xs = toListOfDigits (quot x 10) ((mod x 10) : xs)
longDiv :: Int -> Int -> [Char] longDiv divisor dividend = dropWhile (=='0') $ longDiv2 divisor (toListOfDigits dividend [] 0
longDiv2 :: Int -> [Int] -> Int -> [Char] longDiv2 _ [] 0 = [] longDiv2 divisor [] remainder = '.' : fractionalLongDiv2 divisor remainder longDiv2 divisor (x:xs) remainder = (intToDigit $ quot y divisor) : longDiv2 divisor xs (mod y divisor) where y = (10 * remainder) + x
fractionalLongDiv2 :: Int -> Int -> [Char] fractionalLongDiv2 _ 0 = [] fractionalLongDiv2 divisor remainder = (intToDigit $ quot y divisor) : fractionalLongDiv2 divisor (mod y divisor) where y = 10 * remainder
Note, this code will happily continue to calculate infinite series, but because it is calculating lazily, you can tell it to stop any time you want. longDiv 3 1 <-- will keep calculating .333333333... etc forever take 5 $ longDiv 3 1 <--- will return .3333
If you want a specific number of decimal places, you could do this: decimalPlaces Int -> [Char] -> [Char] decimalPlaces y str = a ++ (take (y + 1) b) where (a, b) = span (/='.') str
That way, decimalPlaces 5 $ longDiv 3 8 <--- will return "2.66666"
There's probably a smarter way to do all this, but I'm pretty new to Haskell so that'll have to do for now. Hope this helps! Thanks. I haven't compiled a Haskell program before, but I've written: ghc -o test test.hs I got an error tho: [1 of 1] Compiling Main ( test.hs, test.o ) test.hs:16:1: parse error (possibly incorrect indentation) Is there anything that I did wrong or is it just code?
The code is fine. Haskell is layout-sensitive. In particular, the where clauses on longDiv2 and fractionaLongDiv2 need to be indented relative to its adjoining definition. If you copy-paste exactly what you have in your text buffer, it'll be easier to diagnose.
|
I'm looking to start learning the .NET Framework ( C++ and/or C# ), starting out with building basic console applications. For a while now I've been trawling around the MSDN site looking for ANYTHING about include libraries, DLL Pre-Build commands ect but I can't find any info on using a .NET class in VC++ 2010 / VC# 2010.
I have no idea how to even get these .NET classes recognised by Visual Studios.
It's probably me being stupid but I am clearly missing something, maybe I'm not understanding how development with .NET works?
Any suggestions/ input would be appreciated.
|
On February 17 2013 02:54 BADBADNOTGOOD wrote: I'm looking to start learning the .NET Framework ( C++ and/or C# ), starting out with building basic console applications. For a while now I've been trawling around the MSDN site looking for ANYTHING about include libraries, DLL Pre-Build commands ect but I can't find any info on using a .NET class in VC++ 2010 / VC# 2010.
I have no idea how to even get these .NET classes recognised by Visual Studios.
It's probably me being stupid but I am clearly missing something, maybe I'm not understanding how development with .NET works?
Any suggestions/ input would be appreciated.
If you are learning the .NET framework, then you should be restricting yourself to C#. What do you mean by getting VS to recognize your classes? The library-and-build model for C# (to a first-order approximation) is much saner and cleaner than native code (which is sounds like where you are coming from). Can you give a concrete example of what you'd like to do as your initial statement is rather vague.
|
On February 17 2013 03:10 Kambing wrote:Show nested quote +On February 17 2013 02:54 BADBADNOTGOOD wrote: I'm looking to start learning the .NET Framework ( C++ and/or C# ), starting out with building basic console applications. For a while now I've been trawling around the MSDN site looking for ANYTHING about include libraries, DLL Pre-Build commands ect but I can't find any info on using a .NET class in VC++ 2010 / VC# 2010.
I have no idea how to even get these .NET classes recognised by Visual Studios.
It's probably me being stupid but I am clearly missing something, maybe I'm not understanding how development with .NET works?
Any suggestions/ input would be appreciated.
If you are learning the .NET framework, then you should be restricting yourself to C#. What do you mean by getting VS to recognize your classes? The library-and-build model for C# (to a first-order approximation) is much saner and cleaner than native code (which is sounds like where you are coming from). Can you give a concrete example of what you'd like to do as your initial statement is rather vague.
I think he just means he can't get his environment setup properly to build.
|
On February 17 2013 03:10 Kambing wrote:Show nested quote +On February 17 2013 02:54 BADBADNOTGOOD wrote: I'm looking to start learning the .NET Framework ( C++ and/or C# ), starting out with building basic console applications. For a while now I've been trawling around the MSDN site looking for ANYTHING about include libraries, DLL Pre-Build commands ect but I can't find any info on using a .NET class in VC++ 2010 / VC# 2010.
I have no idea how to even get these .NET classes recognised by Visual Studios.
It's probably me being stupid but I am clearly missing something, maybe I'm not understanding how development with .NET works?
Any suggestions/ input would be appreciated.
If you are learning the .NET framework, then you should be restricting yourself to C#. What do you mean by getting VS to recognize your classes? The library-and-build model for C# (to a first-order approximation) is much saner and cleaner than native code (which is sounds like where you are coming from). Can you give a concrete example of what you'd like to do as your initial statement is rather vague.
Lets say I literally only want access to the System namespace (http://msdn.microsoft.com/en-gb/library/system.aspx) What headers do I need to use? What libraries do I need to use? How do you set up a VS project to recognise this .NET Framework namespace?
I'm sure I'm just completely overlooking something or missed the page on Getting Started where it mentions this but everyone who talks about using .NET seems to skip mentioning any of this.
Hope that's clearer.
|
Start a new C# project in visual studio from the new project guide. Problem solved, or what on earth are you trying to do?
Edit: You have included libraries under "references" in the solution explorer. Normally System is included (or mscorlib) if you're using .NET 2.0. But I'm recommending using 4.0 or later because of the added functionality.
Anyway, you have the same system as in java where you can use "using System.ComponentModel; " in the header, or you can use full namespace in the code, depending on your style. such as:
using System.Xml; // All namespaces and classes in this file namespace MyApp { using System.ComponentModel; // All classes in this namespace public class MyClass{ public void Main(){ System.Data.DataTable mytable = new System.Data.DataTable("mytable"); // Only here. } } }
Normally you load them using add reference and allow copy local in the properties dialog for the reference. I.e. dlls will be placed in program dir).
|
Could you translate and simplify this one into Java please?
var digit = i < numLength ? parseInt(num[i]) : 0;
My guess is:
int digit;
if (i < numLength) digit = num[i]; else digit = 0;
Is this correct?
|
int digit = (i < numLength) ? num[i] : 0;
Edit: Oh yea, thats correct, but the above also works.
|
|
|
|
|
|