[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 326
Thread images: 33

File: anime.png (786KB, 1000x1300px) Image search: [Google]
anime.png
786KB, 1000x1300px
What are you working on, /g/?

Previous Thread: >>59695514
>>
nth for good image
nth+ 1 for implementing implicit casts in rust.
>>
Post enterprise quality Celsius - Fahrenheit table
use std::ops::{Add, Mul, Div};

fn to_farenheit<T, U>(c: T) -> <<<U as Mul>::Output as Div<U>>::Output as Add<U>>::Output
where T: Into<U>, U: From<i8> + Mul, <U as Mul>::Output: Div<U>, <<U as Mul>::Output as Div<U>>::Output: Add<U> {
c.into() * 9i8.into() / 5i8.into() + 32i8.into()
}

fn main() {
for celsius in 1..11 {
println!("{}C = {}F", celsius, to_farenheit::<_, f64>(celsius));
}
}
>>
>>59700950
Look mom, I know how to use rust.
>>
>>59701020
he jelly
>>
>>59700950
>tfw will never be as verbose as rust senpai
>>
>>59700932
>started using Python a few months ago
>only wrote a bit
>While a tried python years ago and did not like it I am having fun right now

Last finished: A tool to monitor my ping and (if my connection is bad) generates text files.

Up next: A script to read the text files, sort them ( maybe day of the week, time of the day etc.) and plots a heatmap.
>>
>>59700861
https://www.youtube.com/watch?v=oqwzuiSy9y0
>>
https://www.idris-lang.org/idris-1-0-released/
>>
>>59701146
literally nothing btw
>>
What's the use of pointers besides dynamically-allocating resources such as arrays?

Why would you want to "pass by reference" instead of returning the value and not creating side-effects?
>>
>>59700950
%terminates
f : Celsius -> Fahrenheit
f = toFahr

%terminates
table : Celsius -> Text
table x = "C: " ++ show x ++ " = F: " ++ show (f x)

%terminates
main : (m : Monad) => m [Text]
main = pure $ loop 1..100 :- table %iter
>>
>>59701176
because passing by value is slower and allocates memory
>>
>>59701216
do it properly with type indices
Unit -> Type -> Type
>>
File: legacy_silverman2.jpg (69KB, 1024x680px) Image search: [Google]
legacy_silverman2.jpg
69KB, 1024x680px
what do you thing about ken silverman?

i think he is genuis but he played the wrong cards.
>>
>>59701216
>terminates
>>
>>59701240
Why?
>>59701265
What are you trying to say?
>>
>>59701268
The code the other anon gave was
1) enterprise quality
2) generic
>>
>>59701259
>game programmer
>genius
n1
>>
>>59701272
>1) enterprise quality
What does it mean?
Run only on Windows? Not documented? Can not support compiler upgrade? Can not support OS upgrade?
>>
>>59701277
>John Carmack
okay
>>
>>59701280
You know what it means
>>
>>59701284
Yes to all my questions?
>>
>>59701280
>Run only on Windows? Not documented? Can not support compiler upgrade? Can not support OS upgrade?
None of that, are you unemployed?
>>
>>59701272
>1) enterprise quality
Yeah, it's enterprise ready.
>2) generic
In what way is my code less generic than his?
>>
File: 1458796104088.gif (17KB, 200x192px) Image search: [Google]
1458796104088.gif
17KB, 200x192px
>>59701277
back then you had to develop the algorithms yourself so yes they are genius.
>>
>>59701314
>>59701283
>>>/vg/
>>
>>59701317
/agdg/ full of unity devs no!
>>
File: 1491128690703.jpg (59KB, 480x570px) Image search: [Google]
1491128690703.jpg
59KB, 480x570px
>>59700932
Working on learning c++
Making bubble_primes as my first project.
Calculating, sorting using bubble sort and summing all primes below 2 million.

Trying to solve a few bugs and it's basically ready, probably going to refactor some of it to use pointers when i have learned those.
>>
How do you reverse a string that doesn't fit in memory?
>>
>>59701314
>back then you had to multiply 7 digit numbers by hand
>so yeah people from the past are geniuses
>god I hate these neo age people, I wish they could appreciate pointless work a bit more
>I am born in the wrong generation
>>
>>59701328
enterprise quality post.
>>
>>59701337
>being this new
>>
>>59701335
Reverse a what?
>>
>>59701352
A string.
>>
>>59701296
>None of that
So deluded.
>are you unemployed?
No. I am employed to produce OCaml.
>>
File: 1463287798085.png (2KB, 113x51px) Image search: [Google]
1463287798085.png
2KB, 113x51px
>>59701352
>>
>>59701368
>I am employed to produce undocumented, windows only backwards incompatible garbage
Makes sense
>>
File: carlos.png (272KB, 560x560px) Image search: [Google]
carlos.png
272KB, 560x560px
>>59701366
>>59701371
I guess I forgot
>>
>>59701368
>I am employed to produce OCaml.
I'm sorry to hear that.
>>
>>59701336
no i love my generation desu ^_^
>>
>>59701336
>>59701380
Who are you quoting?
>>59701347
Nobody said this.
>>
>>59701391
>Nobody said this.
What are you going to do about it?
>>
>>59701314

We stand on the shoulders of giants.
>>
>>59701399
>this coming from a manlet
>>
>>59701404

I used a ladder to get up here.
>>
>>59701265
so?
>>
>>59701397
>>59701391
>>59701385
>>59701383
>>59701380
>>59701371
>>59701368
>>59701366
>>59701352
>>59701347
>>59701337
>>59701336
kys yourselves, and OP please delete this thread
>>
OSGTP is 5'8"
>>59701409

>>59701414
No.
>>
>>59701421
>tfw my friends bully a guy for being 5'8'' while i'm silently being 5'7''
>>
File: 1481076296027.png (440KB, 645x1260px) Image search: [Google]
1481076296027.png
440KB, 645x1260px
>>59701421
>5'8"
>>
File: 1477304356530.png (231KB, 342x342px) Image search: [Google]
1477304356530.png
231KB, 342x342px
>>59701421
>5'8"
kek
>>
>>59701335
If it is a string, how it doesn't fit in memory?
>>
I have this huge list of proxies.
I tried to remove duplicates before I ran the code but,

