/dpt/ - Daily Programming Thread

prev: What are you working on, Sup Forums?

Other urls found in this thread:

tour.golang.org
jsfiddle.net/y0a8aku4/2/
twitter.com/SFWRedditVideos

First for Idris

that's a cat

Very good observation.

"The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages." -Richard Stallman

Did you just assume xir's species, you shitlord?!

This is Falcon's stringent retard litmus test for his new hires for logical increments.

How would you fare if this was given to you in a technical interview?

>Richard Stallman
Jeg sluttet å lese der.

Learn Go
tour.golang.org

>the only languages are C, C++, Java, and Python
Trash.

How much does he pay? I could ace his test but a mod position doesn't pay the bills.

why would anyone use sublime text when notepad++ exists?

He describes his pay as "reasonable middle class malaysian salary"

He's only ever had 2 people pass his test and they both passed up his job offer because the salary was too low.

My question is why anyone would use either when emacs or vim exists

>How would you fare if this was given to you in a technical interview?
I'd fail.

Then he should lower his requirements and/or increase the salary.

With questions like that I doubt he can program, to be honest.

It's an anime cat, from normie anime. In my mind it pleased everybody.

This isn't reddit.

It's OK

>With questions like that I doubt he can program, to be honest.

It certainly appears that way. He's asking for people to recall things like A* for an position that has nothing to do with programming.

I actually didn't care and chose something at random, you don't have to be a dick about it though.

You're right, this isn't reddit

He strikes me as someone who has read a little about programming, but never done it himself.

The coding questions don't seem too hard. The answers to the technical questions depend upon language and implementation (for instance, if we are programming in C on the Arduino, the answer to 4 is "they're the exact same thing"), but shouldn't be difficult to answer. The theory questions would make the interview interesting.

he's literally copying those "daily programming challenge" threads verbatim

> What is malloc

Making a lisp with curly braces.

Good idea.

set-macro-character

I use curly braces for literal strings. Literal strings that MUST be parsed at compile time.

Wrote some shit parser generator(def-yacc ...), and now have things like:

(infix { 2^10 + x * 20 })

Which my parser turns into the appropriate s-exp, although my "yacc" implementation is crap.

Seems like a good idea but need to abstract that shit out of the parser. With a proper parser abstraction including reader and macros I think I could do a lot straight from the language.

I'm trying to resolve the absolute basics I need in the implementation, and what I can do through compile time evaluation.

I like it already.

Programming challenge.

You have 7 baskets which you want to arrange with fruit. There are 8 apples (A), 4 pears (P) and 6 oranges (O). Only one type of fruit can exist in a basket at any one time but each fruit can appear in multiple baskets. Make a program, given a random input state of baskets, print the swap required to get to an input final state?
Example
arrange([ 3A, 0, 2P, 4O, 5A, 2P, 2O ], [4A, 4A, 3O, 3O, 2P, 2P, 0])
# output
1A 4 --> 0
4A 4 --> 1
2P 2 --> 4
1O 3 --> 2
2O 6 --> 2

How bytecode interpreter can be faster than regular language interpreter or JIT-compiler?

>regular language interpreter
Do you mean directly interpreting the typed tree? Simply because there's too much overhead in fetching content on the heap (each node has to be recovered).
>JIT-compiler
Compiling functions has an overhead.

>but each fruit can appear in multiple baskets.
So I can make 28 pears from 4?

A quick question. In C++, will something like:
#define BUFFER_SIZE getnum()

or
#define BUFFER_SIZE_2 BUFFER_SIZE - 1

evaluate the statements at compiletime and use the resulting values directly, or is it inserting it literally, like a macro? Don't feel like making a test case and picking through the assembly. Though it's the only way to know for sure...

A macro in cpp(not C++, the C PreProcessor) is a literal text substitution. Depends on your compiler how the resulting code is interpreted.

should i learn go or rust? rust seems to have their shit more together

I just want a constexpr to work like a macro. For locality.

Can't your pretend it's the 80s and just undef it?

