Skip to content

Instantly share code, notes, and snippets.

Mikael Carpenter MikaelCarpenter

  • San Francisco, CA
Block or report user

Report or block MikaelCarpenter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MikaelCarpenter
MikaelCarpenter / react-select-data-attributes.jsx
Created Dec 14, 2018
Solution for adding data attributes to a react-select component by passing in "custom components" where you've manipulated the innerProps prop
View react-select-data-attributes.jsx
import React, { Component } from 'react';
import ReactSelect, { components } from 'react-select';
const TextOption = props => (
components.Option && (
<components.Option { ...props }>
...
</components.Option>
)
);
View latin_squares.md

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.

View knights_and_knaves.md

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 Nov 17, 2016
Find the max length of a narcissistic number
View warmup_02_proof.py
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
View warmup_02.py
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)
You can’t perform that action at this time.