oopdawg / summer-work Goto Github PK
View Code? Open in Web Editor NEWsummer work 2023
summer work 2023
summer-work/java/BaseConverter.java
Lines 73 to 81 in 34e2efe
summer-work/java/BaseConverter.java
Line 84 in 34e2efe
summer-work/python/baseConverter.py
Lines 33 to 36 in 34e2efe
summer-work/java/BaseConverter.java
Lines 14 to 35 in 34e2efe
The initialization code in the constructor should be then moved to a static initializer block
summer-work/python/baseConverter.py
Line 19 in 34e2efe
This is enough as it's used once only:
for e, digit in enumerate(reversed(num)):
summer-work/python/baseConverter.py
Line 20 in 3b9d820
summer-work/python/baseConverter.py
Lines 1 to 4 in 34e2efe
summer-work/python/baseConverter.py
Lines 5 to 10 in 34e2efe
summer-work/java/BaseConverter.java
Line 94 in 34e2efe
summer-work/python/baseConverter.py
Lines 22 to 30 in 34e2efe
With a bit of logic, no need to copy code and run it once out of the loop.
Goal is to run the loop at list once, whatever the quotient value to begin with.
This is true is the endDigits
is empty, so we can test for that:
endDigits = []
quotient = numBase10
while quotient or not endDigits:
quotient, remainder = divmod(quotient, endBase)
endDigits.append(remainder)
summer-work/python/baseConverter.py
Lines 14 to 15 in 34e2efe
reverse is fine to reverse the sequence. however, as the list was just built, an alternative is to create the list out of the sequence already in the right order:
num[::-1]
# returns the sequence in reverse. num = '123'
will return '321'
list(sequence) create a list which each element from the sequence. An str is a sequence and each element is a char.
so list(num[::-1])
give the same result.
To be a bit more readable, 'reversed' is a built-in function reversing the sequence order
list(reversed('123'))
works too
# TODO D2 rewrite algorithm with that base
undefined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.