Skip to content

Instantly share code, notes, and snippets.

@huffman
Created August 1, 2012 07:43
Show Gist options
  • Save huffman/3224683 to your computer and use it in GitHub Desktop.
Save huffman/3224683 to your computer and use it in GitHub Desktop.
day = 1
year = 1900
mons = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
fom_sundays = 0
def is_leap_year(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
while year < 2001:
for mon in range(12):
if day == 0 and year > 1900:
fom_sundays += 1
days = 29 if mon == 1 and is_leap_year(year) else mons[mon]
day = (day + days) % 7
year += 1
print fom_sundays
#!/usr/bin/env escript
factorial(0) -> 1;
factorial(N) -> N * factorial(N - 1).
sum(List) -> sum(List, 0).
sum([], Total) -> Total;
sum([N | Rest], Total) -> sum(Rest, Total + N).
main(_) ->
Fac = factorial(100),
Result = sum([N - $0 || N <- integer_to_list(Fac)]),
io:format("result is ~w~n", [Result]).
with open('22.txt') as f:
names = f.read().strip().split(',')
base_value = ord('A') - 1
def word_score(word):
return reduce(lambda tot, c: tot + ord(c) - base_value, word, 0)
total = sum([(k + 1) * word_score(v) for k, v in enumerate(sorted(names))])
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment