challenges

my solutions to various "programming challenge" problems
git clone https://wehaveforgeathome.hates.computer/challenges.git
Log | Files | Refs | LICENSE

commit f584873f4cf647ee365893af4a749dff0a396f21
parent 6fec926eca9fb56bf9911a7ac0df9847a757e51a
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Sat, 26 Feb 2011 22:16:06 -0800

50% done with hyperpublic. in other news, lua is fun

Diffstat:
MREADME.md | 1+
Mhyperpublic/README.md | 20++++++++++++++++++++
Ahyperpublic/challenge1.lua | 43+++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -7,6 +7,7 @@ Completed: In Progress: * project euler +* hyperpublic TODO: diff --git a/hyperpublic/README.md b/hyperpublic/README.md @@ -20,3 +20,23 @@ Use the input file here to determine what the highest influence score is among 100 random Hyperpublic users. To compute the answer to problem 1, append the top 3 influence totals together in descending order. (For example if they are 17, 5, and 3 then submit 1753) + + You've passed Problem 1. You're half way there. Try Problem 2. + + Hyperpublic has an internal karma system to determine which users are the most involved in the ecosystem. Users earn points for the following tasks. + + 2 Points – Add Place + 3 Points – Add Thing + 17 Points – Tag Object + 23 Points – Upload Photo + 42 Points – Twitter Share + 98 Points – Facebook Share + Being addicted to their own product, the Hyperpublic staff has racked up some big karma. The members of the team have the following karma totals: + + Doug – 2349 points + Jordan – 2102 points + Eric – 2001 points + Jonathan – 1747 points + Amazingly, they've all accomplished these totals in the minimum number of tasks possible in order to reach each amount. For example, if their total was 6 points they would have accomplished this in just 2 tasks (2 "Add Thing" tasks), as opposed to accomplishing it by 3 "Add Place" tasks. Your job is to compute how many total tasks each user has completed. After you've done so, find the answer to Problem 2 using the following formula: + + Problem 2 Answer = Doug's total tasks * Jordan's total tasks * Eric's total tasks * Jonathan's total tasks diff --git a/hyperpublic/challenge1.lua b/hyperpublic/challenge1.lua @@ -0,0 +1,43 @@ +#!/usr/bin/lua + +-- convert the silly input format into something more useful +iadded = {} + +i = 1 +for line in io.lines('challenge2input.txt') do + addedjs = {} + for j=1,#line do + if string.sub(line, j, j) == 'X' then + table.insert(addedjs, j) + end + end + iadded[i] = addedjs + i = i + 1 +end + +function score (i) + addedjs = iadded[i] + s = #addedjs + for ji,j in ipairs(addedjs) do + s = s + score(j) + end + return s +end + +scores = {} + +for i=1,#iadded do + s = score(i) + table.insert(scores, s) +end + +table.sort(scores) + +print( + string.format( + "%d%d%d", + scores[#scores], + scores[#scores - 1], + scores[#scores - 2] + ) +)