Skip to content

Instantly share code, notes, and snippets.

View samueljtaylor's full-sized avatar
🎯
Focusing

Sam Taylor samueljtaylor

🎯
Focusing
View GitHub Profile
@samueljtaylor
samueljtaylor / html_implode.php
Created June 1, 2021 22:44
Implode an associative array in html attribute format
<?php
function html_implode(array $array)
{
$callback = fn ($key, $value) => $key . '="' . (is_array($value) ? implode(' ', $value) : $value) . '"';
return implode(' ', array_map($callback, array_keys($array), array_values($array)));
}
#https://www.reddit.com/r/dailyprogrammer/comments/6k123x/20170629_challenge_321_intermediate_affine_cipher/
# Keys are coprimes to 26, values are that coprime's multiplicative modular inverse
# since we are only ever using these coprimes, theres no need to calculate them
COPRIMES = {
3 => 9,
5 => 21,
7 => 15,
11 => 19,
15 => 7,
class Cipher
@@characters = '#_23456789abcdefghijklmnopqrstuvwxyz'
@@vectors = nil
def self.getVector(char)
return self.vectors[char.downcase]
end
def self.vectors()
self.buildVectors() unless @@vectors
@samueljtaylor
samueljtaylor / easyTally.rb
Created May 24, 2018 21:30
Easy Tally Challenge Solution
# https://www.reddit.com/r/dailyprogrammer/comments/8jcffg/20180514_challenge_361_easy_tally_program/
players = {}
ARGV[0].split(//).each do |char|
name = char.downcase
players[name] = 0 if !players[name]
players[name] -= 1 if char == char.upcase
players[name] += 1 if char == char.downcase
end