- I don't really want to add exports for
require()
due to potential unwanted behavior. - I am writing packages that could run in multiple runtimes, whether it's a browser, node or deno. Using CommonJS limits this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char queue[256]; | |
int last = -1; | |
int limit = 256; | |
void enqueue(char itemToInsert) { | |
if (last == limit - 1) { | |
printf("Queue Overflow"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Doubl Linked-List | |
#include <stdio.h> | |
#include <stdlib.h> | |
struct Element { | |
char value; | |
struct Element *next; | |
struct Element *previous; | |
}; |
- If you have an opinion, share it or suggest it. Don't force it on others.
- If you have a personal belief, be it religious or ethical, don't force it on others.
- If you have a personal problem with someone, take it to where it belongs. Bringing it to unrelated online platforms wouldn't give you justice.
- If you need help with something, describe what you need help with instead of asking if you can get help without describing the matter.
- If you are asking for help, be clear with what you exactly need. You might end up wasting the time of the person trying to help you as well as that of yourself.
- If someone asks for help and you don't want to help them, just don't help them. Instead, don't blame their ignorance on the matter.
- If someone doesn't like something, don't do it just to piss them off.
- If someone starts complaining about everything for no reason, just don't mind them. There is no cure for stupidity.
- If you have a sense of justice, it makes sense that the other person
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.StdIn.{readInt}; | |
import scala.collection.mutable.ArrayBuffer; | |
import scala.collection.immutable.List; | |
object Triplicate { | |
def main(args: Array[String]) = { | |
val arr = new ArrayBuffer[Int](); | |
println("Enter the numbers followed by a return after each number. Enter a non-number to stop."); | |
var continue = 1; | |
while(continue == 1) { | |
try { |
import scala.io.StdIn.{readDouble};
import scala.collection.mutable.ArrayBuffer;
object SumArray {
def main(args: Array[String]) = {
var listOfNumbers = new ArrayBuffer[Double]();
println("Enter numbers to add. Enter 0 to stop.");
var current = 1.0;
while (current != 0.0) {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
pub struct LinearRegressionResult { | |
pub slope: f64, | |
pub intercept: f64, | |
pub r2: f64, | |
} | |
impl LinearRegressionResult { | |
pub fn predict(&self, x: f64) -> f64 { | |
self.intercept + (self.slope * x) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Weighted random selection in Scala 2 | |
// You have an array of items. Each item is an unsigned integer. | |
// The value of each item determines its weight. | |
// Higher the weight, higher the chance of rolling it. | |
class Fortuna(items: Array[Double]) { | |
private val weights = items; | |
private val cumulativeWeights: Array[Double] = new Array(items.length); | |
private var totalChance: Double = 0; | |
for (i <- 0 until items.length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand::Rng; | |
/// You have an array of items. Each item is an unsigned 32-bit integer. | |
/// The value of each item determines its weight. | |
/// Higher the weight, higher the chance of rolling it. | |
/// This algorithm uses a simple approach. | |
/// Keep moving in a straight line till your weights sum up to (or get reduced to) | |
/// a weight less than a single item's weight. Return the index of the result. |
OlderNewer