[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]

I will never be a good programmer, right?

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: 225
Thread images: 15

File: Снимок.jpg (214KB, 1027x997px) Image search: [Google]
Снимок.jpg
214KB, 1027x997px
I will never be a good programmer, right?
>>
You don't have to count all of them, only the first 3, this is how you know whether to start scanning for evens or odd numbers.
>>
Pretty much Pajeet tier, OP.

Don't worry, if you have a vagina you'll still get hired.
>>
>>60799260
drink bleach already
>>
>>60799260
You won't be a clever one with that attitude.
If you just want us to reaffirm your lazy self-image, sure, you're and never will be a clever programmer.
>>
>>60799341
holy shit, you are right

>>60799356
i don't have :(
>>
clever != good
>>
Dude, as long as it works at first that's a great first step.
after that try and gradually improve it. Programming skills improve with time and practise.
Don't drink the bleach yet...
>>
>>60799260
Kek wtf is that? It's cool if it's you're new to programming because you can only solve things with the tools you know. Also just because something has less lines doesn't mean it's better. I wouldn't use split, why have a function go through every possibility when the first 3 can give you the answer. If you have list of 1000 even numbers and the odd one is isn't last you're wasting time and power.
>>
>>60799260
Didn't read a word of that horseshit.
But the real reason why you never be a good programmer is simple - you are using python.
>>
>>60799509
This. Op if you want to be a good programmer, don't start with a nigger language
>>
>>60799341
>You don't have to count all of them, only the first 3

why exactly?
>>
>>60799484
>>60799341
>only the first 3
You aren't actually serious, are you?
>>
>>60799577
>>60799597
If you check only the first, it might be even or odd, you don't know how to continue.
If you check only the first 2, they might both be even/odd or it might be one of each, you don't what to look for.
If you check the first 3, it could be 3 evens, or 3 odds, or 2 evens and 1 odd, or 2 odds and 1 even, you'll be able to determine which is the majority in only 3 numbers and you simply scan through the rest looking for the outlier.
>>
>>60799577
It depends on the order of the numbers. If the first two are even, you know to look for the first odd. If it is 2 6 3, you found it.
>>
>>60799616
this. if there is only allowed to be 1 outlier then you can tell exactly what to look for by checking the first 3
>>
>>60799616
Also, it helps to think of it like this:
It wouldn't make sense to provide less than 3 numbers to this function because you require at least 3 numbers to describe the requirements.
>>
>>60799597
I said can, not will. The first 3 can give you the answer therefore there is no need to search the entire list of numbers.
>>
>>60799634
>>60799616
what if its something like 2 2 2 3?
am i not understanding the instructions?
>>
>>60799260
link to website?
>>
>>60799559
what not nigger language do you recommend?
>>
>>60799658
You're supposed to return the index of the outlier number.

>>60799660
if it's 2 2 2 3, you already know it's an even-majority list and you're gonna look for the first odd.
>>
>>60799663
http://www.codewars.com/
>>
>>60799660
3 is the minimum required, not guaranteed
>>
>>60799667
id recommend you java.the others probably gonna say c but you cant really do anything with c except for writing kernels and compilers.also java is a million times easier to learn and you dont need the speed that c provides anyway.
>>
>>60799660
I get it now. Only **one** number differs in evenness.
>>
>>60799677
Why would returning the index call for searching through the entire list?
>>
File: PT1216_FEATURE_STALLMAN_01.jpg (87KB, 639x632px) Image search: [Google]
PT1216_FEATURE_STALLMAN_01.jpg
87KB, 639x632px
>>60799678
thanks ,my man
>>
>>60799697
>Only **one** number differs in evenness.
oh fuck, that's what i missed.

>>60799682
>>60799677
thanks lads, for a moment i thought i'm actually retarded. it's just that i can't read.
>>
>>60799706
the outlier might be at the very end of the list?
You don't have to keep going if you already found it

why am I even explaining this shit I write driver code for a living
>>
>>60799667
Don't learn java, too easy to fall into bad habits. Learn C, the guy saying you can only build kernels is delusional. At least do c++, java is too automated.
>>
>>60799260
>preparing to pass iq test
>indexes
I think the author might need to take one of those tests.

OP, consider learning a language that encourages functional programming like Lisp, it'll teach you to think of these kind of problems in terms of recursion or mapping a function over a list which leads to very neat solutions.
The Little Schemer is a fantastic book for just this.
>>
>>60799735
This.
I started coding at Uni with Java and got too comfy with it. Adopting other languages were a nightmare.
>>
>>60799720
Work on reading comprehension. That or you responded to the wrong person with the index nonsense.
>>
File: 1494359041320.jpg (733KB, 3702x2198px) Image search: [Google]
1494359041320.jpg
733KB, 3702x2198px
>>60799735
why would you tell a hobby programmer to learn c or c++?why would you put him through the pain of managing your own memory,STL,preprocessor directives,templates and the other retarded shit c and c++ does?
why do you think a hobby programmer wants to fuck around with /0 terminated character arrays and shit when we both know that its completely useless to learn c and c++ for their use case.they are not gonna write speed critical applications or an OS anyway.they want results.and now please go back to your c circlejerk thread grandpa
>>
>>60799766
Same that's why I tell people not to do it, especially without guidance.
>>
>>60799803
C is a great first language.
How can you understand all those abstractions like split and join without knowing how to write them yourself?
Could you even extend your language as needed if if your language didn't have nice things like split and join?

Also, this post reeks of someone who has never touched C or C++.
>>
>>60799764
What would an Scheme solution to OP's problem actually look like?
I see posts all the time talking about how great CL and Scheme are, but I've yet to see any actual Lisp on /g/.
>>
>>60799803
Kek found the pajaeet. Java has too many built in functions. If you're trying to make a shitty app quickly, sure use java. If you want to learn and understand programming, use C
>>
there's nothing wrong with your solution aside from insignificant inefficiency per >>60799341
You just didn't jam the logic into one line is all
>>
>>60799836
oh my fucking god from the skies please help me.CANT YOU ETCH IT INTO YOUR SKULL THAT HE IS NOT A PROFESSIONAL?CANT YOU FUCKING UNDERSTAND THAT HE DOESNT GIVE A SINGLE FUCK HOW SOMETHING GETS ABSTRACTED ANYWAY?THATS WHY HE STARTED WITH PYTHON IN THE FIRST CASE.

i think one of my blood vessels gonna pop can we please start banning c posters already?
>>
>>60799893
How are you supposed to become a professional if you don't even know what your magic standard library is doing?
>>
>>60799341
>this post reflects 99% of posters on /g/
>>
>>60799893
The post implies he wants to be a good programmer. C>Java, end of story.
>>
>>60799901
you really just cant understand it can you?literally when a kid sees a dead body and his mind blocks it to defend itself from the trauma.anon's problem is literally a one-sided mirror to you isnt it?
>>
>>60799931
Are you ok?
You write like you're having a mental breakdown.
Get help.
>>
>>60799931
Everyone here is now stupider after reading that. Thanks a lot anon
>>
File: Screenshot_20170608_023945.jpg (61KB, 425x955px) Image search: [Google]
Screenshot_20170608_023945.jpg
61KB, 425x955px
>>60799735
Don't learn both of those. Start with FASM it's really easy and it has a good README file. But before this learn something about how OS works and kernel calls. Then you should learn x86 instruction set and do FASM for practicing.
>>
>>60799843
>list
(((((()))))))))))))))
>>
>>60799931
Ok, tell me, where did the pointer touch you?
>>
>>60800024
Mov is the most idiotic thing ever invented.
>>
File: 1496011415988.jpg (5KB, 210x230px) Image search: [Google]
1496011415988.jpg
5KB, 210x230px
>>60800068
the problem is that your religious love of c is blinding you and you literally dont have enough brain cells to comprehend that c is not the appropiate language for what anon wants.
>>
File: d.png (46KB, 1128x626px) Image search: [Google]
d.png
46KB, 1128x626px
So you guys are telling me this is the right solution?
https://repl.it/Ib1k/1
>>
>>60800117
you two should just stop
you are not even speaking the same language
once you get on the same page, you can restart
until then, I forbid you to carry this discussion any further
>>
>>60800128
yes, but you only need one loop
you have 3 in there (4 if you count the 4th (obviously))
>>
>>60800095
Why?
>>
>>60800146
how do I do that?
>>
File: endtimes.png (16KB, 699x467px) Image search: [Google]
endtimes.png
16KB, 699x467px
>>60799387
>i don't have :(
you don't have too! See application options
>>
>the first three can give you the answer
Why are you retards saying this as if it means anything? OP's code is bad because it iterates through the entire list regardless of where the important number is instead of stopping when it is found.
>>
>>60799341
Does it say anywhere that there will be 5 and only 5 inputs?
>>
import std.stdio;
import std.string;
import std.range;
import std.conv;