When I do:
with open("proxy.txt", "r+") as f:
proxy = f.read().splitlines()
print(len(proxy), 'in list')
proxy = set(proxy)
print(len(proxy),'proxies')

I get:
2284461 in list
393353 proxies

I feel like I'm losing way too many. Am I doing something wrong or are there actually duplicates?
>>
>>59701459
Maybe it's a saved serialized string that fits on the HDD, but you want to read it in the RAM memory
>>
works but kinda slow and crude

wget "https://www.google.com/finance?q=EURUSD" -qO- | grep "1 EUR = " | cut -c 25-31


how to improve?
>>
>>59701518
use an api
>>
>>59701335

>Allocate a page of memory
>Create a new file to store the reversed string
>From the end of the input file to the beginning of the input file:
>>Load a page-sized block of data from the input file
>>Reverse that memory
>>Write out that memory to the output file
>>
>>59701533
nerd
>>
>>59701317
this response is so fucking pathetic
>>
>>59701554
>>>/b/
>>
>>59701559
>name one great gun
XXX
>/k/

>name one great car
XXX
>/o/

did you learn this in your debate club?
>>
>>59701573
>debate club
>>>/reddit/
>>
File: yui.jpg (85KB, 650x780px) Image search: [Google]
yui.jpg
85KB, 650x780px
I want to learn Lisp. Should I go through Land of Lisp or SICP? They both look interesting on first glance.
>>
Making a 3d game with multiplayer. I was thinking Java + OpenGL, but I dunno. So what language/engine should I use? Thanks.
>>
>>59701600
OCaml + SDL + OpenGL
You'll thank me later.
>>
>>59701617
>OCaml
Is this just one guy who keeps spamming his shitty language that they force him to use at work?
>>
>>59701617
Thank you. However, all the game screenshots I find from SDL look like crap.
>>
File: 1487716794438.png (269KB, 433x531px) Image search: [Google]
1487716794438.png
269KB, 433x531px
>>59701654
What? How can you judge SDL by screenshots? Do you know what SDL is?

>>59701600
Wouldn't garbage collection in java cause random fps drops? To my knowledge you can't control the garbage collector in java and it's not optional. I don't use java much so I might be wrong here, and for small games it probably doesn't matter. I'd still go with a language that doesn't have GC or has GC that you can turn off when you don't want it.
>>
>>59701654
Youll end up just re-writing the renderer yourself .
SDL is shit.
Wrap win32 and linux and grab an OGL binding.
>>
>>59701651
>force him
forcing to use the best language?

>>59701654
type ocaml game in google (can't post the URL because 4chan think it's spam)
>>
>>59701700
yeah, all of them look like the garbag java would collect
>>
File: 1415449597007.jpg (80KB, 505x475px) Image search: [Google]
1415449597007.jpg
80KB, 505x475px
>>59700950
I'm the author of this piece of code.

Rate my safe and idiomatic Rust fizzbuzz:
#![feature(collections_range)]
#![feature(step_trait)]

#[derive(Debug)]
enum FizzBuzz<N>
{
FizzBuzz,
Fizz,
Buzz,
Other(N),
}

impl<N> std::ops::Add for FizzBuzz<N> {
type Output = Self;

fn add(self, other: Self) -> Self::Output {
match (self, other) {
(FizzBuzz::Fizz, FizzBuzz::Buzz) => FizzBuzz::FizzBuzz,
_ => panic!(""),
}
}
}

impl<N> From<N> for FizzBuzz<N> {
fn from(val: N) -> Self {
FizzBuzz::Other(val)
}
}

impl<N> std::fmt::Display for FizzBuzz<N>
where N: std::fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
&FizzBuzz::FizzBuzz => write!(f, "FizzBuzz"),
&FizzBuzz::Fizz => write!(f, "Fizz"),
&FizzBuzz::Buzz => write!(f, "Buzz"),
&FizzBuzz::Other(ref n) => n.fmt(f),
}
}
}

fn fizzbuzz<'a, R, N, F1, F2, X, Y, T>(r: R, fizz: F1, buzz: F2) -> Vec<T>
where R: std::collections::range::RangeArgument<N> + Iterator, <R as Iterator>::Item: Copy, N: 'a + std::iter::Step, &'a N: std::ops::Add<&'a N, Output=N>, F1: Fn(<R as Iterator>::Item) -> Option<X>, F2: Fn(<R as Iterator>::Item) -> Option<Y>, X: std::ops::Add<Y>, T: From<X> + From<Y> + From<<R as Iterator>::Item> + From<<X as std::ops::Add<Y>>::Output> {
r.map(|n| {
match (fizz(n), buzz(n)) {
(Some(f), Some(b)) => (f + b).into(),
(Some(f), None) => f.into(),
(None, Some(b)) => b.into(),
(None, None) => n.into(),
}
}).collect()
}

fn main() {
for s in fizzbuzz::<_, _, _, _, _, _, FizzBuzz<_>>(1..101, |n| if n % 3 == 0 { Some(FizzBuzz::Fizz) } else { None }, |n| if n % 5 == 0 { Some(FizzBuzz::Buzz) } else { None }) {
println!("{}", s);
}
}
>>
>>59701753
>
#![feature(collections_range)]
#![feature(step_trait)]

#[derive(Debug)]

rust was the truest mistake ever made.
>>
Defend this

https://www.idris-lang.org/docs/current/base_doc/docs/[builtins].html
>>
>>59701800
defend what?
>>
>>59701710
OK, you're right. Java is superior to OCaml. Stick to java.
>>
>>59701800
just
>>
>>59701815
all those primitives
>>
>>59701855
>more type options are bad
alright pajeet
>>
What are symbol tables used for?

I'm learning about binary trees as a means of symbol table implementation, but I'm not sure when you'd want to use a symbol table.
>>
>>59701753
Java doesn't look that bad after all.
>>
>>59701898
You would only use a symbol table if you're trying to write a compiler/interpreter.
>>
>>59701875
ok smart guy where are the equality primitives

