Skip to content
TORNLIFE More

Programming Game

Started by Dash [3901] on in Technology.

20 replies · 218 views · thread synced · 7 days ago · View on torn.com
About this thread

Posts archived: 21 / 21 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
21
Discussion span
→
Authority score
10 / 100
Historical score
19 / 100
Story score
40 / 100
Engagement score
64 / 100

People posting, likes and official posts are not counted for this thread yet: on threads longer than one page they come from a periodic pass over the archive, which has not covered it.

Most-liked replies

Dash [3901]

i'm bored, so let's see how many of you can code. :)

I will propose a few programming challenges, first to complete one gets the prize described.

BTW: You can use any programming language unless otherwise specified. Scripting languages tolerated will be limited to Linux bash but you must create your own functions.You must use proper syntax, spacing, and indentation. No one line can exceed 80 characters of code. "Pseudo-code" not accepted.

Your answer will be chosen based on the following criteria:
1.) Best practices.
2.) Clean/easy to read code.
3.) Time complexity where applicable.

EDIT: Entries MUST be hardware and OS agnostic. :)

Note: You will be told why your work was not accepted as a vaiid answer should that be the case.

Most of these should be fairly simple and are usually considered introductory level problems. Have fun. :)

*******************************************

Round 2!

OK, so Round 1 was a success and also served to show that we have a decent programming level, so I'm going to set up the following challenges:

Challenge #4: (PRIZE: 25 mill)
Design an app or a script that scrapes torn. It must return the name for any give ID.

For example:
scrapeTorn(3901) should return "Dash"

The function name is just a suggestion you can call it whatever you want.

*******************************************
CHALLENGE #5: (PRIZE 30 MILL)

Design a function that determines the best possible route from any point to another point in the following map (node structure):

Node A is connected to Node B, Node C and Node E
Node B is connected to Node D, Node E, Node A and Node C
Node C is connected to Node B, Node A and Node E
Node D is connected to NodeB, Node F and Node G
Node E is connected to Node B, Node C, Node G, Node A and Node H
Node F is connected to Node D
Node G is connected to Node D, Node E and Node I
Node H is connected to Node E and Node I
Node I is connected to Node G and Node H

Here's an illustration:

[image: sleepyengineer.com]

This is an introductory level AI course problem. It is often referred to as a path finder. The best path will be determined by one that travels through the least amount of nodes in order to get to a destination without repeating a node (meaning you shouldn't have to return to a node once you've been there).

For example:

To get from point A to point G the following routes exist:
A -> B -> C - > E -> G = 5 nodes
A -> C -> B -> E -> G = 5 nodes
A -> B -> E -> G = 4 nodes
A -> C -> E -> G = 4 nodes
A -> B -> D -> G = 4 nodes
A -> E -> G = 3 nodes (best route)

GL, HF!
Astral [300312]

Well here's #1 in ASM (for Windows NASM, but I guess Linux NASM should also be the same but untested). Forget your 2lines, my compiled code will be exactly 1 page of consumed HDD space, smallest you can get. Even though the binary itself is merely a few dozen bytes, typical Windows page size is 4KB. Regardless it will still be smaller than any of your compiled C, or python binaries ;)



global main
extern printf ;gonna cheat and use C runtime printf

section .data
maximum dd 9
format db 'Sum: %d',10,0

section .text
main:
mov ecx, 1
mov eax, 0

loop:
add eax, ecx
inc ecx
cmp ecx, [maximum]
jle loop

push eax
push format
call printf

add esp,8 ;clean stack
ret



Dash [3901]

Very nice, I did not expect anyone to do assembly for these problems. :)

That said, I am unwilling to make corrections in your code to make it run on Linux due to the nature of this contest (entries should run as-is without modifications, libraries or special considerations) but I will offer this if you intend on making corrections:

$ nasm -f elf sum.asm
$ ld -s -o sum sum.o

ld: i386 architecture of input file `sum.o' is incompatible with i386:x86-64 output
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
sum.o: In function `loop':
sum.asm:(.text+0x1c): undefined reference to `_printf'


(Note that I am running it in a Linux environment)

Cheers and well done. I can't accept it as a valid answer just yet, but I am certain you will get it. :)

EDIT: I will add that entries should be hardware and OS agnostic but I will accept your entry if you correct it so that it runs on my machine. :)
Vinkuun [1791283]
Challenge 1:

First a recursive solution:
def partial_sum_1(n): return 1 if n == 1 else partial_sum_1(n-1) + n
Now using a formula to calculate the nth partial sum:
def partial_sum_2(n): return n*(n+1)/2

Challenge 2:
def odd_sum(numbers): return sum([x for x in numbers if x%2 != 0])

Challenge 3:

def reverse_words(sentence): return " ".join([word if len(word) <= 4 else word[::-1] for word in sentence.split()]);
All examples use Python and can be run here: https://repl.it/vRU/1
halberstram [1899754]

I'm not competing, but this is a really awesome idea. I only know some really basic Python so my input would be awful. R+ for a great idea.
Dash [3901]
You sent $75,000,000 to Vinkuun with the message: Programming Challenge 1 winner

Well that message should have said "Programming challenges 1, 2 and 3". Nicely done with the recursive approach.

The programming level seems to be a bit higher than I initially imagined (which is great). This means we can raise the level of difficulty and corresponding prize per challenge. :D

I will post another one soon. In the meanwhile, if you have an idea for a challenge send it to me and I will evaluate how difficult it is and set a prize for it.

It goes without say that proposing a challenge does not make you elegible for a prize, but you would be participating which will be nice. :)
Astral [300312]

Hey, made a small change to the code above and try compile with:

nasm -f elf sum.asm
gcc sum.o -o sum.out
./sum.out

Reason I'm using GCC is it already calls the linker "ld" with all the correct options for dynamic linking to DLLs. Also now I'm no longer restricted to an entry point of _start as GCC will jmp to our specified entry point if we specify "-e" as an arg else default it looks for is main.
0tt3r [1920851]

Challenge #4:
http://jsfiddle.net/n2wwh9t9/3/

Edit: Removed my (now unused) API key. Added API key input box, so others can still use this in the future. To find your API key go to Settings -> API Key
Vinkuun [1791283]

So we now have your Torn API key? You should remove that ;) But if you do your script breaks.

Edit: You stacking E, eh? :D
Dash [3901]

You sent $25,000,000 to 0tt3r with the message: Challenge 4 winner. Congratulations.

Well done.

I like how compact your code was. :)

I will be adding more challenges soon!

If you would like to propose further challenges let me know, I might not pick your idea but it might help come up with something.

Thanks to all who have participated so far! Stay tuned for more!
0tt3r [1920851]

Thanks, Dash!

The compactness was all thanks to the Torn API. I'm looking forward to its full release!

Your challenge 5 can be made even harder by adding in weights on all the edges; think of it like roads. Some roads take longer because of traffic (have larger weight). This makes an interesting twist; the best path may go through more nodes than the 'shortest' path.