[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 23
File: 1422385664777_6.jpg (438 KB, 2500x1000) Image search: [Google]
1422385664777_6.jpg
438 KB, 2500x1000
Old /dpt/ at >>52152484

What are you working on?

HAPPY NEW YEAR EVERYONE!
>>
First for Java
>>
Xth for Go.
>>
Programming is shit
>>
Java a shit
>>
File: 1451551029327.png (402 KB, 1024x768) Image search: [Google]
1451551029327.png
402 KB, 1024x768
nth for FizzBuzz of the Christ
>>
nth for Go
>>
How good is Qt for C++?
>>
>>52158633
For loops are deprecated
>>
File: genocide.png (62 KB, 1024x578) Image search: [Google]
genocide.png
62 KB, 1024x578
>>52158671
The only thing I hate about Qt is the fact that the wrote their own STL.
>>
File: functional-right.jpg (512 KB, 1131x1600) Image search: [Google]
functional-right.jpg
512 KB, 1131x1600
spending too long on these advent of coding problems
will I make it /dpt/?
pic related
>>
QUICK; POST A FUNCTION TO COUNT THE AMOUNT OF WORDS IN A STRING, IN YOUR LANGUAGE OF CHOICE
>>
>>52158633
Now do it without using a loop with a similar number of characters. .
>>
>>52158558
So how do you actually use Qt?
>>
>>52158671
Qt is mediocre, which makes it roughly as good as or better than the other options.

Downsides: defining their own string, vector, etc types, Mocha (reflection system), defining a bunch of shit that should have been left to the OS (e.g. threads) *and insisting you use it* (e.g. "thread-safe" functions are only safe from another QThread, not from a vanilla OS thread).

Also, they didn't put much thought into subclassing (i.e. don't expect to be able to derive from any of the widget classes beyond the completely generic ones). Or into documenting event dispatch (there are a couple of dozen different methods you can override to affect event handling, and the interactions between them aren't documented anywhere).
>>
>>52158853
Assuming space delimited string
string => string.split(' ').length
>>
>>52158671
The best by far. Nothing even comes close.
>>
>>52158853
def count_words(text):
return len(text.split(" "))
>>
>>52158853
wordCount = length . words
>>
Daily reminder that if your language of choice is not on this list you should probably give up and kill yourself:
- C++
- C#
- Lua
- Python
- Elixir
- Haskell
- Bash
- Clojure
- D
>>
>>52158853
OCaml
String.split ~on:' ' s |> List.length
>>
>>52159024
>Bash
Daily reminder to kill yourself.
>>
>>52159024
Replace Haskell with Java and I would agree.
>>
>>52159024
>Bash
>Haskell
kek
>>
>>52158853
int func(char *s)
{
int ctr=0;
while(*s != '\0')
{
if(*s==' ')
{
ctr++;
s++;
while(*s==' ' && *s!='\0')
{
s++;
}
}
s++;
}
return ctr;
}
>>
>>52158954
count_words("                      ")


Literally kill yourself 2bh
>>
which is better python 2.7 or python 3.4?
>>
>>52159024
Lua
>meme trash
>>
>>52159116
haskell
>>
>>52159116
3.4 is technically better but there's a lot of 2.7 libraries that aren't compatible with it. many people still use 2.7 because of this.
>>
>>52158853
String input = "Any random string"; 
String [] output = input.split(" ");
int answer = output.length;
>>
>>52159116
>which is better stalin or hitler
hitler obviously
>>
>>52159116
I still wonder how they were able to fuck up the community so much.
>>
>>52159167
>>52159044
>>52158954
>>52158946
Wrong.
>>
>>52158853
unsigned word_count(const char *str)
{
unsigned count = 0;
unsigned len = strlen(str);
char *tmp = (char *) malloc(sizeof(char) * len + 1);
strcpy(tmp, str);
char *token = strtok(tmp, " ");
while (token != NULL)
{
count++;
token = strtok(NULL, " ");
}
free(tmp);
return count;
}
>>
>>52159191
>>52159107
def count_words(text):
return len(text.strip().split(" "))
>>
astring.match(/\w/g).length
>>
>>52159234
*gm
>>
>>52159226
count_words("Literally               kill            your                 self")
>>
>>52159162
so i should learn 2.7? is there much difference between them?
>>
>>52159193
>>52159074
C-ucks still argue their language isn't shit, lel.
>>
File: 1365497420654.png (58 KB, 447x436) Image search: [Google]
1365497420654.png
58 KB, 447x436
>>52158853
int word_count(const char* s)
{
int c = 0;
char p = *s;
while (p != '\0')
{
s++;
if (p != ' ' && (*s == ' ' || *s == '\0'))
c++;
p = *s;
}
return c;
}
>>
>>52159351
But hey, at least it's the fastest, right?
>>
>>52159351
At least my solution works.
printf("%d\n", word_count("Literally               kill            your                 self"));

./word
4

>>52159261
4
>>
>>52159316
i would just learn 3.4, and if you find a library that needs 2.7 then go back and see what's different. there aren't a ton of differences.
>>
>>52159366
I hear a C program is three times as fast as a program in any other language
>>
>>52159191
You're right, should be
input.split("\\s+");
>>
>>52159383
>only 3 times as fast
I could lose 80 pounds by chopping off one of my legs too. Doesn't mean I'm gonna do it.
>>
>>52159358
why do c-ucks get sick kicks out of making their programs indecipherable with 1-letter variable names?
>>
>>52159358
>>52159074
>>52159193
Test it with
"   You     are     wrong     "

>>52159393
Not even sure what language that is so I'll take your word for it
>>
>>52159429
>i don't know how to implement the tools that I use
webdev babby detected
>>
>>52159434
Faster compilation. You should also never use comments or formatting, and should only use the minimum possible whitespace.
>>
>>52159261

Here it is in C#.

static int count_words(string s)
{
return s.SplNoEm(' ').Length;
}

:^)
>>
>>52159444