i.e. prim__addInt 0 n = n
>>
@59701972
you can stop now
>>
>>59701980
>>59701875
ohhh, you don't actually know what i'm talking about

ok
>>
I've been book learning Python for 3 months now. I finished the book I was learning from. Now, the way for me to continue learning Python would be to start working on projects. I want to start learning C next. I want to start learning C as soon as possible. Would it be a mistake for me to start learning C now?
>>
>Anjana Vakil: Learning Functional Programming with JavaScript

wew
>>
File: Untitled2.png (259KB, 1026x1465px) Image search: [Google]
Untitled2.png
259KB, 1026x1465px
I am making a set of programming questions, meant to test fresh grads or those applying to entry-level programmings jobs.

Please take a look and let me know if any questions are illogical or unclear.

Your comments, suggestions, and criticisms are welcome.
>>
File: 39557101-rage.jpg (69KB, 1280x720px) Image search: [Google]
39557101-rage.jpg
69KB, 1280x720px
i hate myself
i hate programming

fuck
>>
>>59702070
No one cares, just do whatever you want, you'll always be a mediocre programmer anyway
>>
>>59702151
>show the 12x12 table
what?
>>
>>59702151
>Show the 12x12 table
What? The multiplication table?
>>
>>59702197
>>59702215
Needs re-wording?

>Show the 12x12 multiplication table
Better?
>>
>>59702151
Theory 4: what's the "optimum/exact" answer?
>>
>>59702258

You go to Barber Jack, since Jack must be John's barber.
>>
>>59702220
Yes. Although I would personally say "print" instead of show, as it's more precise, but it's probably not an important distinction.

>>59702258
You pick the scruffy barber, because he would be the barber of the clean looking one.
>>
>>59702220
Whats the time limit on these?
Also personally i think theory 6 is a little ridiculous but that could just be the brainlet talking.
#9 im legitimately confused on, whyd you switch the phrasing?
>>
>>59702266
>>59702272
Unless John shaves himself, or his dad gives him a haircut, or he does it in a different town, or any other of the million options
>>
>>59701753
Can it be evaluated at read-time?
>>
>>59702282
> whyd you switch the phrasing?
I do not follow. What did I switch?
>>
>>59702316
oh wait scratch that. just tired
>>
>>59702282
Is the answer for #9 supposed to be 30?
>>
Why doesn't the JVM do TCO?
>>
>>59702300

okie-silly-dilly-dokie-o.
>>
>>59702348
The only silly thing is the ambiguous "clever" puzzle questions that pop up only at low tier companies
>>
>>59702151
how do you do theory 11 in less than 100 steps?
>>
>>59702151
>Technical
This is WAY too focused on C++, and some of the questions would probably fit more into the theory section.

>1: pointer vs address
This is a very vague question. You can argue all sorts of shit, depending on what you decide a pointer and an address it. Maybe that's what you want?
>2: structure vs class
I don't know whether this is about the whole struct/record (Procedural programming) vs classes/objects (OOP), or you're literally asking about the semantics of C++.
>3: string vs character array
Too language dependant, and it a more complicated question that it appears to be.
Are we talking C "characters" (bytes)? Are we talking Unicode code points?
Are you just asking about null termination here?
>4: int vs short
Very C/C++ specific.
>5: return by value vs return by reference
Too C++ focused.
>7: abstract class
People have really gone off of inheritance these days. I'm not a fan of POO either.
>8: unsigned integer
Javafags BTFO.
>11: this
Too C++ focused. It's not really an interesting question.
>12: malloc
Too C focused. If you're really grilling someone on the uses of dynamic memory, make the question more direct.
>13: FIFO LIFO
I would consider this theory.
>14: Sorting algorithms
Also theory. The grammar in this sentence is off too:
What _is_ bubble sort and selection sort?
>15: operator overloading
Too C++ focused.
>>
>>59702383
start at floor 2
>>
>>59702151
>3. .. without conditional statements ...
You want them to do something like this?
int main(){
const char label[2][5] = { "even", "odd" };
for (int i=0; i<100; ++i){
printf("%i:%s\n", i, label[i&1]);
}
}
>>
>>59702466
>
 for (int i=0; i<100; ++i){
printf("%i:%s\n", i, label[i&1]);

a for loop is a condition

these questions are so counter-intuitive though.
Forcing you to think in a tedious way that would get you fired if you pushed out code like it.
>>
>>59702383
use the elevator
:^)
>>
>>59702400
Will go over this a couple more times to see what I can do.

>>59702466
Thanks for pointing that out. That is a bit too much for fresh grads. Will fix.
>>
sometimes I read C code and I see things like
"ifndef __VARX" at the top of the file, what are these for?
>>
>>59701594
Go for LoL, is less dense.
>>
>>59702533
macro abuse.
c's golden piece of shit feature.
>>
>>59702482
>a for loop is a condition
Yeah but without a for loop you can literall just have one puts() statement and be done.

>>59702500
I wouldnt say it's too hard to do for fresh grads, it's too hard to even understand what you want.

Go to codeeval com or other websites and look how they structure their assignments. You need to tell them how exactly their output should look like and your restrictions have to be clear as well.

Like it was pointed out doing programming number 3 literally would disallow the use of loops.
>>
>>59702533
Are you talking about include guards?
>>
>>59702312
No. It's just a stupid indirect fizzbuzz implementation with stupid amounts of generics thrown on top of it.
>>
>want to write something in golang
>component A, B and C exists already
>file consists to 50% out of
import()


Is go the new python?
>>
>>59702683
Go is a replacement for Django and RoR. It has no other use.
>>
>>59702547
what does the double underscore represent?
>>
>>59702683
not even, go is more a meme than rust if thats possible. python atleast has a niche
>>
>>59702710
An eternal reminder of C's missing namespaces.
>>
>>59702710
But if you meant the ifndef
//..
#define
#endif

those are include guards as the other anon said.
C's means of preventing redundant clashes.

