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
in_room(monkey). | |
in_room(banana). | |
in_room(chair). | |
clever(monkey). | |
can_climb(monkey, chair). | |
tall(chair). | |
can_move(monkey, chair, banana). | |
can_reach(X, Y):- |
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
n = int(input()) | |
size = (2 * n) - 1 | |
d = [] | |
for i in range(n - 1): | |
s = [] | |
for j in range(n - 1): | |
s.append(str(n - min(i, j))) | |
rev = [x for x in s] | |
rev.reverse() |
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
object Triplicate { | |
def main(args: Array[String]): Unit = { | |
println("Enter numbers separated by a comma") | |
val nums = scala.io.StdIn.readLine() | |
val arr = nums.split(",").map(x => x.toInt) | |
val trip = arr.flatMap(x => List(x, x, 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
/** | |
* Data transformed by the constructor, fed to the binary search function. | |
* The `result` property holds the result that will be returned after rolling. | |
* `chance` is the weight of the result. | |
* `cumulativeChance` is used to make it fit for binary search. Something like an arithmetic progression. | |
*/ | |
export interface ComputedGachaData<ItemType> { | |
result: ItemType; | |
chance: number; |
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. |
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
#[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
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 { |
- 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
NewerOlder