Skip to content

Instantly share code, notes, and snippets.

@waltman
waltman / findNextLargest.pl
Created August 1, 2017 13:07
Take an integer use those digits to find the next largest number they can make when reshuffled. For example `findNextLargest(1729)` would return `1792`
#!/usr/bin/env perl
use strict;
use warnings;
use feature ":5.10";
use feature 'signatures';
no warnings "experimental::signatures";
use Algorithm::Combinatorics qw(permutations);
my $n = shift @ARGV;
#!/usr/bin/env perl
use strict;
use warnings;
use feature ":5.10";
my $n = shift @ARGV;
while (1) {
if ($n <= 1) {
say $n;
#!/usr/bin/env python2
from sys import argv
n = int(argv[1])
while True:
if n <= 1:
print n
break
#!/usr/bin/env perl
use strict;
use warnings;
use feature ":5.10";
use feature 'signatures';
no warnings "experimental::signatures";
for my $line (@ARGV) {
say testForPangram($line);
}
func testForPangram(_ s: String) -> String {
var count = [Character:Int]()
for c in s.lowercased().characters {
if c >= "a" && c <= "z" {
if count[c] == nil {
count[c] = 1
} else {
count[c] = count[c]! + 1
}
}
#include <stdio.h>
#include <string.h>
void boxWord(char *);
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
boxWord(argv[i]);
puts("");
}
#!/usr/bin/env python2
from sys import argv
def boxWord(s):
if len(s) <= 1:
print s
return
# top
print s
@waltman
waltman / boxedWord2.c
Created August 8, 2017 16:16
Like the previous boxedWord program, but print them in a grid specified on the command line.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void boxWord(char *s, int rows, int cols);
void printEdge(char *s, int cols, int dir);
void printMiddle(char *s, int cols, int offset);
int main(int argc, char *argv[]) {
if (argc != 4) {
#!/usr/bin/env perl
use strict;
use warnings;
use feature "signatures";
no warnings "experimental::signatures";
my ($s, $rows, $cols) = @ARGV;
boxedWord($s, $rows, $cols);
@waltman
waltman / printWord.py
Created August 9, 2017 13:46
Print the words on the command line in a triangle if their first and last letters match, otherwise print them in box
#!/usr/bin/env python2
from sys import argv
def printWord(s):
if s[0] == s[-1]:
triangleWord(s)
else:
boxWord(s)
def triangleWord(s):