In C++ is just a single
#pragma once
>>
>>59702731
But it's not really about namespaces because python and sepples code at least sometimes has underscores sometimes even double even though they have namespaces.
I mean there's no reason for C not to have some kind of simple namespace system but retarded people will use underscores in symbol names regardless. C has reason for it the others don't.
>>
File: allhail.jpg (386KB, 1600x1073px) Image search: [Google]
allhail.jpg
386KB, 1600x1073px
Should I store my app config in the sql database or in an env file?
>>
>>59702807
Database so you don't need to bother with somebody changing and reading data at same time.
If you want it to be human writable though then you probably need to make it file, at least it's lot simpler to implement your self.
>>
>>59702403
Why? If it breaks at floor 2 you don't know whether it breaks at floor 1 or floor 2
>>
>>59702886
gee, its almost like you have another egg or something.
>>
>>59702400
>return by value vs return by reference
>this
>operator overloading
>C++ focused

no
>>
>>59702899
Well if you have many eggs, then you obviously just do binary search in log n
>>
>>59702710
A leading underscore followed by another underscore or a capital letter is part of implementer's/language's namespace.
So whenever you read a system header, all of the "private" information will have them, otherwise they might invalidate standards conforming code.
It's also the reason why whenever they introduce new keywords into C, it's like that as well.
>>
>>59701753
>
where R: std::collections::range::RangeArgument<N> + Iterator, <R as Iterator>::Item: Copy, N: 'a + std::iter::Step, &'a N: std::ops::Add<&'a N, Output=N>, F1: Fn(<R as Iterator>::Item) -> Option<X>, F2: Fn(<R as Iterator>::Item) -> Option<Y>, X: std::ops::Add<Y>, T: From<X> + From<Y> + From<<R as Iterator>::Item> + From<<X as std::ops::Add<Y>>::Output> {

sweet jesus
>>
https://github.com/ableiten/foldem

Welcoming questions and suggestions
>>
>>59702912
You have 2 eggs.
Throw it down every 2 steps, if the first breaks throw the second from step - 1.
51 steps
>>
>>59703250
>You have 2 eggs.
Somehow I didn't read that part lol
>>
After mastering C I literally cannot program in another language, except maybe assembly. All other languages are braindead. They require no systematic thinking, no logical analysis of the problem at hand; no knowledge of how a computer really literally actually works. I can finally see. I not only understand but overstand why C gets so much hate, and you would too if you knew how the IQ bell-curve worked.

So, my C bretheren, fear not this unjust persecution. These "people" can't truly see, and it's not entirely their fault. It is our obligation to make them better people.
>>
>>59703419
>t. brainlet
>>
>>59702073
lel
At least she is hot.
>>
This motherfucker knows his audience

https://simpleprogrammer.com/2017/03/29/dating-for-programmers/
>>
File: bjarne.jpg (28KB, 222x229px) Image search: [Google]
bjarne.jpg
28KB, 222x229px
c++ is the best language :--)
>>
>>59703552
Without any doubt.
>>
>>59703522
>In my view, feeling bad for not having a girlfriend is a symptom of a bigger problem
Lol, I don't feel bad.
>>
I love the "C is how the computer actually works" shit.
Especially since C has no concept of cache hierarchies, invalidation and coherence, no native facilities to exploit multiple execution units, no native support for SIMD and a memory model that could not be further away from what x86 actually provides.
>>
>>59703552
yes, we're all in agreement about this
>>
>>59703552
That's a weird way of saying Lisp.
>>
>>59703596
C is how PDP-11 works, not x86.
>>
How do you get Visual Studio's Solution Explorer to show files at the root (solution) level? Is it even possible?
eg
Solution directory
+- Project #1 directory
+- Project #2 directory
+- File X <- I want to see this goddamn file
>>
I'm using the Euclidean Algorithm to find the GCD of two numbers. It seems to work correctly, but for a reason I can't figure out, it is returning "None". Adding a print(gcd) show's that it has calculated correctly.

def GCD(a,b): #(270,192)
gcd = 0
if a == 0:
gcd = b
print(gcd)
return gcd
if b == 0:
gcd = a
print(gcd)
return gcd
if a>b:
remainder = (a%b)
else:
remainder = (b%a)
GCD(b,remainder)
)
>>
>>59703641
it doesn't just show all files in the directory
if you want it to show up in solution explorer you have to right click on the solution->add file
>>
>>59703673
disregard, it creates a new filter called "solution items"
so yeah, not possible I suppose
>>
>>59703657
you didn't put return nowhere son
>>
>>59703695
>>59703673
Nah, it's enough for what I need to do
Thanks
>>
Python 3
So I'm making a program where you write the name of a person and the debt they have, I wanted to make this a dict like
{"Dan":1000,"Joe":125"}
, but the question is, what the best way to store this dictionary?
json?,pickle?
>>
>>59703702
right there in the first few lines.
if a == 0:
gcd = b
print(gcd)
return gcd
if b == 0:
gcd = a
print(gcd)
return gcd
>>
>>59703657
try at the end doing
return DCD(b,remainder)
>>
>>59703709
csv
>>
>>59703709

python has built in dictionaries that are basically json
>>
>>59703733
GCD(b,remainder) mispelt it
>>
>>59703720
You don't return the result of the recursive call.
>>
Should I do all of the SICP exercises?
>>
>>59703817
Yes
>>
compute gcd
#define ll long long int 

ll gcd(ll a, ll b) {
return !b ? a : gcd(b, a%b);
}
>>
>>59704078
Please just use stdint.h
>>
print a string "without" the main function.
#include <stdio.h>
#define kek(s,t,u,m,p) m##s##u##t
#define top kek(a,n,i,m,e)

int top()
{
printf("Hello World!\n");

return 0;
}
>>
how much space does your visual studio + components take up?
>>
>>59700932

> intro to compsci professor thinks he can write a confusing function on the test
> tfw I know haskell
>>
>>59704099
more than 40 GB
thanks m$
>>
>>59704110
ur so cool anon :)
>>
Ok wtf am I doing wrong here, it keeps returning 0 for some reason

double winVariance = (double) total*(winRatio)*(winDifference/total);
System.out.println(winVariance);


