Programming Challenge

Okay fa/gg/ots it's time for a programming challenge.

Write a parallel program to compute fizzbizz on 1..100,000 in under 1 second.

Sounds too complicated to write in under a second.

u can't :3 is that what you're saying? u can't? :3

fizzbuzz is a useless exercise that does nothing to teach people about code

We're not /homework/.

Why is everyone on Sup Forums so bad at programming? Fine as the OP I'll start us off

-module(parallel_fizzbuzz).
-export([par/1]).

fizzbuzz(X) when (X rem 3 == 0 ) and (X rem 5 ==0) ->
"FizzBuzz";
fizzbuzz(X) when (X rem 3 == 0) ->
"Fizz";
fizzbuzz(X) when (X rem 5 == 0) ->
"Buzz";
fizzbuzz(X) ->
X.

par(N) ->
Parent = self(),
[receive {Pid, Result} -> Result end || Pid Parent ! {self(), fizzbuzz(X)} end) || X

Do you want the program to run in under 1 second, or for it to be coded in under 1 second?

I'm fine with either

How many cores are we allowed and what's the IPC or clock-speed recommended, along with the CL?

Lol, Python fags can't do it. Their language is too slow.

why to bother? the output still needs to be serialized and single-threaded version finishes in 50ms.
package main

import (
"fmt"
"strconv"
)

func main() {
ch := make(chan string, 100000)
go func() {
for i := 0; i < 100000; i++ {
switch {
case i % 15 == 0:
ch

What the fuck is that rubiks cube you cant have a yellow and white piece what the fuck you can't even find a proper image I thought people on this board were intelligent and shit. What the fuck get your fucking shit straight and get a proper image that one looks like dog shit too.


Fuck you.

>Making Sup Forums do your homework

1 thread. 15ms
#include
int main(void){
for (int i=0;++i

Did not get the use of the & operator in 5&12 and 3&4,
Isn't 5&12=0101&1100 ->0100.
Or does it mean somthing else?

(use-package :pcall)

(defun range (start end)
(loop for i from start below end collecting i))

(defun pmap (f seq)
(let ((result (map 'list
#'(lambda (n)
(pexec (funcall f n)))
seq)))
(map-into result #'join result)))

(defun fizz-buzz-message (i)
(cond ((and (zerop (rem i 3)) (zerop (rem i 5))) "FizzBuzz")
((zerop (rem i 3)) "Fizz")
((zerop (rem i 5)) "Buzz")
(t i)))

(format t "~{~a~%~}" (pmap #'fizz-buzz-message (range 1 100001)))

What a shitty fucking challenge.

#include

int main() {
for (int i = 1; i

Also I'm a retard, I need to print out the newline at the end of the loop instead of after every output to make FizzBuzz display properly. Doesn't change my point.

>C
>1 thread
Why am I not surprised?

>spawning a process, using it to get a single value, then waiting for the process to finish before spawning the next one
That's not how you parallelize shit, yours takes 150 ms to execute, mine only takes 12. Granted, mine is still only 20-30% faster than the single threaded implementation, probably because of the list concatenation.
Sup Forums doesn't let me post the code for some reason, so posting it as a pic.

This was supposed to be parallelized.

It's parallelized over 1 thread

More seriously, what's the fucking point when single-threaded performance is 20-50 times better than what OP asked for?

that's semantics. You know what OP meant. Not a solution.

My point was that I didn't bother because there's no fucking point, because the challenge is really shit

Read my post you niglet

kek

>He read an erlang hello world tutorial and now he thinks hes good at brogramming
What an absolute soipussy

shell script
workers=$(nproc)

fizzbuzz() {
seq $1 $2 | while read i; do
f=
b=
[ $(( $i % 3 )) -eq 0 ] && f=Fizz
[ $(( $i % 5 )) -eq 0 ] && b=Buzz
printf '%s %s%s\n' $i $f $b
done
}

for w in $( seq 0 $(( $workers-1 )) ); do
fizzbuzz \
$(( ($w*$1/$workers)+1 )) \
$(( ($w+1)*$1/workers )) &
done | sort -n

./pfb 100000 0.08s user 0.23s system 23% cpu 1.297 total

without sorting:
./pfb 100000 > out.txt 0.00s user 0.00s system 97% cpu 0.004 total

cleanup and fix,
#!/bin/sh

fizzbuzz() {
seq $1 $2 | while read i; do
[ $(( $i % 3 )) -eq 0 ] && f=Fizz || f=
[ $(( $i % 5 )) -eq 0 ] && b=Buzz || b=
printf '%s %s%s\n' $i $f $b
done
}

workers=$(nproc)
for w in $( seq 0 $(( $workers-1 )) ); do
fizzbuzz \
$(( ($w*$1/$workers)+1 )) \
$(( ($w+1)*$1/$workers )) &
done | sort -n

by turning off other CPU-intensive stuff:
./pfb 100000 > /dev/null 0.09s user 0.10s system 24% cpu 0.777 total

You can with Japanese color scheme.
But in that case, yellow and green don't go together.