void main()
{
string[] inputs = readln().strip().split();
int[] numbers;
foreach (number; inputs)
numbers ~= number.to!int;

ulong[] uneven_indices, even_indices;
foreach (index, number; numbers)
if (number % 2)
{
uneven_indices ~= index + 1;

}
else
{
even_indices ~= index + 1;
}

writeln(even_indices.length < uneven_indices.length ? even_indices : uneven_indices);
}


Handles unlimited inputs.
$ echo 1 12 12 3 90 11 7 15 | ./evenness
[2, 3, 5]
$ echo 22 34 5 98 86 90 | ./evenness
[3]
>>
File: 1496882086.png (86KB, 1236x630px) Image search: [Google]
1496882086.png
86KB, 1236x630px
>>60800310
https://repl.it/Ib1k/3
it's shit, but only one loop
>>
File: Screenshot_2017-03-21_15-20-03.png (14KB, 542x202px) Image search: [Google]
Screenshot_2017-03-21_15-20-03.png
14KB, 542x202px
How about this?
>>
>>60800700
Boring
>>
>>60800728
Let's see your sieve, then.
>>
>>60800700
I don't get it. What are the people who ask this question testing for?
Is it a retard test? Are they trying to see if you understand what the question is asking?
Is it a pajeet test? Are they trying to see if you will actually write your own prime sieve?
Why wouldn't I just copy someone else's prime sieve and save time?
>>
>>60800700
I've heard that just having a list of all primes up to x is good to do, instead of doing it yourself. How true is that really?
>>
>>60800775
It's on Wikipedia
>>
File: 1496882926.png (35KB, 397x475px) Image search: [Google]
1496882926.png
35KB, 397x475px
>>60800665
https://repl.it/Ib1k/4
improved it a tad
>>
>>60799868
You're book smart but you don't make paper

-Java programmer
>>
>>60800838
Why aren't you reading from the input stream? Why are you expecting only one (un)evenness?
>>
>the best solution
Requires intimate knowledge of the language. Given it's python, so whatever crappy solution is fine because it's gonna be fucking slow anyway, I'd prefer yours. If I found it slow I could easily make it faster. It really is trivial code. I don't even write python and I understand exactly what you're doing.
The other shit has so many things where I'd have to assume semantics of the language.

Also.
>best practices
Is just something people say to claim superiority.
>>
>>60800864
>Expecting a complete program from pythonfaggots
>>
>>60799923
But it actually is more efficient not to indiscriminately go over all the numbers counting odds and evens.
Go over the first two or three (depending on input,) and set a flag to true or false.
Then iterate over the remaining numbers until list[index]%2 == flag, at which point return index+1. Simple.
The "elegant" approach is computationally wasteful.
>>
>>60800864
Because the question dictates that there is only going to be one (1) (un)even number???
>>
>>60800864
>Why aren't you reading from the input stream?
Are you an idiot?
>Why are you expecting only one (un)evenness?
Read the OP and the thread again.