total and windifference are int and winratio is a double btw.
>>
>>59704110
https://www.youtube.com/watch?v=3NuFVQk_CCs
>>
>>59704137
Cast either windDifference or total to a double.
>>
>>59704152
thanks mate, got it.
>>
>>59704148

> weeaboo replies to me
> tfw when I reply
>>
Why won't this work
fwpd.core=> (map #(nil? (get vamp-keys %)) sample)
(true true)
fwpd.core=> (apply and (map #(nil? (get vamp-keys %)) sample))
CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(/tmp/form-init90542080361189119.clj:1:1)

fwpd.core=>
>>
>>59703795
how do I do that?
>>
>>59704201
Change
GCD(...)
to
return GCD(...)
>>
>>59704201
See >>59703733, >>59703749. You print the GCD in the base case and return there, but you don't return for the recursive case so the caller doesn't get the result (unless they did GCD(x, 0) or GCD(0, x)).
>>
>>59704189
Apparently apply doesn't work on macros.
This solutions works:
(every? identity (map #(nil? (get vamp-keys %)) sample))
>>
me@basement ~/Documents/waifus $ make love
make: *** No rule to make target 'love'. Stop.
>>
>>59704257
>Documents
>D
kys
>>
>>59704218
>>59704219
That did the trick. I sort of understand why, but recursive functions confuse me a bit still. I'll keep working on them. thanks anons.
>>
>>59704182
Congratulation anon
https://www.youtube.com/watch?v=1Bix44C1EzY
You win one intrenet
>>
File: TODAY.png (31KB, 1064x237px) Image search: [Google]
TODAY.png
31KB, 1064x237px
>>59700932
>What are you working on, /g/?
HELLO. I AM WORKING ON THIS.
>>
>>59704325
Clever code or stupid code?
>>
>It doesn't happen because we've got instant-gratification retards like you shitting shit up. Keep doing procedural, but stop trying to drag everyone else down with you.
OOPajeets are amusing.
>>
>>59702151
as a noob, i find this fascinating and very helpful.

maybe something similar should be added into a pastebin or something.

I like it. Thanks.
>>
>>59704325
either use your brain and calculate this by hand or do the algorithm for generating consecutive permutations: https://www.nayuki.io/page/next-lexicographical-permutation-algorithm
>>
>>59704339
clever code would be nice
>>
>>59704369
wew, this makes sense
>>
>>59704384
there are 9! permutations beginning with 0
and 9! permutations beginning with 1
so the answer begin with 2
>>
File: C.C..full.1888749.jpg (445KB, 531x800px) Image search: [Google]
C.C..full.1888749.jpg
445KB, 531x800px
Can someone who uses ORMs extensively share some thoughts please?

It's been ages since I last used EF, but if I recall correctly you'd do something like this:

using (DbContext someContext = fromSomewhere) {
someContext.Select<User>();
someContext.Select<User>().Include(u => u.Profiles);
}


Or something like that.
Anyway, what I'd like to ask is:
- If you don't call the "Include" it won't do the JOIN and the property will be null as far as I can remember, but is there a way to always join everything so I don't need to care about it?
- If my model has a property I want to be lazy'ed, can I call it after the "using" statement is closed? Because if the context is closed/disposed, doesn't that mean there's no connection anymore? Does it know how to reopen it to fetch the lazy ones?
- Last one is, when you model your project do you have to create a context for every model/entity or can you create a single generic repository once and never ever care about it again?
(This is assuming you can always JOIN or properties can always be LAZY'ed because otherwise you'd need to add the proper "includes" for each and that would definitely make this generic class inviable)

Genuinely curious because I'm coding some ORM and I'm having some... code design crisis or w/e this is called and I want to hear how others do it.
>>
File: perms.png (22KB, 890x286px) Image search: [Google]
perms.png
22KB, 890x286px
>>59704325
#include <iostream>
#include <algorithm>

int main() {
int v[] = { 0,1,2,3,4,5,6,7,8,9 };
for (int i = 0; i < 1000000; i++)
std::next_permutation(v, v + 10);

for (auto it : v)
std::cout << it << " ";

return 0;
}


2 7 8 3 9 1 5 6 0 4
>>
>>59704369
>that spoonfeeding
You're only huting him in the long run.
>>
>>59704419
not him, but how are you so smart?
>>
>>59704419
I continue
We're left with
274240 perms
we can fit 6*8! in 274240
so next digit is 7
27x
we're left with 32320 perms
we can fit 6*7!
so next digit is 8
278x

etc...

>>59704469
I'm a wizard compared to you
>>
>>59704440
that's 1e6 + 1 though
>>
CREATE FUNCTION [dbo].[factorial]
(@x as decimal(38,0))
RETURNS decimal(38,0)
BEGIN
declare @factorial as decimal(38,0)
set @factorial = 1
WHILE (@x > 0) begin
set @factorial = @factorial * @x
set @x = @x - 1
end
return @factotial
END

T-SQL is really a simple language.
>>
>>59704508
it's ambiguous if the first one counts or not
>>
>>59704342
Source?
>>
>>59704542
well, technically { 0,1,2,3,4,5,6,7,8,9 } is a permutation too, but I agree, it's not that important
>>
>>59704582
AGDG
>>
>>59704651
so why dont you stay there
>>
>>59704651
Well I guess I'm not surprised. Gamedev.net is the same.
>>
File: 1437789415181.png (17KB, 2414x648px) Image search: [Google]
1437789415181.png
17KB, 2414x648px
Write a concise report giving an abstract description of your program. Explain the architecture and design of the program and point out the use of any object oriented design patterns. Very short program fragments may be included to illustrate the description.

Not really sure what to write here. I barely used any OO and got rid of the shitty overrides because it made it unreadable. Am I meant to explain the algorithms I used to implement different formats? It's only a short 1k line program.
>>
>>59704684
You are supposed to rewrite it to use OOP cause they probably wanted you to talk about inheritance and polymorphism and etc
>>
>>59704723
Yeah, I thought that might be it. I'm not going to though, we got given some starting code, and it was fucking impossible to tell what the fuck it was doing, it just jumped between derived and base classes every fucking line.

The way it looked like they wanted us to extend it would mean essentially copying the entire class, and changing one function, which in one of the bits was an extra 120 or so lines of code, for a two line change.

I wrote that I used some Linq because I thought it was badly suited for OOP and lists were used a lot, so mapping/filtering etc was pretty handy using Linq.

It's only 500 fucking words so I can barely even describe one algorithm in that, fuck
>>
>>59704795
obviously you were supposed to be learning OOP, and instead you just turned the solution into something that wasn't OOP
so you didn't do the assignment at all
>>
>>59704795
>because I thought it was badly suited for OOP
If you make a good case for why OOP was bad and why you solution solves those problems, maybe they'll be lenient with you
>>
>>59704839
No, not really actually, we've already done tons of OOP shit in early years, and the course is more on pros and cons of different techniques. In fact, some of the lectures are about why overrides and inheritance are often a bad idea, and I figured this was one of them.

I'll probably do what >>59704846 said.

It's only 20% of the mark, so I'm not that bothered if it doesn't get that great marks.
>>
>>59704839
Maybe they should find a good use case for OOP if they want to teach it successfully.
>>
>>59704877
>find a good use case for OOP
{obligatory meme response}
laughingpeople.jpg
>>
>>59704912
thatsthejoke.jpg
>>
File: ?.png (7KB, 120x120px) Image search: [Google]
?.png
7KB, 120x120px
Does the same Java code compiles to the same byte code in different platforms ?
>>
>>59704458
>You're only huting him in the long run.
actually, if he calculated this by hand and no one ever told him about that algorithm, it would've hurt him even more.
>>
>>59704946
you don't even need to compile it on different platforms
you can compile it on windows and run it on linux
>>
>>59704946
It does. That's the whole point of bytecode.
>>
>>59704953
what i meant was:
compiling a java file called Test.java, in windows and linux, results in the same bytecode?
>>
A script that takes an image and adds random pixels and creates as many as copies you want so you can spam the same shit over and over while dodging spam detection :^)
>>
>>59705017
holy shit, madman!
>>
Anyone knows any good SQL exercises site?
>>
>>59705031
thanks for acknowledging my superiority bro
>>
>>59705041
hackerrank
>>
>>59705041
http://www.sql-ex.ru/

left side bar called exercicies
>>
File: george-carlin.jpg (34KB, 640x480px) Image search: [Google]
george-carlin.jpg
34KB, 640x480px
>>59705061
>.ru
>>
I'm making a script for harassing my friends a month after I an hero
>>
>>59705072
what's the problem, reddit?
>>
>>59705072
Most trustworthy domain that is
>>
File: cool_cato.jpg (196KB, 432x444px) Image search: [Google]
cool_cato.jpg
196KB, 432x444px
>>59705054
>>59705061

Appreciated 'nons.
>>
File: mqwo6yojiloy.jpg (328KB, 1882x786px) Image search: [Google]
mqwo6yojiloy.jpg
328KB, 1882x786px
>>59705083
>>
>>59705101
nice /b/ folder anon, now please go back
>>
>>59705124
you have to go back
>>
>>59705101
>shit advice
>not even a quad or dub as the op asked
>>
>>59700932
A doggo fright generator. "Oh X you're Y-ing me a Z"
>>
>>59705482
but why
>>
File: preludeprogramminglanguage.jpg (98KB, 1280x720px) Image search: [Google]
preludeprogramminglanguage.jpg
98KB, 1280x720px
>>59700932
>>
>>59705785
What are you going to mean by this?
>>
>>59705785
Dumb animu poster.
>>
>>59703552
Yes, your LISP dialect is really great, Bjarne. Thanks for doing such a great work.
>>
How do you send an output to stdout in C?

The instructions are:
If the -o option is used the output will go to a
file named as specified without changing the
filename at all otherwise it will go to stdout.


So in the instance -o option is used, I just have it as something like outputName = optarg where optarg is the output filename provided by the user and that's where the output goes. Well if they don't bother using the -o option then the output should be to stdout. How do I do that?
>>
>>59705932
As far as I remember use stdout (maybe uppercase idk) as a file handle. It's predefined.
>>
>>59705932
printf
>>
I made an ebook reader so you can read text files in CLI. This way you can read .txt books from Archive.org and save bookmarks, search for sections, navigate pages, etc.

https://github.com/collinoswalt/books

Anyone wanna help by submitting a better makefile or configuration file?
>>
>>59705932
man 3 dup2
>>
Since there seems to be more traffic now:

If I'm making an editor of sorts, for text, image, sound etc... What's the usual way to implement changes tracking, or more simply, the undo and redo actions?
Should I only keep track of changes themselves, ex: only remember which pixels changed color, and what was the old and whats the new color, or after the 198th character five were deleted...
or
Should I keep the whole document after any action as a saved state so I don't have to know what was explicitly changed to revert it, just simply go back to a previous state (though I imagine this can get resource intensive after a while if I don't limit the number of saved states)
>>
>>59705987
here's a demo:

http://collinoswalt.com/res/img/1491159783.webm
>>
>>59705986
I'm outputting an image, cant.
>>59705991
can you elaborate? I don't know much about dup2 but it's something I saw that I might be able to use

is it simple like dup2(outputName, stdout) or...?
>>
For someone programming Java OOP,
Should I be using Eclipse IDE or NetBeans IDE
>>
>>59705987
Here's a better Makefile
diff --git a/Makefile b/Makefile
index 6ca58ea..e41543f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,21 @@
CC=gcc
-SRC=./src
-BIN=./bin
+SRC=src
+BIN=bin
LIBS=-lncursesw -lm
+RM=rm -f

-all:
- $(CC) $(SRC)/books.c -o $(BIN)/books $(LIBS)
+.PHONY: all clean
+
+all: $(BIN)/books
+
+clean:
+ $(RM) $(BIN)/books $(SRC)/books.o
+
+$(BIN)/books: $(SRC)/books.o
+ $(CC) -o $(BIN)/books $(SRC)/books.o $(LIBS)
+
+.SUFFIXES:
+.SUFFIXES: .c .o
+
+.c.o:
+ $(CC) -c -o $@ $<
>>
>>59706007
The formatting is a bit weird desu, but that's pretty cool.
>>
>>59706017
In short, to a program stdout is just a file (or a filestream, whatever) like any other, and it has its handle number for example 1. and if your program is sending anything to 1 its going to stdout. Dup2 allows you to take an open file which has its own handle, and give it a handle of some other open file, in this case stdout. Sou when the program tries writing to 1 after that, its all going to the other file, not the stdout.
>>
Why is it necessary to declare the refence as const when defining a copy constructor for C++?

I see why it's a good idea to be declaring args as const everywhere where it's the case just to aid the compiler and such but I don't see why it's mandatory.
>>
>>59706058
I fixed it a bit since that demo. New lines don't pad with a space and I also added 1char of padding to the entire reader. I'm also working on word wrapping.

This is what it looks like now
>>
Any decent resources on how to set up a simple application server? (Book format preferred, but as long as it's systematic and structured).

I'm confused as to how all the various Interconnecting aspects that constitute a web server operate. There are all these meme frameworks, paradigms and protocols, and I can't make sense of it all. I just want to learn to build stuff that's simple, performant and secure.

Just thought I'd ask here first since my background is in embedded systems. Or should I scuttle off to /wdg/?
>>
File: KWC_-_Alley.jpg (844KB, 800x1049px) Image search: [Google]
KWC_-_Alley.jpg
844KB, 800x1049px
>>59706049
I'm getting

Makefile:1: *** missing separator.  Stop.
>>
>>59706159
How is it possible? How did you apply the patch?
>>
>>59706108
What kind of application server? do you want it to interface with a web browser?
>>
>>59706168
Patch? Sorry, I don't know much about this stuff
>>
Why is the variable not assigned ?
def checkfile():
if os.path.exists("accounts.dat"):
account = open("accounts.dat","r+")
print("File Found")
else:
account = open("accounts.dat","w")
print("Account Data File Not Found\nCreating File...")
def index(com):
global account
if com == "list":
for key, value in account.items():
print(key, ":" ,value)

 line 17, in index
for key, value in account.items():
NameError: name 'account' is not defined
>>
>>59706172

>do you want it to interface with a web browser?

Uhh, yeah I guess.
>>
>>59706194
Use the patch command nerd.
>>
>>59706194
another patch for your configure script
diff --git a/configure.sh b/configure.sh
old mode 100644
new mode 100755
index 6850d5f..3db434d
--- a/configure.sh
+++ b/configure.sh
@@ -1,2 +1,4 @@
-mkdir ~/.books
-mkdir ~/.books/bookmarks
+#!/bin/sh -e
+
+mkdir -p "$HOME/.books"
+mkdir -p "$HOME/.books/bookmarks"
>>
>>59706194
Or save https://pastebin.com/R0fD3EZt in a fille like foobar.patch
and type
>git am foobar.patch
>>
>>59701328
Turns out that's fake news:
http://goboiano.com/sexy-dragon-maid-cosplayer-is-actually-a-guy/
>>
I found a port of the first computer game Spacewar to the TI Explorer Lisp machines in this archive: http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/impdep/explorer/jwz.tgz

Flavors and the Lisp machine-specific I/O functions are used, otherwise it's quite similar to modern Common Lisp code. Quite interesting, if you care about history. There is a lot of other software as well, lots of graphics hacks apparently.
>>
About to start learning my first language as part of a curriculum. I misunderstood and thought we would be learning both languages in the course for some reason.

My choices were between Python or Ruby. I panicked and picked Ruby, because (and this is pretty embarrassing) it's my birthstone...Also I seem to remember hearing that it was good for beginners.

How bad did I fuck up boys? I get the feeling I should've picked Python for some reason.
>>
>>59706201
What does the program print? Does it say anything to indicate whether the accounts file was opened successfully? Furthermore, while I don't know that much about python, shouldn't you declare the account variable as global in checkfile()? Otherwise, I would think it refers only to the variable local to that function.
>>
>>59706608
Ehh, Python and Ruby are quite interchangeable, don't worry.
>>
>>59706458
>>59706397
Got it. thanks guys
>>
>>59706608
Pick Python. It's more versatile.
>>
>>59706643
Whew...thank you anon.

>>59706719
Ehhh...Would Python be easy enough to pick up post Ruby? Dunno if I can change or not.
>>
>>59706820
>Ehhh...Would Python be easy enough to pick up post Ruby? Dunno if I can change or not.
Well, is this like an introductory programming course, or is it some sort of really in-depth advanced course in a language? My first programming class was in Java for example, but everything since then was mainly in C++, and it wasn't really a major effort to switch, since introductory stuff is focused on the principles that apply to all languages.
>>
Is it bad if I can't figure out how to add up the sums of all primes numbers in a given range? I can't even figure out how to determine if a number is prime or not.
>>
>go out
>come back
>38 new messages
>no (You)'s
wow ok "friends"
>>
>>59706864
If you want to be a web dev it's ok.
>>
>>59706869
You should kill the normies for what we did to you
>>
File: 1465159543045.jpg (9KB, 205x246px) Image search: [Google]
1465159543045.jpg
9KB, 205x246px
>>59706864
>interested in learning programming
>realize I wouldn't be able to solve that question without googling a bunch first and probably having to copy somebody else's work
>realize I'm too stupid to become a programmer
>>
>>59706952
>googling a bunch

That's how you program
>>
>>59706928
>implying i didn't go out by myself
what kind of monster do you think i am
>>
>>59706854
It's an introduction to the programming language as well as one of its frameworks. I'm sure the Ruby course goes into Rails, but as far as how in-depth it goes but I know that by the end of the course we're supposed to have a working portfolio completed, which could mean anything.
>>
>>59706952
It's really more of a math problem than a programming one. Even working in low-level languages, primality tests don't come up often except in specific situations, such as encryption algorithms. And unless that's the specialty you go into, it's very unlikely that you'll ever have to come up with a new encryption algorithm on your own.
>>
I was following Microsofts introductory Direct2D tutorial and there was on problem solution that i thought was unnecessarily complicated and unintuitive. So i ripped that out and tried to solve that problem again myself. Turns out the solution i finally came up with was exactly the same as the original.
>>
>>59707001
that's a web dev course. not sure if there's anything worse than ruby + webdev? i guess php
>>
>>59707041
welcome to graphics api
>>
>>59706874
but i want to be a software engineer anon. im a bit of a brainlet but i always get a solution to my problems eventually, just takes me a bit longer and a lot more trial and error. I'll figure this shit out
>>
>>59707053
Damn. Yeah throughout the entire program, we're supposed to get a taste of a few avenues of comp science. I thought the Ruby course would be more of a programming course and not webdev.

I did fuck up huh?
>>
>>59701259
kentris is his best game
>>
>>59706864

integrate x/ln(x) across your range, it will be a good approximation if your range is big enough.
>>
>>59701485
>RAM memory
>>
>>59706952
The naive finding of primes is easy:
 
n=17 //this is what we're checking
isprime=false
i=2
while(i<n) {
if(n%i==0) break
i++
}
if(i==n) isprime=true

Making a sum of them when you can test for primeness isn't hard. Just test the range and sum the primes.

Now this isn't the best solution. It's a woefully slow test for primeness. But that's fine for a first draft right?
>>
>>59700932
Thread ruined by disgusting weeaboo faggotry

Do you cry yourself to sleep because you will never be Japanese you self hating escapist?
>>
>>59707193
>random-access RAM memory
>>
I just realized I have a poor understanding of pointers and & operator in C.
Can somebody help me answer this question on my practice code on an online c compiler?
Question is the comment in the screenshot.
>>
>>59707245
>not using an integrated IDE development environment and the GNU GCC compiler to make a graphical GUI user interface for automated ATM teller machines
>>
>>59707249
don't they both set check to the same value? the first one sets check to point to the value of i, and yours sets check to the address of i, thus *check would still be equal to i
>>
>>59707304
>GNU
>not getting stuck in an infinite loop in the backronym or however that meme is called
>>
>>59707249
You use the asterisk when initially declaring a pointer, or when dereferencing it (operating on the pointed-to value), but not when assigning a new ADDRESS to the pointer. You should simply do
check = &i
, if you want to make the pointer "check" point to whatever is stored in the integer variable "i".
>>
>>59707249
I'm not good at explaining but check=&i would take the address of i and put it in check. *check=i derferences check and places the value of i where check was pointing to.
>>
>>59707249
Because changing the pointer to the the address if i will not do anything about what the pointer originally pointed to.
>>
>>59707249
>>59707407
PS since the variable i is a local variable passing the pointer to it outside the function would be unwise. So taking the address to it is kinda useless. Now it happens that check is passed by value. Changing the value of check in the function doesn't matter to the outside because you're just working with a copy. But if it was a pointer to a pointer to an int (int**)
Writing *check =&i would be a very bad idea.
>>
>>59707249
Shouldn't your function take a pointer to a pointer if you want to pass by reference?
>>
>>59707558
Only if you want a reference TO THE POINTER. A pointer is a reference TO THE ORIGINAL VALUE.
>>
Rate my log(n) factorial:

(defun _fac (s e) 
(cond
((= s e) s)
(t (* (_fac s (floor (/ (+ s e) 2)))
(_fac (floor (1+ (/ (+ s e) 2))) e)))))

(defun fac (n)
(_fac 1 n))
>>
>>59707643
I recommend using labels.
>>
>>59707643
Isn't this nlog(n)?
>>
>>59707699
no it's log(n). can't you read?
>>
Hey /dpt/. why does [32724153825,32724153825,32724153825] decode to JSON in php but [32724153825,01/01/2017,Event Lift-Off at Night] doesn't?
>>
>>59707717
No this is definitely n log(n). It's like merge sort with multiply instead of sort.
>>
File: pls.png (51KB, 400x250px) Image search: [Google]
pls.png
51KB, 400x250px
/prog/ is down...
>>
>>59707769
it's been down for awhile
>>
New thread:
>>59707776
>>59707776
>>59707776
>>
New thread:

>>59707778
>>59707778
>>59707778
>>
>I have to optimise assembly output for 5 algorithms from some esoteric compiler.
>mfw deadline is today.
>>
>>59707321
It runs it just sets the address of whats being passed in to the function to the value of i.
Hence when checker is printed the second time it is indeed changed to i instead of 9.
>>
>>59707834
What? No it doesn't.
check=&i sets check to point to i, at which point you've lost your pointer to checker, so checker remains 9
>>
>>59707923
Yeah i was talking about the line of code. *check=i;
However both check=&i and *check=i are not the same for some reason.
they both don't set the value to
>>
>>59708380
the int variable 2
>>
>>59708380
What do you mean?
*check=i works. That sets value of checker to 2.
check=&i doesn't work.because it doesn't change the value of checker.
>>
>>59708544
But should not check=&i mean that the pointer check which right now points to memory location 0x... should now point to address of i which is 0x.... because i is being refenced. &i means address - of - i. source: google search [...]the address-of operator ( & ) [...]
>>
>>59708544
>>59708691
i might be confused if u cud be a * to a good source to read that would allow me to compile this information very nicely.
>>
>>59708691
Yes. check=&i means that 'check' points to 'i'. Which means that 'check' does NOT point to 'checker'.
>>
>>59708819
But I am going to be passing in 'checker' into the function check(int* check);
Or should I have declared it as check(int*){
int i=2;
???=&i
}
How would that work do you know?
>>
>>59707193
>>59707245
>>59707304
>kys yourself
>>
>>59708924
I dont think I understand how exactly things are passed into functions.
Anyways thanks for all your guys help. I can take it from here
>>
>>59708924
When you pass in the address of 'checker' to the function, 'check' will point to 'checker'.
But if you then do check=&i you're changing 'check' so that 'check' now points to 'i' and not to 'checker'.
Thread posts: 326
Thread images: 33


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.