Skip to content

Instantly share code, notes, and snippets.

View MikaelCarpenter's full-sized avatar

Mikael Carpenter MikaelCarpenter

View GitHub Profile
// Reference: https://github.com/tobyxdd/bread/blob/master/bread.js
function processWord(word, node) {
const len = word.length;
const boldLen = Math.ceil(len * 0.45); // might need an exception for 1 letter words
const boldText = word.substring(0, boldLen);
const normText = word.substring(boldLen);
const span = document.createElement("span");
@MikaelCarpenter
MikaelCarpenter / react-select-data-attributes.jsx
Created December 14, 2018 19:09
Solution for adding data attributes to a react-select component by passing in "custom components" where you've manipulated the innerProps prop
import React, { Component } from 'react';
import ReactSelect, { components } from 'react-select';
const TextOption = props => (
components.Option && (
<components.Option { ...props }>
...
</components.Option>
)
);

Problem

An r × n Latin Rectangle [LR] based on 1, …, n is a 2-dimensional array of r rows and n columns, where r < n, such that each entry is one of the integers 1, …, n and each of these integers occurs at most once in each row and at most once in each column.

Is it true that every r × n LR can be extended to an n × n LR (a Latin square [LS])? Why or why not?

Approach

Okay so my way of checking this is to first see what conditions need to be met that would make a LR unable to conform to a LS.

I will be making an assumption that the only case we need to worry about is the case where r = n-1 because that is the most confined example. And to convert every other example where r < n-1 to a LS is just a series of steps more trivial than the final step of the r=n-1 case.

@MikaelCarpenter
MikaelCarpenter / knights_and_knaves.md
Created November 21, 2016 02:27
Warmup Problem #3

Problem

You are shipwrecked on an unknown island where there are two kinds of people - Knights & Knaves. Knights always tell the truth and knaves always lie. To survive, you need to know who is who.

For each person in the following scenarios, can you figure out if they are a knight or a knave? Support your answer with a logical justification / proof.

1. Persons: A & B

  • A says: “B is a knave.”
  • B says: “We are both knights.”
@MikaelCarpenter
MikaelCarpenter / warmup_02_proof.py
Created November 17, 2016 22:50
Find the max length of a narcissistic number
found = False
i = 1
# the first n digit number is 10**(n-1).
# the largest possible number you can get by summing n digits to the nth power is n*9**n.
# if that largest number is smaller than the first number of length n then no more Narcissistic numbers exist.
while not found:
if i*9**i > 10**(i-1):
i += 1
else:
found = True
from time import time
test_range = range(100, 146511209)
power_ref = {n: {i: i**n for i in range(1,10)} for n in range(2,10)}
def is_narcissistic(x):
string = str(x)
digits = sorted([int(i) for i in string if i != '0'], reverse=True)
digit_counts = {i: digits.count(i) for i in set(digits)}
n = len(string)