>>60800886
I have never programmed in Python. I just showed the dude how it could be done in a single loop.
>>
>>60800794
>>60800824
If you can't write your own sieve off the top of your head, you're incompetent. It's a trivial algorithm - mark off multiples of primes. There's nothing to "copy", unless you can't actually program.
>>
>>60800963
I'm incompetent and can't actually program, then. Thank you for your analysis.
>>
>>60800955
What's wrong with reading from stdin?
>>
>>60800974
How sad.
>>
>>60800963
Writing your own sieve is literally a waste of time. Any employer that doesn't recognize that is probably staffing Pajeets.
>>
>>60800985
>a waste of time
It's like 6 LOC in Python. The waste of time is you if you can't write it. The concept is trivial, meaning it's fizzbuzz-tier. Are you telling me you also struggle with writing fizzbuzz?
>>
>>60801003
You are very proud of your 6LoC program, aren't you
>>
>>60801013
You are very defensive in your inability to write a sieve. What trivial algorithm can you write, actually?
>>
>>60800979
What's wrong with not reading from stdin?
>>
>>60801025
Cute
>>
>>60801025
Bubble Sort, if I get the pseudocode from somewhere
>>
>>60801037
You have to compile program each time you want to compute different arguments
>>
>>60801050
You don't get it, but you are missing the point
Can't tell if actually autistic
>>
>>60801003
Why would I bother writing my own fizzbuzz when I can just get right answer off of stackoverflow?
like am I supposed to memorize this modular nonsense that will never be used in 99% of programs?
>>
>>60801056
>but you are missing the point
what point?
>>
>>60801003
>Wastes of time are acceptable because it's not a massive waste of time
Hello good sir Sanjeev Balakrishna! Please do the needful and make finished your JavaScript assignment.
>>
>>60799405
THIS
Always write shitty code and refine.
>>
>>60801081
>Always write shitty code and refine.
This is the best way to code that I've found
>>
>>60799260
>the best solution
feh
If argument is passed sensibly as an array of numbers:
let iqTest = n => n.findIndex(a=>(a%2)^(n.slice(0,3).map(x=>x%2).sort()[1]))+1

If argument is passed as a stupid space separated string like in OP's pic:
let iqTest = n => n.split(' ').map(m=>parseInt(m)).findIndex(a=>(a%2)^(n.split(' ').map(m=>parseInt(m)).slice(0,3).map(x=>x%2).sort()[1]))+1
>>
>>60801131
>' '
what if there tabs in between?
>>
>>60801145
They aren't
>>
>>60800700
def sieve(limit):
if limit >= 2:
yield 2
l = [1]*(limit + 1)
for i in range(3, limit + 1, 2):
if l[i]:
yield i
for j in range(i*i, limit, i):
l[j] = 0

print(sum(sieve(2000000)))

142913828922

real 0m0.441s
user 0m0.404s
sys 0m0.012s

Easy. If you struggle with this, you must be mentally deficient.
>>
>>60801154
what if there is? And what happens if you get multiple ' ' s?
>>
>>60801154
>If argument is passed sensibly as an array of numbers
it isn't
>>
>>60801071
>knowing how to program is a waste of time
>knowing how to write an algorithm is a waste of time
>knowing trivial highschool maths is a waste of time
You're literally retarded. Stay in school, kid.
>>
File: anything wrong with this code.png (149KB, 1083x698px) Image search: [Google]
anything wrong with this code.png
149KB, 1083x698px
>>60799677
>if it's 2 2 2 3, you already know it's an even-majority list and you're gonna look for the first odd.
what the fuck are you talking about kiddo
2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

>even-majority list
??????
>>
>>60800700
Easy
import std.stdio;

void main() { writeln(142913828922);}


Your problem is a loser just like yourself
>>
>>60801171
Angry pajeet detected.
>>
>>60801176
This is a malformed input according to the requirements.

Fuck off.
>>
>>60801163
>what if there is?
split on "\t" instead?
>And what happens if you get multiple ' ' s?
Then we've deviated far past the actual purpose of this challenge, but could still do split(/ +/g) or split(/\S+/g) to match spaces and tabs. This would be stupid though.

>>60801164
>it isn't
I know. Try reading the rest of the post
>>
>>60801176
I though the same on first reading him
but turns out he is actually right
>>
>>60799999
>>60800000
>>
>>60801188
>I know. Try reading the rest of the post
oh man this thread keeps on getting dumber and dumber
I'm laughing my ass off
>>
>>60801187
i dont get the requirements
>>
>>60801177
Now find the same minus the sum of primes ending with 1. Except you can't, just like you probably pull out a calculator to add 2+2. The answer is worthless, it's the method.
>>
>>60801227
>sum of primes ending with 1
what does ending with 1 mean?
>>
>>60801235
Forget it, it's too much for you. Back to copying code from SA you go.
>>
>>60801235
think of it as an string
last character in the string == '1'
>>
>>60801249
Uh?
>>
>>60801261
Or think of it as a decimal fucking number where the least significant digit is a 1
>>
>>60801261
Why should I need to think of strings then?
>>
>>60801261
>>60801271
You're both idiots who failed highschool maths. Any number ending with 1 will = 1 (mod 10). E.g. 41 % 10 = 1, so 41 = 1 (mod 10)
>>
>>60801291
>Any number ending with 1 will = 1 (mod 10)
No shit? Nobody contradicted that
>>
>>60801291

