This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#mostly from https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwjqkOKIodKAAxV3T0EAHbWTCxkQFnoECBIQAQ&url=https%3A%2F%2Fleetcode.com%2Fproblems%2Fx-of-a-kind-in-a-deck-of-cards%2Fsolutions%2F2857069%2Fpython-easy-solution-faster-than-99-22%2F&usg=AOvVaw0OEHJEjy6pL2XqRoSZTmAj&opi=89978449 | |
#import collections | |
class Solution: | |
def hasGroupsSizeX(self, deck) -> bool: | |
print(deck) | |
#count = collections.Counter(deck) | |
count = dict.fromkeys(deck,0) | |
for card in deck: | |
count[card]+=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def reverseParentheses(s): | |
if not s: | |
return '' | |
arr = [] | |
for char in s: | |
if char == ')': | |
combine_str = '' | |
while arr and arr[-1] != '(': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def canPlaceFlowers(self, flowerbed, n) -> bool: | |
for i, flower in enumerate(flowerbed): | |
if flower == 0 and (i == 0 or flowerbed[i - 1] == 0) and (i == len(flowerbed) - 1 or flowerbed[i + 1] == 0): | |
flowerbed[i] = 1 | |
n -= 1 | |
if n <= 0: | |
return True | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def isLongPressedName(self, name: str, typed: str) -> bool: | |
print(name,typed) | |
groups_name = [] | |
groups_name_count = [] | |
prev = None | |
for c in name: | |
if c != prev: | |
groups_name.append(c) | |
prev = c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
various(4) BTC testnet transmit / pushtx/ propagate methods, all failed :( | |
--------------------------------------- | |
sending using helloblock: | |
HTTPSConnectionPool(host='testnet.helloblock.io', port=443): Max retries exceeded with url: /v1/transactions (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000000000475E860>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)) | |
--------------------------------------- | |
sending using blockcypher: | |
{'error': "Couldn't deserialize request: invalid character 'x' in literal true (expecting 'r')"} | |
--------------------------------------- | |
sending using blockcypher @ sessions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
assumes you've entered (sendamount+fee) greater than Wallet balance | |
ignores special treatment of vout for coinbase tx | |
ignores fee considerations, assumes this is already part of nTargetValue | |
https://github.com/bitcoin/bitcoin/blob/v0.5.3/src/wallet.cpp#L760 | |
http://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm | |
""" | |
import random | |
def SelectCoins(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
OUTPUT: | |
private key#2: | |
9950aad11fc33c2d4a1f206e043c9755b377cf0bd7d6c93713143a3d23b0671d | |
public key#1: | |
0320869668e199a9499a41636983dfe337ca4878ee4170fcccd599b5674a02d055 | |
p2sh wallet: | |
2NAFVo3PXKoND1JvLkGug3FFmyzs9TxEy8X | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' Run from "electrum/lib" directory. | |
ThomaxV started a discussion on https://bitcointalk.org/index.php?topic=274182.msg2939599#msg2939599 | |
about changing the HD derivation logic in electrum 2. The below post: | |
http://bitcoin.stackexchange.com/questions/37013/how-to-import-a-hd-wallet-from-an-extended-private-key | |
confirms that the format is actually m/c/i (and not m/44'/0'/a'/c/i) | |
so I have altered https://gist.github.com/romanz/4b32782bfc0ff4984713 accordingly: | |
tested to work with keys/addresses exported from electrum 2.7.0 | |
note Electrum has a "gap limit" of 20, so loop @ level "c" to get the next 20 addresses | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from blockcypher import create_unsigned_tx | |
dest_addr = "mgMZ3UdQsEmJ1ebjRV9ibTn1DFCxgmMo7a" | |
priv1 = "9c46389dde9e820294b68defd44e01da12cfe1374324cf27c198e4822e7d9d1e" | |
pub1 = "0471b0e83960b9a8ad980400fc7ee85e9739009f0ee08ef033784bdcefe7f38c64e9ba2b9d842089486735556e0b1940304db510ad521865bb5b028dee229c1dbd" | |
addr1 = "mySFV5esqFZqz8maEVjEodxwc9xyhXMmmY" | |
pub2 = '04a3cc3225df2ef6ca72e960c5cab0059731301d5efe61e7ffa1c4cac3a8e4994adcb27f01a282b7747d96ffdad324e774087c4a35197e99016bca62541af26eab' | |
addr2 = 'mouKAz9iAgMJzZjiiw4bZ4rxkJapkTXVDZ' |