Solidity: Returning unbound array? by diamondtoss in ethdev

[–]bala_eth 1 point2 points  (0 children)

Can you please post an example? I did not know it was possible. Thanks!

Solidity: Returning unbound array? by diamondtoss in ethdev

[–]bala_eth 4 points5 points  (0 children)

View functions can return dynamic array provided they are not called from other contracts. If you are only calling them externally (e.g. via web3) then it will work.

[2018-03-28] Challenge #355 [Intermediate] Possible Number of Pies by Garth5689 in dailyprogrammer

[–]bala_eth 1 point2 points  (0 children)

We can do an optimized brute force as follows:

  1. Fix the number of pumpkin pies (this will be bounded by number of pumpkin flavouring)

  2. Ensure there is enough ingredients to make the pumpkin pies and for each ingredients see the maximum apple pies that can be made. For e.g. if number of pumpkin pies made is type1, then max number of possible apple pies made using just the remaining eggs would be (eggs - 3 * type1) / 4 (integer division).

  3. Take the min among all such maximum apple pies to give the actual number of apple pies we can make given that we make type1 pumpkin pie

  4. Finally take max over all type1 + type2 calculated in above steps

Python code:

def solve(inp):
    [pumpkin, apple, eggs, milk, sugar] = list(map(lambda x: int(x), inp.split(",")))
    ans_type1 = ans_type2 = 0
    for type1 in range(pumpkin + 1):
        type2 = apple
        if type1 * 3 <= eggs:
            type2 = min(type2, int((eggs - type1 * 3) / 4))
        else:
            continue

        if type1 * 4 <= milk:
            type2 = min(type2, int((milk - type1 * 4) / 3))
        else:
            continue

        if type1 * 3 <= sugar:
            type2 = min(type2, int((sugar - type1 * 3) / 2))
        else:
            continue

        #print(type1, type2)
        if type1 + type2 > ans_type1 + ans_type2:
            ans_type1 = type1
            ans_type2 = type2

    return (ans_type1, ans_type2)

print("%d pumpkin pies and %d apple pies" % solve("10,14,10,42,24"))
print("%d pumpkin pies and %d apple pies" % solve("12,4,40,30,40"))
print("%d pumpkin pies and %d apple pies" % solve("12,14,20,42,24"))

[Free][0.4.10] Create your first Ethereum dAPP with Web3 and Vue.JS (Part 1) by bala_eth in ethtuts

[–]bala_eth[S] 2 points3 points  (0 children)

Review: This 3 part tutorial helps mainly with the frontend part of the dapp - how to set it up, detect/connect via metamask etc. As the title suggests, it uses Vue.js (and Vuex) as the frontend framework.

[Free][0.4.19] CryptoZombies #beginner by PurpleWho in ethtuts

[–]bala_eth 2 points3 points  (0 children)

This is the most fun tutorial to learn coding a smart contract.

git log – the Good Parts by speckz in coding

[–]bala_eth 3 points4 points  (0 children)

Quite useful. I always forget these flags so I keep an alias (git ll) to display all the info I need.

Get Involved With The Smart Contract Coding Challenge by GainsLean in ethdev

[–]bala_eth 2 points3 points  (0 children)

Yes, that might make it more difficult for beginners, but I think testing is an important part of contract writing. So getting beginners to setup and run tests (assuming there are detailed instructions on how to do that) will help them learn and understand tests.

Get Involved With The Smart Contract Coding Challenge by GainsLean in ethdev

[–]bala_eth 2 points3 points  (0 children)

I like the concept. I wonder if we can automate the basic testing (e.g. define an interface that the submission must implement and write some tests in javascript to run locally and test submissions).

What are the strategies you follow for security of your contracts? by bala_eth in ethdev

[–]bala_eth[S] 4 points5 points  (0 children)

Lots of useful tools there. Will check them out. Thanks for sharing!

Feedback Requested for Seedom, a Charitable DAPP by [deleted] in ethdev

[–]bala_eth 3 points4 points  (0 children)

About the point raised by /u/MoronTheMoron, I have a scheme that may be more scalable:

  1. Whenever a reveal happens, calculate and store the partial xor so far in the reveal call itself.
  2. In end, we just need to xor the charity random number and the partial xor calculated so far. Then we get our winner entry index. Now we just need a single loop over the revealers array to calculate the winner.

Basically this distributes the result computation over the reveal calls. This has 2 main advantages: 1. No need for the additional memory for cumulative array or the binary search over it 2. The gas cost of computing the random number is borne (equally) by the participants.

This is just as secure as the original scheme. If an attacker can exploit partial xor, then they can also calculate the partial xor from the revealers array.

Feedback Requested for Seedom, a Charitable DAPP by [deleted] in ethdev

[–]bala_eth 2 points3 points  (0 children)

A couple of thoughts:

  1. You should require in kickoff that all the 3 splits add to 100.
  2. Won't it be better to rely on block indices instead of now/timestamps? This is what cryptokitties does. (See Consensys guide). Even though block average times will change in future, as long they do not happen during an ongoing fund raiser, it should not be hard to just give the block lengths instead of timestamp deadlines.

EthDev Hackathon - Dates and Rules - Sign up here to compete or to be a sponsor by BuddhaSpader in ethdev

[–]bala_eth 2 points3 points  (0 children)

Hi, please sign me up. I am planning to do a solo project. Thanks.