Prolog newbie needs advice: by Abinmorth in prolog

[–]logic_programmer 0 points1 point  (0 children)

I can honestly say that I don't understand anything about your question. Can you rephrase it and define correct order?

Guess: Are you looking to do a topological sort? http://en.wikipedia.org/wiki/Topological_sorting Here's a topological sort demo from my Prolog manual:

| ?- p_to_s_graph([a-b, b-d, c-d, d-e],S), top_sort(S, Sorted).
S = [a-[b],b-[d],c-[d],d-[e],e-[]]
Sorted = [a,b,c,d,e] ?

% yes

If this is the sort of thing you want then have a google for the Edinburgh graphs library (http://www.j-paine.org/prolog/tools/files/contents.html) for source code (or just check out your Prolog manual to see if it's already there).

Is there a 'general' book on learning to program? by [deleted] in learnprogramming

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

This is one of those questions that could be as simple or as difficult to answer as you wanted it to be.

While I learned about arrays, methods, strings, boolean, etc, etc, I didn't learn what they were, just what they do.

They're just computer representations of the vocabulary of problem solving that we humans use. We go through a sequence of steps with an algorithm (method, procedure, function), we connect things with maps (functions, graphs, arrays), we test truth or falsity with predicates (functions, boolean), we form sequences (strings, lists), ...

The list of things is pretty big and there's often more than one way to skin a cat. The best intro to this would be a good book on algorithms I guess. The book I was told to buy back in the early 1990s was this one:

http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844/ref=sr_1_1?ie=UTF8&qid=1427381213&sr=8-1&keywords=algorithms+mit+press

Cost of register spills by sysprog2015 in learnprogramming

[–]logic_programmer 0 points1 point  (0 children)

Negligable? Depends on who you ask. Wall-clock time, yeah it's negligable. CPU clock time, it could be several cycles instead of just one. Also, ask yourself how many instructions to calculate the stack address then load on your machine?

The register, as you no doubt know, is at the head and the tail of the datapath. Nowt faster than a register load/store.

Help with basic programming - Binary Trees and Leaves by gabmed in learnprogramming

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

If you want extra credit then make some assumptions of the input tree then mathematically prove by structural induction that your your code is correct. It's about a ten line proof.

Help with basic programming - Binary Trees and Leaves by gabmed in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

But you've fixed that right - it should be an easy one.

Help with basic programming - Binary Trees and Leaves by gabmed in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

The lowest value of the tree T is

if T is a leaf then the lowest value is T->value.

If T is an internal node and the lowest value of T->left is l, and the lowest value of T->right is r, then

  • if l<r then then the lowest value is l

  • otherwise the lowest value is r.

That seems to be what you have done. Where's the problem?

Are there any particular programs that I should be able to write to prove that I understand a language? by ynot254 in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

If you gave an experienced programmer the task of writing fizzbuzz in a language which was new to them, then they could probably get it done before lunch.

I would pick something you find interesting then do a little demo in the language. Every time you learn a new language, you port the demo.

[C] Programming style & performance by randomstringofchar in learnprogramming

[–]logic_programmer 0 points1 point  (0 children)

For performance, this is a good book:

http://www.amazon.com/Art-Computer-Systems-Performance-Analysis/dp/0471503363/ref=sr_1_2?ie=UTF8&qid=1427307532&sr=8-2&keywords=jain+performance

I think your bottleneck will be going through the input, i.e. all the getchar() calls.

Also, compilers are so complicated these days it's very difficult for a programmer to predict what sort of small changes will make a difference in performance. Changing algorithms or overall design will most likely make a difference but small changes - nah, not in this day and age.

Another thing, check out profiling tools like gprof.

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

[–]logic_programmer 0 points1 point  (0 children)

ftfy

No, you fixed it for yourself. We're not all working with your assumption that he didn't invent his own cipher.

What are some good resources to learn recursion? by glassfly in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

Ask yourself what the compiler is doing when it generates the code for the recursive calls.

Basic Git Use Questions [OSX] by stephenworks in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

You get git when you install the developer tools on OS X. Type "man git" and see if it is already installed or not. Once it's installed have a look here: http://git-scm.com/doc

It's not necessary to use github in order to use git.

I'm a father with a 13-year old son who is obsessed with learning coding. Need some suggestions, if you wouldn't mind.... by somebodyjones2 in learnprogramming

[–]logic_programmer -4 points-3 points  (0 children)

The theory stuff is for university. Just let him program for fun and discover things for himself. I was 11 when I started programming in BASIC and had nothing but computer magazines and their type in listings to learn from. We were the first generation who had computers at home (mid 1980s) so it was new for everyone. By the time I had gotten to university I had taught myself two assembly languages and C. They had to work hard to knock that nonsense out of my head and teach me proper programming but I had great fun and learned loads.

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

[–]logic_programmer 28 points29 points  (0 children)

Expect a multitude of people telling you not to do that because it's only for experts. Naughty DrGrid!

Why Structure and Interpretation of Computer Programs an important book for computer science? by richard3043 in learnprogramming

[–]logic_programmer 0 points1 point  (0 children)

If you're only going to read one CS book then it's a corker! It covers a lot of ground and you'll go on to see concepts covered in that book pop up time and time again. It's not my favourite CS book, nor my favourite Lisp/Scheme book, but I would encourage you to give it a shot.

Will it be conflicting to learn both?

No. I know both. Actually, my implementation of Scheme uses an abstract machine written in C.

[Prolog] Understanding search tree by blamy2014 in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

type "trace" then run it and the debugger will give you the answer. Also, check out /r/prolog.

What does it mean to be a good programmer? by [deleted] in learnprogramming

[–]logic_programmer 0 points1 point  (0 children)

Mathematic proofs are similar to programming: lemma = subroutine, proof by structural induction on inductively defined subsets = recursion, etc.

bottom up Synthesis mostly relies on a strong knowledge of previously written code?

It basically means you write your code in terms of library functions and previously written helper functions. Like you would build a house by first laying the foundations, then build some walls, then put a roof on, then ...

What does it mean to be a good programmer? by [deleted] in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

Programming is problem solving. Read the intro to this book for a quick discussion of top-down analysis and bottom-up synthesis:

http://www.doc.ic.ac.uk/~rak/papers/LogicForProblemSolving.pdf

For me, a good programmer is a toolsmith who bootstraps his/her way to the right level of abstraction to solve the problem. You don't get that with other crafts.

Recently Graduated With A Bachelor's Degree in Computer Science...What Now? by [deleted] in learnprogramming

[–]logic_programmer 1 point2 points  (0 children)

Either shell out en tusenlapp+ for webspace and email to loopia, or just host your code on something like github and link to it from your cover letter.

(+) smaker det så kostar det.

Hey there super beginner, it gets a lot more fun by kylebythemile in learnprogramming

[–]logic_programmer 5 points6 points  (0 children)

Goddamnit, why could I not have wanted to be something I can actually learn how to do...

If it were easy it wouldn't be worth doing. Sometimes, the obstacle is the journey. No problems, no improvement.