Skip to content

Instantly share code, notes, and snippets.

View LeFreq's full-sized avatar
:electron:
Ready for the jump to light speed.

Marxos LeFreq

:electron:
Ready for the jump to light speed.
View GitHub Profile
@LeFreq
LeFreq / BigInts
Last active December 22, 2015 18:59
How to implement arbitrarily-sized integers.
Arbitrary-precision arithmetic (aka BigNums)
(R) Registered Mark Janssen under Creative Commons: BY; idea can be used commercially if attribution is given in the credits and the resulting software if available freely to author or website is available to public.
The right way to think about implementing arbitrarily-sized integers is to use base-256 encoding and using simple ASCII strings (i.e. Ascii-Coded Binary).
To make an arbitrary precision *real* number, use Bigint to make an "Rational" class that simply uses two BigInts as numerator and denominator.
Now you have an exact, lossless way to represent any (finite) "real" number.
@LeFreq
LeFreq / Chooser
Last active October 20, 2019 12:57
Probabilistic Chooser Algorithm
Probabilistic Chooser: idea for giving fair output for all contributing participants based on a weighted vote. Should be used for all websites (for example) which use crowdsourced voting to prevent positive feedback loops.
(R) Registered Mark Janssen, under Creative Commons: BY, NC. Patents pending (hence NC) and these ideas are used in the GA-SOLVE program as well.
In the common Internet context of listing dynamic content that users are voting for, one encounters users gaming the ranking system by seeing who gets first, or unrecognized but good content content hiding below the popular content.
The solution is to give a weighted listing where each item is chosen proportional to its vote. This technique will prevent positive feedback loops that raise popular items forever above the rest (due to limitations of people's attention span to scan all contributions or positions). The idea is for every contribution, tally a count of all votes, then each contribution gets weighted from this total and an intelligen
@LeFreq
LeFreq / Pick.py
Created November 24, 2012 04:10
Probabilistic Chooser
"""Given a list of items, each with a floating-point number representing popularity, bounded at the bottom at zero (no negative values), pick an item based on the weight of that popularity.
"""
#NOTE: A variant of this is used in the Network flow class in pangaia. <github/Social-Garden>\
#This was originally developed for genetic algorithms and the program called GA-SOLVE written in Pascal in 1992
# Zero-weighted values are given a value equal to *half* the lowest value.
from random import *
cityrank = {"Denver": 0.5, "Chicago": 1.0, "Houston": 0.0, "NYC": 2.9}
@LeFreq
LeFreq / Python3000
Last active October 11, 2015 07:58
The real Python 3000
This is a start for an examination of Python and its evolution. More specifically, it looks at the issue of what was called Python3000 (Python3k) and how well the release of Python3 lived up to its hopes and vision. (For more detail see Ward's Wiki at the WikiWikiWeb).
I think many have not migrated over to python3 because there was a feeling of being let down with the possibilities of re-structuring Python for its famed 3000 release. This gist is a place holder for all issues that I know relating to a fully satisfying Python 3000 that keeps to the spirit of the Python community and continues the path of elegance.
Without knowing, Python (and the computer programming domain, in general) has been evolving into a Unified Information Model. In hindsight, this seems a natural trajectory within the field of Computer Science towards simplification of data handling and ease of use. Elegance has become the keyword for programmers in the Programming and Open Source community and I think Python is the language w