Ask coding questions

← Back to all posts
A challenge with a $5 bitcoin prize
h
jajoosam (655)

What up replers!

I've got an algorithms problem for you, where you're trying to find the longest pay it forward chain of gifts.

https://repl.it/@jajoosam/r-g-hist-chain-challenge

Check the details there👆 - and comment down if you have any questions.

The first to get a solution that works (only js please!) gets a $5 bitcoin prize - include your BTC address with your solution.

Edit: @ammarbinfaisal won 🏆

Have fun!

Answered by ammarbinfaisal (6) [earned 5 cycles]
View Answer
Commentshotnewtop
jajoosam (655)

@ammarbinfaisal Yes, perfect! What's your bitcoin address?

ammarbinfaisal (6)

@jajoosam ugh don't have one... and you don't need to do that :)

jajoosam (655)

@ammarbinfaisal I appreciate the help :)

If you ever create a https://read.gift page, hmu and I'll gift you a book!

PDanielY (626)

Oof I missed the challenge

RajivReddy (0)

https://repl.it/@RajivReddy/r-g-hist-chain-challenge-1

It returns all the chains that have the max chain length. The chains are inverted though, i.e. the last person is at index 0 and the first person is at index n.

RajivReddy (0)

Two questions :

  • Do you just need the chain length or do you need the nodes of each chain?
  • If history JSON is real time data that is stored from read.gift is it okay to assume that the data is already chronologically ordered?
jajoosam (655)

@RajivReddy

  • Need the nodes of each chain
  • Yes, ok to assume data is already chronologically ordered
[deleted]

are we doing your homework or something?

theangryepicbanana (1291)

I'd do this but why only js lol

[deleted]

@theangryepicbanana yeah js is boring

jajoosam (655)

@theangryepicbanana iss gotta go in the nodejs codebase for read.gift

MrEconomical (1351)

your json is invalid because you need quotes for the keys
also there are some strange data points where the buyer is the same as the receiver and also this one where the receiver is just true

anyways, the instructions were a little hard to understand. I hope I interpreted the "pay it forward chain" correctly and here is my solution:

https://repl.it/@MrEconomical/r-g-hist-chain

if i got it backwards it should be easy to fix

jajoosam (655)

@MrEconomical oof that was a stupid mistake, added quotes.

by pay it forward chain, I mean where person B is gifted a book by Person A, and then gifts a book to person C, after which Person C gifts a book to Person D and so on.

In this case, the chain would be A => B => C => D.

One person can appear multiple times in a chain.

AdCharity (871)

@MrEconomical nice altough I don't really have a clue what he's talking about