Go

im doing this right now.

if anyone else if whats ur strat

>if anyone else if whats ur strat
What?

Can stack-based machines be fast as register machines?
How slow is Forth compared to assembly language?

sorry I'm retarded.

If anyone else is also doing this problem, what strategy are you using to solve it?

Ignoring all the baskets that don't have any problems seems like the easy part.

I wondering if the remaining is like the bridge crossing problem.

Assembly has nothing to do with it. In 32-bit x86 used to be all over the stack in calling conventions. When x64 came along they finally realized passing arguments on the stack what stupid when you had 10 registers doing fuck all. So now they're passed by register in the modern calling convention.

Fine, all but forth has a stack at the core of the language, forth can't benifit from this optimization.

That said, the calling convention of using registers should have applied way before x64.

Like most of these kinds of problems, if the world "minimum" and "steps" appears, BFS is usually the way to go.

Seems like the branching factor is too high for BFS. Im just making an algorithm that will get a valid solution, even if its shit.

So I've finished Codeacademy's course on Javascript, and am just now making my way through Eloquent Javascript and I'm stuck on the very first exercise.

Can someone take a look at this and explain to me why it's not working?

jsfiddle.net/y0a8aku4/2/

...

Got a solution sort of

A2 1 ---> 0
['3A', '0', '5A', '4O', '2P', '2P', '2O']
A5 2 ---> 0
['8A', '0', '0', '4O', '2P', '2P', '2O']
P2 5 ---> 4
['8A', '0', '0', '4O', '4P', '0', '2O']
O2 6 ---> 3
['8A', '0', '0', '6O', '4P', '0', '0']
A8 0 ---> 6
['0', '0', '0', '6O', '4P', '0', '8A']
A8 6 ---> 0
['8A', '0', '0', '6O', '4P', '0', '0']
O6 3 ---> 1
['8A', '6O', '0', '0', '4P', '0', '0']
P4 4 ---> 2
['8A', '6O', '4P', '0', '0', '0', '0']
O6 1 ---> 3
['8A', '0', '4P', '6O', '0', '0', '0']
P4 2 ---> 4
['8A', '0', '0', '6O', '4P', '0', '0']
A4 0 ---> 1
['4A', '4A', '0', '6O', '4P', '0', '0']
O3 3 ---> 2
['4A', '4A', '3O', '3O', '4P', '0', '0']
P2 4 ---> 5
['4A', '4A', '3O', '3O', '2P', '2P', '0']

Its not minimum path. It maps the input into an intermediate stage where solving it is easy to do.

>tfw to retarded to solve easy tasks
;_;

woops used the wrong inputs on that run. These are the same as yours now.

A5 4 ---> 0
['8A', '0', '2P', '4O', '0', '2P', '2O']
P2 5 ---> 2
['8A', '0', '4P', '4O', '0', '0', '2O']
O2 6 ---> 3
['8A', '0', '4P', '6O', '0', '0', '0']
A8 0 ---> 6
['0', '0', '4P', '6O', '0', '0', '8A']
A8 6 ---> 0
['8A', '0', '4P', '6O', '0', '0', '0']
O6 3 ---> 1
['8A', '6O', '4P', '0', '0', '0', '0']
P4 2 ---> 6
['8A', '6O', '0', '0', '0', '0', '4P']
P4 6 ---> 2
['8A', '6O', '4P', '0', '0', '0', '0']
O6 1 ---> 3
['8A', '0', '4P', '6O', '0', '0', '0']
P4 2 ---> 4
['8A', '0', '0', '6O', '4P', '0', '0']
A4 0 ---> 1
['4A', '4A', '0', '6O', '4P', '0', '0']
O3 3 ---> 2
['4A', '4A', '3O', '3O', '4P', '0', '0']
P2 4 ---> 5
['4A', '4A', '3O', '3O', '2P', '2P', '0']

gambatte!

is this possible to O(1)?

presumably

>What are you working on, Sup Forums?
A gayme with SFML

>Thirty days has September..
India?

I think so

