Skip to content

Instantly share code, notes, and snippets.

View lonelycompiler's full-sized avatar
exploring my passions

lonelycompiler

exploring my passions
View GitHub Profile
@lonelycompiler
lonelycompiler / main.cpp
Created September 29, 2023 15:35
Write a program that calculates and prints the sum of all the natural numbers divisible by 3 or 5, up to a given limit entered by the user.
#include <cstdio>
int sumOfNaturalDivisibleByThreeAndFive (int limit)
{
int sum = 0;
for (int i = 1; i <= limit; ++i)
{
if (i % 5 == 0 && i % 3 == 0) sum += i;
}
return sum;
@lonelycompiler
lonelycompiler / meanmode.c
Created September 29, 2023 15:33
Given an array of size length, return an array of [mean, mode]
/*
Given an array of size length, return an array of [mean, mode]
*/
typedef struct nums nums
{
int *data;
int size;
}
@lonelycompiler
lonelycompiler / doublylinkedlist.cpp
Created August 14, 2023 16:29
Doubly Linked List with insertion (at end), find, and delete operations
/*
Define a doubly linked list of heap-allocated strings.
Write functions to insert, find, and delete items from it.
Test them.
*/
#define NULL 0
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
<html>
<head>
<title>strip end</title>
<style>
div, input {
flex-direction: column;
flex: 1;
}
</style>
<script>
"""1000 integers in a random order + one duplicate pair.
How to find an integer that has been duplicated?"""
import random
def generate_nums(list_size: int) -> list[int]:
"""
generate a list of numbers from 1 to list_size in a random order
"""
sorted_nums = [i for i in range(1, list_size+1)]
randomized_nums = []
struct Binary {
num_bits: usize,
binary_str: String,
}
impl Binary {
fn new(num_bits: usize) -> Binary {
let mut new_binary = String::new();
for _ in 0..num_bits {