we're trying to explain something to a retard who can't even figure out what "ending in 1" means and you want us to use modulo in the explanation? Are you also retarded?
>>
>>60799260
Interested in the haskell solution.
>>
>>60801304
>adding strings to the equation when a modular identity is all that matters
This would translate to more LOC for no reason at all.
>>60801335
The poster is clearly baiting.
>modular
>hard to grasp
You learn this in high school.
>>
>>60799260
>pass an IQ test
>>
>>60801335
What does "ending with 1" means?
>>
>>60801366
>This would translate to more LOC for no reason at all.
Nobody is talking about the code implementation you dumbass. We're trying to explain what the particular phrasing *means* to someone who didn't understand it, not explain to them the best way implement it

Are you actually autistic?
>>
>>60799893
*autistic screeching*
>>
>>60801389
No, you're the autistic person replying to a shitposter like above.
>>
>>60801335
Anon how can a number "end in 1"? Is it normal for a pytoddler to spew nonsense?
>>
>>60799803
>>60799893
Why are you so bad at punctuation? Put a fucking space between your punctuation and the following words
>>
>>60801389
I'm with you, anon
Nvm him
>>
@60801398
>how can the last digit of a number be 1
Who knows.
>>
>>60799405
seriously underrated comment
*everyone* sucks at some point
>>
>>60801424
How can a number "end in 1" though?
>>
>>60799836
honestly I hate C but it was my first language and I agree that it's a good one