>>52159193 here
3
>>
>>52153138
>
auto sq = cast(typeof(num))sqrt(cast(real)num);

>Is just detritus left over from when I was trying to make something typecheck correctly.
auto/var fags everyone
>>
>>52159455
>if you want to build a house, you better know how to mine the ore, smelt your own steel, cut your own wood, and craft your own hammer, before you even think about using it to hammer in any nails
>>
>>52159477
>not knowing how to make a smelter
"C is low level" fag detected
>>
>>52159477
This is more akin to you forging your own hammer for use in your projects that works better for your situation than the hammers they sell in stores.
Stop being dense.
>>
>>52159477
scooby built his own house

contractors generally do a shit job at building houses

just look at those paper houses in murrica
>>
>>52159506
>specialised hammer
This is what C programmers actually believe
>>
Is there literally any reason to use separate compilation? Seems like it's totally fucking useless. If you have the source code why not just #include it?
>>
>>52158853
fite me cunt
def noOfWords(text):
wordCount=0
startWord=False
for i in text:
if startWord and i==" ":
startWord=False
wordCount+=1
if not startWord and i!=" ":
startWord=True
return wordCount
>>
>>52159521
>durr durr merican houses suck lmao

If I had a nickel for every time a retardo Yuropeon said this, I'd have quite a few nickels.
>>
>>52159383
not necessarily. for example, hello world


python:
print "hello world"


C:
#include <stdio.h>

int main(void)
{
for (int i = 0; i < 100000000; i++) {
continue;
}
printf("Hello World\n");
return 0;
}


my point is speed depends on the programmer's skill to some degree.
>>
>>52159525
When you start building large projects that take more than 1 second to compile, you'll learn to appreciate the amount of time saved when you only need to recompile objects and not the entire program.
>>
>>52159506
>wasting all this time forging your own shitty hammer to build a house when you could've just bought one machined by people with much better equipment, R&D, quality-control, and if their hammer breaks you can send it in for a refund
>>
>his hammer isn't made of adamantium
And you call your language low-level
>>
>>52159191
Str.split (Str.regexp "[ \t\n]+") s |> List.count ~f:(function | "" -> false | _ -> true)

HAPPY?
>>
>>52159541
you have no idea what you're talking about
write an algorithm that actually demands CPU time from the kernel before making such blanket statements
>>
>>52159541

