Skip to content

Instantly share code, notes, and snippets.

View Dante83's full-sized avatar
💭
Let's write some code!

David Evans Dante83

💭
Let's write some code!
View GitHub Profile
function utopianTree(n) {
//A naive way to approach this is to just sum through our years
//alternating between multiplying by 2 and adding 1
//But there is a better way by considering that our even cycles
//are actually the sum of 2^m for m in 0..n where n is the even
//number of years.
//
//This is a special sum whose value is 2^n-1 - 1.
//See https://math.stackexchange.com/questions/1990137/the-idea-behind-the-sum-of-powers-of-2
//Then our result can be determined in O(c) time
@Dante83
Dante83 / numberOfAnnagramPairs.js
Created December 23, 2020 04:50
Number Of Annagram Pair Substrings In A String
var maxNStored = 1;
var storedFactorials = [1n, 1n]
function getFactorial(n){
//We can say that if n is not in our stored factors, no other factorials
//are in there. Don't worry, we can't fill that stored factorial list
//up too big as factorials get big FAST.
if(n > maxNStored){
let factorial = storedFactorials[maxNStored];
for(let i = maxNStored + 1; i <= n; ++i){
factorial *= BigInt(i);
@Dante83
Dante83 / superdigit.js
Created December 22, 2020 05:46
Super Digit Problem on Hackerrank
function superDigit(n, k) {
//This reminds me of a clever math trick, and makes me
//wonder if there are more. If you recursively sum a number
//and it the final number like this is divisible by 3,
//then the number is divisble by 3. Therefore, if n, k times
//will just become sum(n) * k and sum(n) * k % 3 === 0
//then the super digit is 3, 6, 9.
//
//In fact, if the sum of digits is 9, then the super number IS 9.
//In fact, there IS a relationship between the sum of the digits
@Dante83
Dante83 / staircase.js
Created December 6, 2020 17:28
Staircase Problem Code Body
//Let us make a table of factorials as I feel they're
//going to be really useful.
var maxNStored = 1;
var storedFactorials = [1n, 1n]
function getFactorial(n){
//We can say that if n is not in our stored factors, no other factorials
//are in there. Don't worry, we can't fill that stored factorial list
//up too big as factorials get big FAST.
if(n > maxNStored){
let factorial = storedFactorials[maxNStored];
@Dante83
Dante83 / ScrollbarUnderNav.html
Created June 25, 2018 07:06
Kinda Like This?
<html><head>
<meta charset="utf-8">
<!-- <meta http-equiv="refresh" content="10" /> -->
<title>Sample 3</title>
<link href="https://fonts.googleapis.com/css?family=Dancing+Script|Poiret+One|Ropa+Sans|Signika" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
self.global_node_coordinates = [[0,0,0] for c in range(len(g_x_data))]
for i, x in enumerate(g_x_data):
self.global_node_coordinates[i][0] = x
if self.highest_global_x == None or x > self.highest_global_x:
self.highest_global_x = x
if self.lowest_global_x == None or x < self.lowest_global_x:
self.lowest_global_x = x
for i, y in enumerate(g_y_data):
self.global_node_coordinates[i][1] = y
if self.highest_global_y == None or y > self.highest_global_y:
import bpy
from mathutils import Vector
import bmesh
import numpy as np
from math import *
import random as rand
import os, sys
import operator
from operator import itemgetter
rp1 = self.rotated_p1
rp2 = self.rotated_p2
rp3 = self.rotated_p3
alpha_numerator = ((rp2[1] - rp3[1])*(intersection_point[0] - rp3[0]) + (rp3[0] - rp2[0])*(intersection_point[1] - rp3[1]))
alpha_denominator = ((rp2[1] - rp3[1])*(rp1[0] - rp3[0]) + (rp3[0] - rp2[0])*(rp1[1] - rp3[1]))
alpha = alpha_numerator / alpha_denominator
beta_numerator = ((rp3[1] - rp1[1])*(intersection_point[0] - rp3[0]) + (rp1[0] - rp3[0])*(intersection_point[1] - rp3[1]))
beta_denominator = ((rp2[1] - rp3[1])*(rp1[0] - rp3[0]) + (rp3[0] - rp2[0])*(rp1[1] - rp3[1]))
beta = beta_numerator / beta_denominator
@Dante83
Dante83 / basic_sign_oscillation.lsl
Created August 21, 2016 23:38
A lsl attempt at making a sign oscillate back and forth using a "sign wave" :P.
//I'm so sorry to whomever works with this - yes, it's not even remotely perfect and I have much work to do
//Apologies ahead of time - Dante
float wind_speed;
float sign_period = 4.0;
float time = 0.0;
integer time_2 = 0;
float theta_min = 0.0;
float theta_max = 0.0;
float v_f = 0.0;
//
//This is what happens when you get Markov Chains wrong. Magic! >:{D
//
var markov_id = 0;
var markovChain = [];
function parseNameCSVData(){
var rawWordData = $('#name-csv-data').val().split(',');
var words = [];