Skip to content

Instantly share code, notes, and snippets.

View faresbakhit's full-sized avatar

Fares A. Bakhit faresbakhit

View GitHub Profile
// @author Fares A. Bakhit
// @date 2024-10-03
// @description Merge and Quick Sort Implementations
//
// Compile with at least a C++11 conforming compiler
#include <cstdlib> // size_t
#include <functional> // std::less
#include <utility> // std::swap
/*
*
* Examples:
*
* // Calculate GPA using grades from the current page
* const gpa1 = newecomComputeGPA();
*
* // Calculate GPA with modified grades for MA112 and HU118, and removing CS112
* const gpa2 = newecomComputeGPA({ "MA112": "A+", "HU118": "B+", "CS112": "" });
*
@faresbakhit
faresbakhit / monte_carlo.py
Created January 20, 2025 00:49
"Monte Carlo Process" simulation for the example in Taylor's Introduction to Management Science textbook
from collections.abc import Callable
import random
def demand(x: int) -> int:
d = 0
if not 0 <= x <= 99:
raise RuntimeError(f"{x=} not in [0, 100)")
for m in [19, 59, 79, 89]:
if x > m:
  • inheritance
    • unless the destructor ~Base is marked virtual, the destructor ~Child won't be called on delete base where base is of type Child*.
  • algorithm

s.upper_bound(13); // 32

@faresbakhit
faresbakhit / functional.cpp
Created November 18, 2024 20:02
C++ Structured VS. Functional Programming
#include <iostream>
#include <ranges>
#include <cmath>
int main() {
int p, q;
std::cin >> p;
std::cin >> q;
for (const auto &r :
std::views::iota(p, q)
@faresbakhit
faresbakhit / cannibals-missioneries.py
Created September 13, 2024 05:54
Find solution to the Cannibals & Missioneries river crossing puzzle
# Cannibals & Missioneries solution finder
# https://archive.org/details/cannibals-missioneries
import sys
from enum import IntEnum
from typing import NamedTuple, Any
from collections.abc import Iterable, Iterator, Callable
class Side(IntEnum):
@faresbakhit
faresbakhit / dynamic.cc
Last active May 8, 2024 03:36
Demonstrate how a dynamic type system might be implemented
// File: dynamic.cc
// Purpose: Demonstrate how a dynamic type system might be implemented
// Author: Fares A. Bakhit
// Date: May 8th, 2024
// License: Zero Clause BSD (https://spdx.org/licenses/0BSD.html)
#include <cstdint>
#include <iostream>
using namespace std;
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
string s;
cout << "Plain text: ";
getline(cin, s);
for (auto it = s.begin(); it != s.end();) {