The C program will still be 3x faster on a decent compiler.
>>
>>52159547
Is this true? I've converted a relatively large project (~400k LOC) to a single translation unit build and the compile time went from 4 minutes to 14 seconds.
>>
>>52159552
>aspiring to build these kinds of houses
>>
File: lets see you do better.jpg (140 KB, 1280x720) Image search: [Google]
lets see you do better.jpg
140 KB, 1280x720
>>52159596
>implying
>>
>he didn't mine his own silicon ore and smelt it into his computer
lmao you lot aren't good enough for /g/
>>
>>52159457
>Implying variable names aren't solely for the programmer and they don't get changed to memory addresses upon compilation and your program won't run at exactly the same speed no matter how long you make your variable names
Cuck
>>
>>52159614
pretty sure he's trolling lad
if not, there's no saving this general
>>
>>52159552
>refund
lol
open source libraries offer no warranty
>>
>>52159614
Maybe you should read that again, Gosling.
>>
>>52159562
Str.(split (regexp "[ \t\n]+") s) |> List.length;;

Fixed.
>>
How many of you actually program in vim?
>>
>>52159612

I admire James May in a totally heterosexual way.
>>
>>52159647
I program in nano.
it's pretty much the same thing, but the learning curve is zero.
>>
>>52159647
Yes.
>>
>>52158853
(define (deep-length lst)
(cond ((null? lst) 0)
((atom? lst) 1)
(else (+ (deep-length (car lst))
(deep-length (cdr lst)))))
(deep-length (read (open-input-string str)))

looked around for deep-length but couldn't find a native implementation
>>
>>52159647
I program in Emacs with vim keybindings. In fact, I'm shitposting in this thread with my custom 4chan mode. :^)

Can't imagine anyone seriously uses vim, it's shit.
>>
>>52159657
But you're into black women so you're also a total homosex faggot
>>
>>52159647
I use it for quick scripts and general file editing, but when I'm doing any serious programming I use an IDE.
>>
>>52159530
Learn this: https://docs.python.org/2/library/
What you wrote can be done in 2 lines max using built-in methods.
>>
File: lol.jpg (9 KB, 289x175) Image search: [Google]
lol.jpg
9 KB, 289x175
>>52159701
>python
>>
>>52159674
>(open-input-string str)
should be
 (open-input-string (string-append "(" str ")"))
>>
>>52159683
>black WOMEN
>homosex

Lad, I..
>>
>>52159647
I use Sublime 3 with vim keybindings. (the vim keybinding plugin sucks though, it pisses me off daily)
>>
>>52159701
not with his fucking demanding restrictions m8, u pullin me leg? i'll knock u out
>>
File: Niggerturd.jpg (95 KB, 358x501) Image search: [Google]
Niggerturd.jpg
95 KB, 358x501
>>52159730
>sheboons
>""""""""""women""""""""""
>>
>>52159730
You're totally straight, you just want women as high test as possible
>>
>>52158853
llength $str
>>
>>52159468
>>52159261
Blows up on null. Wasteful memory requirement for large strings. Ignorant of UTF-8 space separators. Doesn't work with tabs, line-feeds or carriage returns.

Kids these days...
>>
>>52159749
kek
>>
>>52158853

$input = "asdfghjk qwerty sdfg "
echo $input | wc -w
>>
>>52159751

Look, I like big fat black asses. I can't help it.

>>52159749

Racism isn't funny. :)
>>
/dpt/, show me your best """frob"""
>>
>>52159434
because it looks cool senpai
>>
>>52158853
function countWords(sentence) {
return sentence.replace(/[ ]{2,}/g, " ").split(" ").length;
}


In JavaScript, God's favourite programming language.
>>
>>52159794
You won't survive the day of the rope
>>
>>52159719
>>52159738
def count_words(string):
return len(string.split())


Plebs
>>
>>52159444
>" You are wrong "
Gives 3 for >>52159358
>>
Hey buds. Im working with boids (intellegent particles) using pygame and python. For some reason the sprites always go to the bottom right of the window can someone please help. http://pastebin.com/ZeATad9M
>>
>>52159824
I was just pullin your leg lmao
>>
>>52159786
>Blows up on null. Wasteful memory requirement for large strings. Ignorant of UTF-8 space separators. Doesn't work with tabs, line-feeds or carriage returns.

string t0  = null;
Console.WriteLine(count_words(t0));
string t1 = "This\r\n\r\n\tis a test.";
Console.WriteLine(count_words(t1));


0
4
>>
>>52159191
But it isn't? You never stated what kind of string, faggot, so that means a space delimited one.
>>
>>52159823
DOTR is pure populism. I bet you have read neither Moldbug nor Evola. Now is a good time to fix that.
>>
>>52159867
He said count all the words in a string m8
Why the salt you aren't even hashing
>>
>>52158853
ulong count(string str)
{
return split(str).length;
}


Everyone else btfo
>>
>>52159822
God's favourite programming language is Python, and the holy fizzbuzz

>>52159848
>>>/g/sqt/
>>
Help, the binary search in K&R isn't working, can someone fix this for me?


int kr_binsearch(int x, int v[], int n)
{
/* binsearch: find x in v[0] <= v[1] <= ... <= v[n-1] */
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high) {
mid = (low+high)/2;
if (x < v[mid])
high = mid + 1;
else if (x > v[mid])
low = mid + 1;
else /* found match */
return mid;
}
return -1; /* no match */
}

int main(void)
{
int arr[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 20};
int n = (sizeof(arr) / sizeof(arr[0]));
int x = 2;

kr_binsearch(x, arr, n);

return 0;
}

>>
I did it boys!
>>
>>52159234
>>52159260

NOTICE ME SENPAI
>>
>>52159701
That's not the point of the challenge
>>
>>52159927
the absolute madman
>>
>>52159866
error CS1061: Type `string' does not contain a definition for `SplNoEm' and no extension method `SplNoEm' of type `string' could be found. Are you missing an assembly reference?
>>
>>52159927
did what?
>>
>>52159965

You have to write the extension method first.
>>
>>52159927
>says it again
absolute madman
>>
>>52159927
source or gtfo
>>
File: tomoko lite uses thinkpaddu.png (984 KB, 1920x1080) Image search: [Google]
tomoko lite uses thinkpaddu.png
984 KB, 1920x1080
So how does one learn javascript?
Do I use the interpreter in my browser, or do I start with a framework and avoid pure js, or what?
>>
>>59715528
Most jobs are like that,doesn't matter if you're a engineer or plumber.>>52159024
>Daily reminder that if your language of choice is not on this list you should probably give up and kill yourself:
>- C++
Ok, if you are developing software that need performance.
>- C#
Replace with Java.
>- Lua
Lol useless shit
>- Python
Ok, not to write enterprise applications but small application that do not need big performance
>- Elixir
Useless cral
>- Haskell
Useless crap
>- Bash
Important if you are working as Linux system admin or in a Linux environment in general
>- Clojure
Shit
>- D
Shit
>>
>>52160067
>webdev meme
>>
>>52159993
okay now i know you're just a troll, you fucking faggot homo
>>
>>52160067
Just learn jQuery.
>>
>>52160069
>>- D
>Shit
I disagree
>>
>>52160090
fuck jquery build a site with angular
>>
>>52160069
>Replacing C# with Java
Literally why? At least C# runs fast and has SIMD. Java is just shit.
>>
>>52160069
>>>59715528
time traveller???
>>
>>52160069
>Replace with Java.
Ha Ha
C# is literally just a better version of Java, why would you use Java over C#?
>>
>>52160082

I wrote the extension method myself. All it does is hide a few things because there's no split that takes (char, StringSplitOption), only (char[], StringSplitOption).
>>
>>52159647
I do, less distractions when I don't run a GUI
>>
>>52160110

both are shit tbqh
>>
>>52160110
if you prefer the language that's one thing but C# runs about as fast as or a bit slower than java
>>
>>52160130
No it doesn't. Java doesn't support SIMD. C# does. Therefore C# can run up to 8x faster than Java (on AVX-256 CPUs).
>>
Why is Haskell useless?
>>
>>52160069
Elixir is not cral. It's actually very nice for a lot of things.
>>
>>52160110
>>52160116
Portability. (mono a shit)
Huge community.
Millions of frameworks.
Android development.

>java slow meme
https://benchmarksgame.alioth.debian.org/u64q/csharp.html
>>
File: temp.png (71 KB, 634x376) Image search: [Google]
temp.png
71 KB, 634x376
>>52160151
k tard

see pic related

now i know it has mono and not .NET

but if you think java is slow and C# is fast you're a memer
>>
>>52160192
Mono doesn't count. It's shit. Compare it to native code.
>>
>>52160200
F#, no!
>>
>>52160202
if C# were 8 times faster than java it'd be faster than C... lol
>>
>>52160200
>now i know it has mono and not .NET

You realize that's a pretty big deal, right?
>>
>>52160244
No, because C code can use SIMD as well.
>>
File: ew.png (272 KB, 470x624) Image search: [Google]
ew.png
272 KB, 470x624
>>52160067
You make things in JavaScript, anon.

I recommend these:
https://developer.mozilla.org/en-US/docs/Web/JavaScript
https://www.youtube.com/watch?v=zf_cb_Nw5zY

Ignore the anti-webdev cucks, JavaScript is welcome here.

Don't start messing with a frameworks until you have a basic understanding of JavaScript.
>>
Can't wait till F# native desu
>>
Is there any way to make this method more efficient in C++? It's just supposed to find the sum of the numbers 1 to n.

int f(int n)
{
int t = n;
while (--n != 0)
t += n;
return t;
}
>>
>write a brainfuck interpreter in c
>try to run hello world on it
admin$ ./brainfuck brainfuck.txt
???
?
brainfuck(16636,0x7fff7f2bf000) malloc: *** error for object 0x7fb223c03162: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

wtf
>>
>>52160246
no because the claim was
>At least C# runs fast
implying java is slow

the chart shows that java isn't slow or at least around the same order of magnitude as C# .NET
>>
File: tj.gif (1023 KB, 500x362) Image search: [Google]
tj.gif
1023 KB, 500x362
A cleanup goto at the end of a function is the single most readable, maintainable, and comprehensible way to clean up in C. Prove me wrong.
>>
>>52160269
return (n*(n+1))/2;
>>
>>52160269
int f(int n)
{
if (!n)
return 0;
return n + f(n - 1);
}

;^»
>>
>>52160269
yeah m8 use python as a dll, then run it from there
>>
>>52160276
The char is bad, though. They explicitly don't let you take advantage of things like SIMD, which if you care about speed, you *will* do.

C# can SIMD, Java can't. It's that simple.
>>
>>52160272
Pretty clear error desu
>>
>>52160282
Now I feel stupid, thanks anon.
>>
>>52160200
you can squeeze performance out of C# in some niche areas (SIMD/fixed memory + pointers) which control (or even possibility, afaik no compiler will even automatically unroll loops to use SIMD for Java, while in C# you can fine-tune it manually) you don't have in JAVA.

Of course, if you don't use that additional control, the performance is roughly the same on Windows, while on Linux Mono is obvioulsy lags behind Java. Would like to see those tests re-run with .Net Core now that it's out, but almost certainly Java still performs far better on Linux
>>
>>52160252
Java uses simd as well but for simple code.
There are several bug tickets about this issue and will probably be fixed with Java 9.
>>
>>52160304
No worries lol
Learn a bit more maths
>>
>>52160299
if you care about speed you will use C/C++, not C#
>>
>>52160289

genius detected

>inb4 bait
>>
>>52160299
>They explicitly don't let you take advantage of things like SIMD

source?
>>
>>52160303
I've already used calloc on the variable it returns an error.
>>
>>52159924
This should work.

#include <stdio.h>
#define DEBUG 0
int kr_binsearch(int x, int v[], int n)
{
/* binsearch: find x in v[0] <= v[1] <= ... <= v[n-1] */
int low, high, mid;
low = 0;
high = n - 1;
if (x == v[high])
return high;

while (high - low > 1) {
#if DEBUG
printf("%d %d %d\n", low, mid, high);
#endif
mid = (low + high)/2;
if (x < v[mid])
high = mid;
else if (x > v[mid])
low = mid;
else /* found match */
return mid;
}
return -1; /* no match */
}

int main(void)
{
int arr[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 20};
int n = (sizeof(arr) / sizeof(arr[0]));

for (int i = 0; i < n; i++) {
printf("Found %d at index %d\n", arr[i], kr_binsearch(arr[i], arr, n));
}
printf("Searching for %d... Got %d.\n", 2, kr_binsearch(2, arr, n));
printf("Searching for %d... Got %d.\n", -57, kr_binsearch(-57, arr, n));
printf("Searching for %d... Got %d.\n", 42, kr_binsearch(42, arr, n));
return 0;
}
>>
>>52159074
>no strtok
do you even C?
>>
>>52160328
Post source
>>
>>52160325
Yes. And if you care about speed but don't want to write C/C++, you will write C#. Java is useless, outdated shit.
>>
>>52160309
C# does not have proper SIMD support
>>
>>52160326
c# was the b8 m8
>>
>>52160254
look at all those beta low test limp-wristed cucks teaching javascript
>>
>>52160324
I actually knew about the formula that's why I felt so stupid for not realizing I could use it.
>>
>>52160269
Here's the recursive solution:
int kek(int n){
if(n > 0)
return n + kek(n-1);
return 0;
}
>>
>>52160309
You can fine tune the JVM as well.
>>
>>52160338
Awesome, thanks anon. I like K&R but the issues are annoying sometimes.
>>
>>52160325
if you want to develop a (functionally) complex app without at least a dozen code monkey/droids, you won't touch C/C++, that simple
>>
>>52160338
>>52160356
You're welcome but I found a bug in my code. Replace

    if (x == v[high])
return high;


with

    if (x == v[low])
return low;
if (x == v[high])
return high;
>>
File: 1451337320315.jpg (25 KB, 400x386) Image search: [Google]
1451337320315.jpg
25 KB, 400x386
>the C# version was still slower than the Java version, despite my use of the special SIMD instructions
>Undeterred, I thought I would try to use SIMD to improve another C# benchmark, and took a shot at the N-body benchmark test. Once again, the version I wrote, in my hands, was much faster. But when submitted to the shoot-out and accepted, it was either much slower, or didn’t even run. My submission using the SSE instructions not only didn’t beat Java, it was actually slower than the original C# version!

>C# and Java have no meaningful performance differences.
>C# and Java have no meaningful performance differences.
>C# and Java have no meaningful performance differences.

>As a result of using all the registers used, the Java code has great pipelining. Note that up to 5 vmulsd instructions show up at once. The JVM is simply brilliant at packing operations together, and this means that even though I, the programmer, was smart and used SSE2, my C# code only won by 20%, and not 200%. It’s hard to beat Java pipelining.

http://evolvedmicrobe.com/blogs/?p=299
>>
>>52160346
What is it you can't manually SIMD in C# that you can in C++?
>>
>>52160384
It's only because mono is shit. Again, with native code and AVX-256, C# outperforms Java by a factor of 4+. Can't wait until it's up to 8x when AVX-512 becomes mainstream!
>>
>>52160355
>You can fine tune the JVM as well.

wat

You can, but it'll only run on your rig..
>>
Why is this:

#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#define DIGITS 2;

bool palindrome(int x);

int main(){
int n1 = pow(10, DIGITS-1);
int n2 = n1;
//const int TOP = pow(10, 2*DIGITS);
int j=0;
while(j<5){
int a;
scanf("%d", &a);
if(palindrome(a))
printf("ye");
else
printf("lmao");
}
return 0;
}

bool palindrome(int x){
char num[DIGITS*2];
sprintf(num, "%d", x);
int i=0;
while(i<DIGITS){
if(num[i] != num[DIGITS-(i+1)])
return false;
}
return true;
}


giving me this?

jews@didNineEleven:~/Programs$ gcc 4.c
4.c: In function ‘main’:
4.c:9:19: error: expected ‘)’ before ‘;’ token
4.c: In function ‘palindrome’:
4.c:25:11: error: expected ‘]’ before ‘;’ token
4.c:26:10: error: ‘num’ undeclared (first use in this function)
4.c:26:10: note: each undeclared identifier is reported only once for each function it appears in
4.c:28:10: error: expected ‘)’ before ‘;’ token
4.c:29:20: error: expected ‘]’ before ‘;’ token
>>
>>52158853

int words (char *p)
{
int words = 0;
while (*p == ' ')
p++;

while (*p != '\0') {
if (*p == ' ') {
while (*p == ' ')
p++;
}
else {
words++;
while (*p != ' ' && *p != '\0')
p++;
}
}

return words;
}
>>
>>52160384
>http://evolvedmicrobe.com/blogs/?p=299

That's Xamarin Mono versus Oracle JVM comparison on Mac, misleadingly named by a Java (and most likely Apple-) shill
>>
>>52160340
nvm figured it out, it was because of the way I handled [
>>
>>52160069
Python is used a lot outside little scripts by a lot of big companies
>>
>>52160443
Remove the ';' in
#define DIGITS 2;
>>
>>52160443
>#define DIGITS 2;
>>
>>52160446
>8 space indent
use tabs or 4 spaces
>>
>>52160486
> t. Guido van Rossum
>>
>>52160488
>>52160491
OH, first time using #define
I've just been using const
thank you~
>>
>>52160431
No it won't.
You can ship every jre with your program.
>>
>>52160446
>>52159074
these are unreliable and blow up when you have lots of whitespace between words
just make a copy of the string, replace every space with a null byte, and then keep scanning forward through the string and count the number of uninterupted character streams that aren't null bytes.
Or you know, just use strtok, because that's literally what it does.
>>
>>52160200
>java is 2x faster than swift
>people still say android apps are slower than ios
>>
>>52160519
android still can't maintain 60fps
>btfo
>>
>>52160497
Yeah, i need to get on changing the vim config for this machine, usually I program on something else.
>>
>>52160519
people perceive iOS apps as faster because the fancy schmancy UI animations have top priority
>>
File: 1444519185838.jpg (122 KB, 425x516) Image search: [Google]
1444519185838.jpg
122 KB, 425x516
>>52158853
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("%d\n", argc - 1);
}
>>
>>52160519
Not the fault of Java but the fault of dalvik.
>>
>>52160508
dude, I don't think you understand what we're talking about and i'm kinda tired to explain it to you

you clearly don't actually develop software (professionally) either, so at least wait till you have coded for a few years before you become a shill pls
>>
>>52160525
yes it can
>>
>>52160384
>>52160411
You guys know C# and Java are BOTH shit right?
>>
>>52160539
Oh Nigga please,you have been BTFO hard.
Now you are going all passive aggressive “i know it better than you“.

Are you mad?
>>
desu most people think android is slow just because of the shitty curry phone sterotype

>>52160525
You know apart from how they can
>btfo

>>52160538
most phones use ART now
>>
>>52159575
3x faster? More like 30x faster
>>
>>52160571
they're the perfect middle ground for certain types of applications that don't need to squeeze out every last little drop of performance. they provide high-level features while keeping type safety and being up to 2 orders of magnitude faster than for example shit like python.
>>
>>52160536
holy
shit

i love you christ chan
>>
>>52160511
>these are unreliable and blow up when you have lots of whitespace between words
I see what you mean, but I would like you to give me an example string in which my program (the first one you quoted) will break on.
I tested it on
"                  Kill                   YOUR               SELF                  "

and some variations and it worked fine. I'm not trying to argue that the method you suggested isn't better than mine, since it definitely is, but I would like an example for better understanding of what the flaw in the other code is.
>>
>>52160610
I meant even if it still did the for loop ;)
>>
C++ is the only language anyone should be programming in.
>>
>>52160341
No.... If you care about speed you write your complete, correct, solution. Then profile it, THEN see what can be done to improve speed where it's slow.
>>
>>52160672
Someone needs to fork C++ now and just fix the broken fucking syntax and add standard FP
>>
>>52160684
In Java? You'll reach a hard cap pretty fast where you're running up against the JVM.
>>
Daily reminder the C# shills our out enmass since its 2x holiday pay for new years eve. Be sure to thank Rajeed for his hard work!
>>
>>52160768
>our out enmass

Are you sure your name isn't Rajeed?
>>
This finds actual real English words and prints how many there are:

If on not Windows or Mac:
sudo apt-get install enchant


In python
import pip
pip.main(['install', 'pyenchant'])
import enchant, enchant.tokenize
english_dict = enchant.Dict("en_US")
tokenizer = enchant.tokenize.get_tokenizer("en_US")
def count_words(string, dct, tknzr):
return sum(map(lambda x: dct.check(x[0]), tknzr(string)))

count_words(" a long time _ alskdjfs coming", english_dict, tokenizer)
>>
>>52160819
>English
He said words.
>>
>>52160857
I did but this is cool too, and there's already been about 4 generic python soloutions
>>
>>52160819
or you know, you could just strtok instead of installing like 10000 libraries to do a trivial string scanning fucntion.
>>
Where were you the day /dpt/ got blown the fuck out?

>>52160536
>>
local n = 0
for word in string.gmatch(str, "%w") do
n = n + 1
end
>>
>>52160536

Lord have mercy.
>>
File: 1406908022044.gif (933 KB, 343x284) Image search: [Google]
1406908022044.gif
933 KB, 343x284
>>52160536
how does this wo- HOLY SHIT
>>
>>52160819
>pip install pyenchant
>no amd64 support
>>
>>52160933
it's a neat trick, but try doing that with stdin, or pretty much any use case in where a word counting program would be useful.
You're basically asking your shell to tokenize your input in this one specific way. How do you count the words in a file, or from stdin?
>>
>>52160536
>>52160933
>>52160974

./a.out "Literally still not correct"
>>
>>52160974
clever.
>>
echo "hay guys can i play??" | wc -w
>>
>>52158558
Starting CS student here. Over fall, I create a console calculator using queues and stacks in java. Does much as what a standard scientific calculator does.

Short term goal: create a GUI for the calculator.
Long term goal: try create a similar calculator program in C++ and a webpage (using javascript and such).
>>
>>52160104
Fuck Angular, build a site with small libraries and Backbone.
>>
>>52161011
My Casio represents intermediate results as proper fractions and doesn't convert to decimal until told to, does yours?
>>
>>52160988
prog.exe < file


>implying cmd line input isn't stdin
>>
>>52158853
counted = input(">>> ")
i = 0
for item in counted.split(" "):
if item != "":
i += 1
print(i)
>>
>>52161058
that wouldn't work for the argc trick.
>>
what was the first useful thing you programmed, /g/?
>>
I have a question. Let's say in C++ I have a class like

class foo
{
private:
int n;
public:
foo(int i) {n=i;}
int getN() {return n;}
}


If I initialize 1000 foos. Are there going to be 1000 "getN"s? Or do they share the same code and just have different "n"s?
>>
>>52161105
I guess a program to generate basketball-American names?
Example output:
Liatonta
Qunanima
Lajan
Linesha
Tondeen
Sha
Lantand
Tarickickararel
Kekan
Kekes
Lenandr
Tys
Lanar
Kat
Andea
Kique
Dedei
Kaya
Denik
Tays
Tori
Dan
Jaqual
Daranie
Nimatinylina
Keshan
Qua
Toryalauane
Lickis
Tyrqui
Majashata
Ryl
Nivo
Keicke
>>
>>52160511
Better?

int words (char *p)
{
int words = 0;
char *s = strtok(p, " ");
while (s != NULL) {
words++;
while (*s != ' ')
s++;
s = strtok(NULL, " ");
}

return words;
}
>>
>>52161114
Ideally, this is implemented as a function pointer to a single getN() outside of your class, but not accessible outside of a foo object.

Or at least, I hope.
>>
>>52161114
they share the same code
>>
>>52161114
There's only 1 getN

static int foo@@getN(foo* _this) { return this->n; }
>>
>>52161135
>No L'-a

you disappoint me
>>
>>52161157
I should probably add punctuation, kek
>>
>>52158558
I'm about done with a lisp interpreter I've been working on over break. It's kinda like scheme, but with common lisp macros (because they're easy to implement.) Closures are properly working, as well as all the higher-order-function goodness. I'm just putting the finishing touches on macros and the garbage collector and I'll be satisfied. I've been testing recursive functions and higher order functions, and it all works pretty flawlessly.

I wanted a lisp interpreter that I can statically link with C programs. I'm a student, so in my networking class next semester I can implement all the low-level stuff in C, and then tie it together with my lisp.
>>
Wait

is Scala actually the best language?
>>
>>52161105
A program that counted words in a String.
>>
>>52161137
you might want to make a second copy of the string, because strtok irreversibly modifies the original string.
char *s simply points to the original string *p + an internal index that gets advanced every time you call strtok().
>>
>>52159358
>>52159193
part of the c stdlib is
ispace(int)
. You should really use this
>>
>>52161196
I guess so.
>>
>>52161140
>>52161143
>>52161154
Thanks. Makes me feel better about making a huge amount of functions that generally just point to each other.
>>
>>52161227
isspace(int)
>>
When you write a Java application, do you have to install the JVM on the user's machine if it's not already installed, or can you just embed the JVM into your executable file to create a standalone executable?
>>
>>52161137
>Better?

Did you even test your own code, how about just looking at it? The damn thing has a glaring flaw.

Hint:
*s != ' '
Thread replies: 255
Thread images: 23

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.