Last active
April 9, 2022 16:10
-
-
Save ooliver1/a390029b018414dafd68c1a14cbdd5a1 to your computer and use it in GitHub Desktop.
funky recursive lambda from https://gist.github.com/ooliver1/f92f6a1dd8373b2e3911fdc5eca708b6
This file contains hidden or 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
(lambda a: lambda v: a(a, v))(lambda f, value: f(f, value * 2))(initial) |
This file contains hidden or 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
print(int(((lambda a: lambda v: a(a, v))(lambda f, stuff: f(f, [[digits for digits in stuff[0] if digits[stuff[1]] == (max({v[stuff[1]] for v in stuff[0]}, key=[v[stuff[1]] for v in stuff[0]].count) if [v[stuff[1]] for v in stuff[0]].count("0") != [v[stuff[1]] for v in stuff[0]].count("1") else "1")], stuff[1] + 1]) if len([digits for digits in stuff[0]if digits[stuff[1]] == (max({v[stuff[1]] for v in stuff[0]}, key=[v[stuff[1]] for v in stuff[0]].count) if [v[stuff[1]] for v in stuff[0]].count("0") != [v[stuff[1]] for v in stuff[0]].count("1") else "1")]) != 0 and stuff[1] < 12 else stuff[0]))([list(open("input3.txt").readlines()), 0])[0], base=2) * int(((lambda a: lambda v: a(a, v))(lambda f, stuff: f(f, [[digits for digits in stuff[0] if digits[stuff[1]] == (min({v[stuff[1]] for v in stuff[0]}, key=[v[stuff[1]] for v in stuff[0]].count) if [v[stuff[1]] for v in stuff[0]].count("0") != [v[stuff[1]] for v in stuff[0]].count("1") else "0")], stuff[1] + 1]) if len([digits for digits in stuff[0] if digits[stuff[1]] == (min({v[stuff[1]] for v in stuff[0]}, key=[v[stuff[1]] for v in stuff[0]].count) if [v[stuff[1]] for v in stuff[0]].count("0") != [v[stuff[1]] for v in stuff[0]].count("1") else "0")]) != 0 and stuff[1] < 12 else stuff[0]))([list(open("input3.txt").readlines()), 0])[0], base=2)) | |
# https://adventofcode.com/2021/day/3 i think |
This file contains hidden or 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
(lambda a: lambda *v: a(a, v))(lambda f, value, value2: f(f, value * 2 + value2, value2))(initial) |
This file contains hidden or 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
print((lambda a: lambda *v: a(a, *v))(lambda f, a, b: a if b == 1 else a ** f(f, a, b - 1))(3, 3)) | |
# https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation#Introduction |
This file contains hidden or 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
( # 1 - called with the 2nd part then 3rd to call 2nd with itself and 3rd | |
lambda function: lambda value: function(function, value) | |
)( # 2 - called with itself and the 3rd part and returns calling itself | |
lambda function, value: function(function, value * 2) | |
)( # 3 - the actual initial value | |
value | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment