Profile Picture

pooperlegend

Reputation: 0 [rate]

Joined: Jun, 2023

Last online:

https://media.discordapp.net/attachments/1074297826219139153/1118491534581567568/Mask_group.png

Badges

badge

Etc

Send Message

Threads List
Possible Alts

Activity Feed

Replied to thread : Somebodies pretending to be me


i dont know who to believe :skull:

Replied to thread : Atonix V3 | Updates and UI


gross syntax highlighting

Replied to thread : CodeWars V2 in any language


@B00M the testing results were tested on 32 threads i was modifying the code to check for bugs later so yeh mine was tested on 32 threads

 

Replied to thread : CodeWars V2 in any language


@B00M
ignore the extra 0.1 second idk why thats happening its hard coded to stop exactly at 5 seconds
https://cdn.discordapp.com/attachments/1065628036994715679/1121457757464313866/image.png


#include <iostream>
#include <vector>
#include <chrono>
#include <thread>
#include <atomic>

using namespace std;
using namespace std::chrono;

const int limit = 1000000;
const int numThreads = 48;

void sieveThread(vector<char>& sieve, atomic<int>& passes) {
    while (true) {
        int p = 2;
        for (; p * p <= limit; p++) {
            if (sieve[p]) {
                for (int i = p * p; i <= limit; i += p) {
                    sieve[i] = false;
                }
            }
        }
        passes++;
    }
}

int main() {
    int count = 0;
    atomic<int> passes(0);

    vector<char> sieve(limit + 1, true);
    vector<thread> threads;

    for (int i = 0; i < numThreads; i++) {
        threads.emplace_back(sieveThread, ref(sieve), ref(passes));
    }
    auto startTime = high_resolution_clock::now();

    this_thread::sleep_for(seconds(5));
    for (auto& thread : threads) {
        thread.detach();
    }

    auto endTime = high_resolution_clock::now();
    auto elapsedTime = duration_cast<duration<double>>(endTime - startTime).count();

    for (int i = 2; i <= limit; i++) {
        if (sieve[i]) {
            count++;
        }
    }
    cout << "Time: " << elapsedTime << "s" << endl;
    cout << "Passes: " << passes << endl;
    cout << "Prime numbers found: " << count << endl;

    return 0;
}

Commented to thread : codewars but code any language


@B00M yes loll

Replied to thread : codewars but code any language


@B00M goto the new challenge

Created a new thread : CodeWars V2 in any language


make a program which will get how many prime numbers there are in 1 million then keep doing that for 5 seconds give or take a few miliseconds and then list how many times it was able to do that.

Rules
you can only use the Sieve of eratosthenes algorihim
multithreading is allowed but limited to 32 threads
you must show how long it took and how many passes in the console

Good Luck my fellow coders!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Replied to thread : Codewars but rewrite my code to make it faster in any language!


https://media.discordapp.net/attachments/980907747031789638/1121158601600409720/image.png

Created a new thread : Codewars but rewrite my code to make it faster in any language!


do what ze title says
rules.
your not allowed to change the main function of the code you can only try to remake or optimise it to be faster

using System;
using System.Collections.Generic;
using System.Diagnostics;

public class FibonacciSequence
{
    private static Dictionary<int, int> fibCache = new Dictionary<int, int>();

    public static void Main(string[] args)
    {
        long totalTime = 0;
        int iterations = 100;
        for (int i = 0; i < iterations; i++)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int e = 0; e < 10000; e++)
            {
                int fibonacciNumber = Fibonacci(e);
                Console.Write(fibonacciNumber + " ");
            }
            stopwatch.Stop();

            totalTime += stopwatch.ElapsedMilliseconds;
        }
        double averageTime = (double)totalTime / iterations;

        Console.WriteLine("\n \n Average time: " + averageTime + " ms");
        Console.WriteLine("Total time " + totalTime / 1000 + " Seconds");

        Console.ReadLine();
    }

    public static int Fibonacci(int n)
    {
        if (fibCache.ContainsKey(n))
        {
            return fibCache[n];
        }

        int fibonacciNumber;
        if (n <= 1)
        {
            fibonacciNumber = n;
        }
        else
        {
            fibonacciNumber = Fibonacci(n - 1) + Fibonacci(n - 2);
        }

        fibCache[n] = fibonacciNumber;
        return fibonacciNumber;
    }
}

Commented to thread : codewars but code any language


@Alawrpar embed fail

https://cdn.discordapp.com/attachments/1064359813175328891/1121133416411316344/image.png

Replied to thread : codewars but code any language


@SeizureSalad fak you, anyways @Alawrpar

 

 

https://cdn.discordapp.com/attachments/980907747031789638/1121122448314749099/image.png

#include <iostream>
#include <vector>
#include <cmath>
#include <chrono>
#include <omp.h>

int countPrimeNumbers(int limit)
{
    std::vector<char> isComposite(limit + 1, false);
    int sqrtLimit = static_cast<int>(std::sqrt(limit));

#pragma omp parallel for schedule(dynamic)
    for (int number = 2; number <= sqrtLimit; number++)
    {
        if (!isComposite[number])
        {
            for (int multiple = number * number; multiple <= limit; multiple += (2 * number))
            {
                isComposite[multiple] = true;
            }
        }
    }

    int primeCount = 1;
#pragma omp parallel for schedule(guided) reduction(+: primeCount)
    for (int number = 3; number <= limit; number += 2)
    {
        if (!isComposite[number])
        {
            primeCount++;
        }
    }

    return primeCount;
}

int main()
{
    const int iterations = 1000;
    const int limit = 1000000;

    long long totalTime = 0;
    int primeCount = 0;

    omp_set_nested(true);

    for (int i = 0; i < iterations; i++)
    {
        auto startTime = std::chrono::high_resolution_clock::now();

        primeCount = countPrimeNumbers(limit);

        auto endTime = std::chrono::high_resolution_clock::now();
        auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
        totalTime += elapsedTime;
    }

    double averageTime = static_cast<double>(totalTime) / iterations;

    std::cout << "Average time: " << averageTime << " ms" << std::endl;
    std::cout << "Prime numbers found: " << primeCount << std::endl;

    return 0;
}

Replied to thread : codewars but code any language


@Alawrpar i have found a way to beat your score :)

Commented to thread : codewars but code any language


i will beat you just wait you little son of a

Replied to thread : codewars but code any language


@Alawrpar

im gonna fart inb your rusty fahh face

https://cdn.discordapp.com/attachments/980907747031789638/1121084362063085608/image.png

 

using System;
using System.Diagnostics;

class PrimeNumberCounter
{
    static void Main()
    {
        const int iterations = 1000;
        const int limit = 1000000;

        long totalTime = 0;
        int primeCount = 0;

        for (int i = 0; i < iterations; i++)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            primeCount = CountPrimeNumbers(limit);

            stopwatch.Stop();
            totalTime += stopwatch.ElapsedMilliseconds;
        }

        double averageTime = (double)totalTime / iterations;

        Console.WriteLine("Average time: " + averageTime + " ms");
        Console.WriteLine("Prime numbers found: " + primeCount);
    }

    static int CountPrimeNumbers(int limit)
    {
        bool[] isComposite = new bool[limit + 1];

        for (int number = 2; number * number <= limit; number++)
        {
            if (!isComposite[number])
            {
                for (int multiple = number * number; multiple <= limit; multiple += number)
                {
                    isComposite[multiple] = true;
                }
            }
        }

        int primeCount = 0;
        for (int number = 2; number <= limit; number++)
        {
            if (!isComposite[number])
            {
                primeCount++;
            }
        }

        return primeCount;
    }
}




Replied to thread : codewars but code any language


@Alawrpar


https://cdn.discordapp.com/attachments/980907747031789638/1121080431501123647/image.png

using System;
using System.Diagnostics;
using System.Threading.Tasks;

class PrimeNumberCounter
{
    static void Main()
    {
        const int iterations = 100;
        const int limit = 1000000;

        long totalTime = 0;
        int primeCount = 0;

        for (int i = 0; i < iterations; i++)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            primeCount = CountPrimeNumbers(limit);

            stopwatch.Stop();
            totalTime += stopwatch.ElapsedMilliseconds;
        }

        double averageTime = (double)totalTime / iterations;

        Console.WriteLine("Average time: " + averageTime + " ms");
        Console.WriteLine("Prime numbers found: " + primeCount);
    }

    static int CountPrimeNumbers(int limit)
    {
        bool[] isPrime = new bool[limit + 1];

        for (int number = 2; number <= limit; number++)
        {
            isPrime[number] = true;
        }

        for (int number = 2; number * number <= limit; number++)
        {
            if (isPrime[number])
            {
                for (int k = number * number; k <= limit; k += number)
                {
                    isPrime[k] = false;
                }
            }
        }

        int primeCount = 0;
        for (int number = 2; number <= limit; number++)
        {
            if (isPrime[number])
            {
                primeCount++;
            }
        }

        return primeCount;
    }
}