September does have 30 days

but does 30 days also have september

if mySelf.virginAfter30 != 0:
mySelf.destroy()
else:
mySelf.enjoy()

men are fertile well into their fifties

ever since I read about functional programming and 'pure' oop I am not sure how to write my applications anymore.
hold me /dpt/

Forget about pointless things like purely functional and oop. All you need is imperative C.

How's your FizzBuzz project coming along?

But I like my applications readable and organized

do it naturally and without a million years wasted on what kind of diagrams to draw or how this piece connects to that

it should flow intuitively

Is it possible to learn programming alone and make money with it ?

if you devote youself to it, probably.

More like do it how it feels right at the time, 50 hours later figure out why it was bad to do it that way, spend 5 hours fixing it. And that's how you learn. Wikipedia articles aren't going to teach you how to predict future demands and how to comb concepts into effective, modular design, but trying and learning from your mistakes will.

>50 hours later figure out why it was bad to do it that way, spend 5 hours fixing it
that's what happens when you overplan

protip: inheritance does not solve problems

>imperative C
Be more specific than that. "Imperative" is the better term to use.

thanks although I'm talking more about paradigms.
Refactoring from one to another is pretty much rewriting everything

As if you've ever spent 50 hours on a single project in your life.

Do you mean as a software virtual machine or actual hardware?
Implementing a stack based machine model in top if a hardware register machine is obviously gonna require more from your compiler to 'destruct' the stack and map/cache top N-items onto registers, but it's not too difficult, and should be able to achieve similar performance.

For a comparison between the actual hardware: Pros of stack machines is that they are way simpler, require a lot less power and can have extremely fast interrupt response times. Cons are that instruction parallelism is hard to achieve, but you can go the GreenArray route and make hundreds of mini-cores instead, but that puts more onus on the programmer to achieve higher throughput.

...

/dpt/ is right again

Sorry but I'm not a retard.

..learn Rust

>what are you working on
Style manager and updater for StylRRR. Thanks God for Scene Builder.

Some languages are too pure to handle GUI.

Akarin is too pure to be used in such a dirty post

Can I be a game coder if I don't remember trigonometry stuff from school?

>what's the difference between a string and a char[]
C tards absolutely BTFO

Why would you want to be a "game coder"?

>Doesn't even know high-school trigonometry, let alone things like linear algebra
>Posts frogs
>"""coder"""
No. Give up on your dreams.

To make the new Minecraft and get $$$$$$$$$

use strict;
use warnings;
use v5.10;

sub is_leap {
my $year = shift;
my $leap = 0;
if ($year % 4 == 0) { $leap = 1; };
if ($year % 100 == 0) { $leap = 0; };
if ($year % 400 == 0) { $leap = 1; };
return $leap;
}

my @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $count = 0;
my $sundays = 0;

for my $year (1900..2000) {
for my $month (0..11) {
$count += $days[$month];
$count++ if $month == 1 and is_leap($year);
# Mon = 0 .. Sun = 6 .. Sun 13 ... etc.
$sundays++ if $count%7==6 and $year > 1900;
}
}

say $sundays;

>intelligent enough to read perl
>not intelligent enough to write perl

Notch made billions and yet he's still lonely

If you want to make some money, just work at McDonald's or some shit. I'm sure somebody as mentally deficient as you can at least handle that.

Im poor and Im lonely.
Money wouldn't hurt desu

>Money wouldn't hurt
wrong

Wow fucking asshole. Some guy pretended to be employed there and he was unsure about those questions.

They're trivial overall but some of them are ambiguous.

2. Notably. Because you're not told the end condition. (500%13!=0)
Its such a trivial problem with a major Ambiguity. I wouldn't work for a person like that. It'd be spending time with an autist trying to explain to him why you're doing things the right way and why (yes, why) he's not getting it.

What the fuck. I dont even know where to start.

presumably by writing a function to sum the factors of a number

nice solution!

Writing a function that finds the sum of a number's whole divisors would probably be a good place to start, user.

Simple enough