but once you're done learning, abandon that shit and never look back
>>
>>60801431
you're either a troll or you walked in to a lot of table corners as a child
>>
>>60799260
You will, Anon, i believe in you :3
>>
>>60801464
Kill yourself you peabrained pajeet. NUMBERS cannot end in anything. The final DIGIT in a number can be defined, though.
>>
One line c

 
#define nigger (7 + ( 8 * (sizeof(int) - 1) ) )
short DoSomeNumShitYouFaggot(const int input[4])
{
return ( (input[0] << nigger == input[2] << nigger)? 4 : 3 ) - ( 2 * (input[0] << nigger != input[1] << nigger);
}
>>
>>60801488
you seriously have Aspergers if you can't parse the phrase "n ends in k" into "the final digit of n is k"

get that shit checked out
>>
>>60801464
Can you answer my question?
>>
>>60801488
I get your point.
>>60801508 doesn't.
>>
>>60801508
Damage control more. It won't make you any less of a moron.
>>
>>60800665
it hurts my brain when I am trying to understand that code :(
>>
>>60801523
What program did you want me to write again?
>>
>>60800700
I would use a sieve of eratosthenes to find the primes
max_prime=2000000
def sieve(size):
array = [True] * size
for each in xrange(3,int(sqrt(size))+1,2):
if array[each]:
array[each*each::2*each]=[False]*((size-each*each-1)/(2*each)+1)
return [2] + [each for each in xrange(3,size,2) if array[each]]

def sumElements(array):
return sum(array)

print "sum of all primes less than " + max_prime + " is: " + sumElements(sieve(max_prime))
>>
>hard on himself because of python meme comprehensions
>>
>>60801542
see >>60801177


O(1)
>>
>>60801559
hey, i know you. didnt you just try to get a job here the other day?

wasnt this your fizzbuzz solution?
Print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz")
>>
>>60801559
>>60801227
>>
>>60801559
See >>60801227
"What does ending with 1-" will also not pass on an interview.
>>
>>60801583
>>60801585

import std.stdio;

void main() { writeln(199999200000);}

Come on, pytoddler at least try
>>
>>60801489
terry pls go
>>
>>60801595
>199999200000
Wrong, retard.
>>
>>60801227
>Now find the same minus the sum of primes ending with 1

prime=2000000
def sieve(size):
array = [True] * size
for each in xrange(3,int(sqrt(size))+1,2):
if array[each]:
array[each*each::2*each]=[False]*((size-each*each-1)/(2*each)+1)
return [2] + [each for each in xrange(3,size,2) if array[each]]

def sumElements(array):
return sum(array) - totalToSubtract(array)

def totalToSubtract(array):
total=0
for each in array:
if each%10==1:
total+each
return total

print "sum of all primes less than " + max_prime + "minus every prime ending in 1 is: " + (sumElements(sieve(max_prime))
>>
>>60801631
Except it literally isn't, pytoddler
import std.stdio, std.bigint;

void main()
{
auto n = 2_000_000;
BigInt sum;
foreach (i; 1..n+1)
{
if (i%10==1) sum += i;
}
writeln(sum);
}
>>
>>60801585
>Add a single check for the final digit being 1 in any sieve you want copied from anywhere
If you want someone to prove their abilities you shouldn't be asking for prime number sieves.
>>
>>60799901
Do you understand how you car works, how the turbo charger delivers fuel and how the engine stays in sync with the fuel injectors? Probably not. Yet you can still drive it become an Uber / Taxi driver and make money right?

Same concept applies here. Survival of the fittest does not necessarily mean survival of the smartest.
>>
>>60801665
Someone has to understand these things to build that car you're driving.
>>
from math import sqrt
max_prime=2000000
def sieve(size):
array = [True] * size
for each in xrange(3,int(sqrt(size))+1,2):
if array[each]:
array[each*each::2*each]=[False]*((size-each*each-1)/(2*each)+1)
return [2] + [each for each in xrange(3,size,2) if array[each]]

def sumElements(array):
return sum(array) - totalToSubtract(array)

def totalToSubtract(array):
total=0
for each in array:
if each%10==1:
total+each
return total

print "sum of all primes less than " + str(max_prime) + " minus every prime ending in 1 is:\n" + str((sumElements(sieve(max_prime))))


>>sum of all primes less than 2000000 minus every prime ending in 1 is:
142913828922
>>
>python code artisan getting thoroughly BTFO
kek
>>
>>60801673
You are like the perpetually angry mathfags on /sci/ that tell me math is not a colorful toolbox and that I actually need to know how it works to use it. Protip: I don't, and neither do most engineers.
>>
>>60801654
It appears you summed the numbers below 2 million with last digits ending on 1. I'm afraid this was not the problem in question. Thank you, you'll be hearing back from us.
>>
>>60801712
What program does the pytoddler need me to write now?
>>
>>60801660
>copy
>sieve
>copying anything
You fail already.
>>
>>60801712
How can a number "end on" 1, rakesh?
>>
>>60801712
>>60801738
How can a last digit "end on 1"?? wtf is the nu-pytoddler speak?
>>
>>60801691
>142913828922
No, this is the sum of all primes.
>>60801725
The sum of all primes below 2 million whose last digit is not 1.
>>
>>60801752
your right. I forgot the = sign at line 17: total += each

corrected
from math import sqrt
max_prime=2000000
def sieve(size):
array = [True] * size
for each in xrange(3,int(sqrt(size))+1,2):
if array[each]:
array[each*each::2*each]=[False]*((size-each*each-1)/(2*each)+1)
return [2] + [each for each in xrange(3,size,2) if array[each]]

def sumElements(array):
return sum(array) - totalToSubtract(array)

def totalToSubtract(array):
total=0
for each in range(len(array)):
if array[each]%10==1:
total+=each
print 'total is: ' + str(total)
return total

print "sum of all primes less than " + str(max_prime) + " minus every prime ending in 1 is:\n" + str((sumElements(sieve(max_prime))))

>>
>>60801765
output:
>>>sum of all primes less than 2000000 minus every prime ending in 1 is:
140144461002
>>
>>60801752
>The sum of all primes below 2 million whose last digit is not 1.
Come on, pytoddler


import std.stdio;

void main() { writeln(1800001800000);}
>>
Can we make one thread like this daily, where OP posts a problem and we all solve it in our language of choice and discuss different solutions?
Could be interesting.
>>
>>60801712
>last digits ending on 1.
Parjeet my son..
>>
>>60799260
Is there any book on coding optimization or similar? I have the same problem but I can improve.
>>
File: you.jpg (9KB, 212x123px) Image search: [Google]
you.jpg
9KB, 212x123px
>>60801779
id rather banter and call people faggots.

but meh, I guess i could go either way
>>
File: 1496888460.png (40KB, 592x457px) Image search: [Google]
1496888460.png
40KB, 592x457px
>>60800838
https://repl.it/Ib1k/5
Getting clever
>>
>>60801774
Incorrect, I'm afraid.
>>60801777
Wrong, you fucking retard. What's the matter, can't to trivial maths? Did you drop out of high school?
>>
>>60801831
>Wrong
Except it isn't, pytoddler
>>
>>60801731
>he thinks he can write a better algorithm than primesieve
just kill yourself pajeet.
>>
>>60801847
>>60801831
pajeet, how can a last digit "end on" 1?
>>
File: 1442851614517.jpg (100KB, 540x394px) Image search: [Google]
1442851614517.jpg
100KB, 540x394px
>>60801838
>>> sum(i for i in primes.sieve(2e6) if i%10 != 1)
107227422774

BTFO. Now we know who the real pajeet is, Pajeet. Next you'll be claiming you're white, too.
>>
>>60801863
>107227422774
Dumb fucking pajeet doesn't know his sum is overflowing
LOL
>>
>>60801818
we need to compare execution time
>>
>>60799260
The best solution is crap as well. Unnecessary copy of string to array of numbers
>>
>>60801879
>python
>overflow
Hello, Pajeet.
>>
readable code > clever code

/thread
>>
>>60801898
>Python pajeet pretending he knows what overflows even mean
top quality comedy pajeet. Go poo in the loo
>>
Nice troll faggot ALL are smaefags
>>
>>60801909
This
>>
>>60801909
>>60801920
All me, pajeet
>>
>>60801530
yes it's really shit
the point was solving it in a single loop
what about the later revisions? can you read them?
>>
>>60801901
Maybe for code that goes into production, but the point of these challenges are to be clever.
Nobody's going to need to read them in 6 years and figure out what they do so they can modify them. They're just meant to give you the opportunity to have fun writing code in a way that's neat to you
>>
>>60801818
>>60800838
>>60799260
if there is always going to be only one number with a different mod 2 than all the others this is quite easy to solve.
>>> def iq_test(numbers):
count=[0,0]
recent=[0,0]
for each in numbers:
count[each%2]+=1
recent[each%2]=each
return (recent[int(count[1]<count[0])])


>>> iq_test([11,5,3,8,7])
8

>>
>>60800700
import std.conv;
import std.stdio;
import std.range;

void main(string[] args)
{
immutable max = (1 < args.length)
? args[1].to!size_t
: 0x4000;
size_t count = 1; // we have 2.
// flags[i] = isPrime(2 * i + 3)
auto flags = new bool[(max - 1) / 2];
flags[] = true;

foreach (i; 0..flags.length)
{
if (!flags[i])
continue;
auto prime = i + i + 3;
foreach (k; iota(i + prime, flags.length, prime))
flags[k] = false;

count++;
}
writefln("%d primes", count);
}


Rate my prime sieve
>>
>>60801953
I like it
>>
>>60801961
>
foreach (i; 0..flags.length)
{
if (!flags[i])
continue;
auto prime = i + i + 3;
foreach (k; iota(i + prime, flags.length, prime))
flags[k] = false;

count++;
}


That's actually pretty nice. But why 0x4000?
>>
>>60801879
>>60801905
there was no overflow tho. that is the correct answer
>>
>>60799260
learn list comprehension, nigger
>>
>>60802011
>0x4000
for a good giggle, keeps babbies out
>>
>>60801953
doesn't return the index and needlessly iterates after finding the target number.

2/10
>>
>>60801961
Needlessly autistic/10
>>
>>60802062
>Your brain in python
>>
>>60801889
$ time python3 60799260.py
8209

real 0m0.039s
user 0m0.032s
sys 0m0.004s
$ time python3 60801818.py
8209

real 0m0.035s
user 0m0.032s
sys 0m0.000s
$


it's a 100k column input string or so
want another one tested?
>>
>>60802085
But my Python sieve is equivalent.
>>
>>60802104
No, I don't think python can even match in terms of speed
>>
>>60802104
>>60802116
>inb4 hurr but complexity class
>>
>>60802118
Oh, are you still butthurt about the jokes I made about my "solutions" being O(1).

Sucks to be you, I have compile time loop evaluation/code generation
>>
>>60802116
I meant in implementation. And if we're talking about performance, then they're both shit, as they're not segmented, not wheel factorized, and don't use a bit array. Memory requirements are thus O(n).
>>
>>60802045
nobody specified return the index but i agree that the algorithm should stop after it has minimum required information for decision:

>>> def iq_test(numbers):
count=[0,0]
recent=[0,0]
for each in numbers:
count[each%2]+=1
recent[each%2]=each
if abs(count[0]-count[1]) >= 2 and bool(count[0]) and bool(count[1]):
return (recent[int(count[1]<count[0])])


>>> iq_test([11,5,3,8,7])
8
>>>
>>
>>60802143
I could easily use CTFE to generate the result at compile time so it saves on runtime performance
>>
>>60802134
>the jokes I made about my "solutions" being O(1).
I have no idea what you're talking about. I was predicting a response talking about how both solutions have the same complexity class so they're equivalent, even though one will take several times longer to run than the other.
>>
>>60802166
>O(1)
>I have no idea what you're talking about.
t. highschool freshman
>>
>>60802174
That's not what he meant
>>
>>60802159
Completely irrelevant. Time complexity is still the same to Python code. Your sieve is a toy.
>>
>>60802158
>nobody specified return the index
"Help Bob to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number."
>>
>>60802182
>Time complexity is still the same to Python code.
Nope, if I use CTFE i'll constantly obtain O(1), it's just computing a constant
>>
>>60802186
welp, thats it, I give up. too complicated for me now, this is a job for elliot anderson
>>
>>60802097
I see (samefagging hard)
>>
I was terribad at routines and my code looked like spaghetti
>>
>>60802186
>>60802199
I said I give up, but I got elliot anderson AKA mr robot to help me out with this insurmountable problem of returning an index instead of its referenced value

>>> def iq_test(numbers):
count=[0,0]
recent=[0,0]
for each in range(len(numbers)):
count[numbers[each]%2]+=1
recent[numbers[each]%2]=each
if abs(count[0]-count[1]) >= 2 and bool(count[0]) and bool(count[1]):
return (recent[int(count[1]<count[0])])


>>> iq_test([11,5,3,8,7])
3
>>>
>>
>>60801603
just for you I made one for array of n > 2 numbers that's one line:

#define nigger (7 + 8 * (sizeof(int) -1))

int whiteGenocideIsAChoice(const int* input, const int size, const int index)
{
return 1 + ((index == size - 2) ? (((*input) << nigger == *(input - 1) << dis)? 1 : 0) : ((((index < size - 2)) && ((*input) << nigger == (*(input + 1) << nigger) || (*input) << nigger == (*(input + 2) << nigger))) ? doNums(input + 1, size, index + 1) : 0));
}
>>
>>60801220
Clearly. Only one of the numbers can be in the minority, all of the rest MUST be in the majority according to the requirements
>>
>>60802675
ops replace the "dis" with "nigger" I was trying something then realized it was gay.

here's the fixed code:

#define nigger (7 + 8 * (sizeof(int) -1))

int whiteGenocideIsAChoice(const int* input, const int size, const int index)
{
return 1 + ((index == size - 2) ? (((*input) << nigger == *(input - 1) << nigger)? 1 : 0) : ((((index < size - 2)) && ((*input) << nigger == (*(input + 1) << nigger) || (*input) << nigger == (*(input + 2) << nigger))) ? doNums(input + 1, size, index + 1) : 0));
}
>>
>>60801665
This isn't even necessarily of the smartest, more like "more knowledgable"
He can always learn the abstractions later if he's really interested
>>
>>60802708
>GitHub SJW's are insane, racist code doesn't exi-
>>
>>60800985
>an employer that doesn't hire employees that copy/paste code off the internet is probably the one hiring Pajeets

Bro, all Pajeets do is copy/paste code off the internet, then copy blog posts about it and spam people on Linkedin. Wanting people who can think is the mark of a company that hires people who aren't Pajeets.
Thread posts: 225
Thread images: 15


[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.