Skip to content

Instantly share code, notes, and snippets.

# PE#34
#
# 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
#
# Find the sum of all numbers which are equal to the sum of the factorial of their digits.
#
# Note: as 1! = 1 and 2! = 2 are not sums they are not included.
require 'pe-library'
require 'benchmark'
# PE#34
#
# 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
#
# Find the sum of all numbers which are equal to the sum of the factorial of their digits.
#
# Note: as 1! = 1 and 2! = 2 are not sums they are not included.
require 'pe-library'
require 'benchmark'
# PE#30
#
# Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
#
# 1634 = 1**4 + 6**4 + 3**4 + 4**4
# 8208 = 8**4 + 2**4 + 0**4 + 8**4
# 9474 = 9**4 + 4**4 + 7**4 + 4**4
# As 1 = 1**4 is not a sum it is not included.
#
# The sum of these numbers is 1634 + 8208 + 9474 = 19316.
# PE#30
#
# Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
#
# 1634 = 1**4 + 6**4 + 3**4 + 4**4
# 8208 = 8**4 + 2**4 + 0**4 + 8**4
# 9474 = 9**4 + 4**4 + 7**4 + 4**4
# As 1 = 1**4 is not a sum it is not included.
#
# The sum of these numbers is 1634 + 8208 + 9474 = 19316.
“At 24 years of age,” says a striking footnote on page one of the Army’s suicide reports, “a Soldier, on average, has moved from home, family, and friends and resided in two other states; has traveled the world (deployed); been promoted four times; bought a car and wrecked it; married and had children; has had relationship and financial problems; seen death; is responsible for dozens of Soldiers; maintains millions of dollars’ worth of equipment; and gets paid less than $40,000 a year.” Now consider what happens when this cycle repeats itself for a decade. “Moving, divorce, death, financial turmoil,” says Lily Burana, author of the memoir I Love a Man in Uniform. “Those are the top stressors in a life. And this is what you get every freaking year in the Army.”
ultramarine:China jdc$ git remote -v
origin git@github.com:golocal/China.git (fetch)
origin git@github.com:golocal/China.git (push)
production git@heroku.jdc:giftly.git (fetch)
production git@heroku.jdc:giftly.git (push)
staging git@heroku.jdc:giftly-staging.git (fetch)
staging git@heroku.jdc:giftly-staging.git (push)
ultramarine:China jdc$ git config heroku.remote
giftly-staging
@joncooper
joncooper / gist:1043829
Created June 23, 2011 22:56
Strange behavior with JRuby IO#rewind when backed by a ByteArrayInputStream
# https://github.com/jruby/jruby/blob/master/src/org/jruby/RubyIO.java
#
# public RubyFixnum rewind (...) {
# calls OpenFile#getMainStreamSafe#lseek(0L, Stream.SEEK_SET)
#
# https://github.com/jruby/jruby/blob/master/src/org/jruby/util/io/ChannelStream.java
#
# public synchronized void lseek (...) {
# checks if the fd is seekable
# checks if the fd is a SelectableChannel
@joncooper
joncooper / arpwatch-2.1a15.darwin.patch
Created July 1, 2011 15:11
Patch arpwatch-2.1a15 to install with correct user/group ownership on OS X
diff --git a/Makefile.in b/Makefile.in
index 75fb4ba..3ccc2de 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -110,13 +110,15 @@ zap: zap.o intoa.o
$(CC) $(CFLAGS) -o $@ zap.o intoa.o -lutil
install: force
- $(INSTALL) -m 555 -o bin -g bin arpwatch $(DESTDIR)$(BINDEST)
- $(INSTALL) -m 555 -o bin -g bin arpsnmp $(DESTDIR)$(BINDEST)
@joncooper
joncooper / argument-parsing-nice
Created October 4, 2011 20:19
Explorations in Go: A dupe checker in Go and Ruby
➜ dupe git:(master) ✗ ./dupe --help
Usage of ./dupe:
-verbose=false: Print the list of duplicate files.
@joncooper
joncooper / bm-go
Created October 4, 2011 20:35
Explorations in Go: A dupe checker in Go and Ruby #2
➜ dupe git:(master) time ./dupe ~
Total duped files found: 49432
./dupe ~ 6.73s user 16.67s system 77% cpu 30.309 total
➜ dupe git:(master) time ./dupe ~
Total duped files found: 49432
./dupe ~ 6.74s user 16.95s system 77% cpu 30.564 total
➜ dupe git:(master) time ./dupe ~
Total duped files found: 49432
./dupe ~ 6.70s user 16.85s system 77% cpu 30.423 total