Show newer
@namark @Absinthe

CONS = construct
CAR = Contents of Address Register
CDR = Contents of Decrement Register

Assembly language instructions for one of the first lisp interpreters. I don’t know which machine.

@alex I trust you don't eat almonds or other almond products either

@Absinthe ancient abbreviations? and I was hoping they were some cool french words...

Here's a python solution 

Need a better solution for deserialization than eval()

git.qoto.org/Absinthe/serializ

Show thread


Here's another freebie, I assume it is python specific because they start with a base of python code. But if it makes sense, try it in whatever language you like:

This problem was asked by Google.

Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.

For example, given the following Node class

class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
The following test should pass:

node = Node('root', Node('left', Node('left.left')), Node('right'))
assert deserialize(serialize(node)).left.left.val == 'left.left'

@namark what are the inplications of "cons" "car" and "cdr"? What are these terms suggesting?


Here's another freebie, I assume it is python specific because they start with a base of python code. But if it makes sense, try it in whatever language you like:

This problem was asked by Google.

Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.

For example, given the following Node class

class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
The following test should pass:

node = Node('root', Node('left', Node('left.left')), Node('right'))
assert deserialize(serialize(node)).left.left.val == 'left.left'


Here's a Freebie!

This problem was asked by Stripe.

Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well.

For example, the input [3, 4, -1, 1] should give 2. The input [1, 2, 0] should give 3.

You can modify the input array in-place.

re: Solution 

@billstclair I am not sure I am seeing what power they are trying to illustrate...

re: Solution 

@billstclair yep, that is what it seems. But what is the use/benefit of this technology?

#python #toyprogrammingchallenge Here is a problem that even though the answer seemed easy, I don't understand what it is supposed to be teaching, or what's going on. Anyone care to explain this problem to me? 

# This problem was asked by Jane Street.
#
# cons(a, b) constructs a pair,
# and car(pair) and cdr(pair) returns the first and last element of that
# pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4))
# returns 4.
#
# Given this implementation of cons:
#
# def cons(a, b):
# def pair(f):
# return f(a, b)
# return pair
#
# Implement car and cdr

def cons(a, b):
def pair(f):
return f(a, b)
return pair

def car(pair):
def f(a, b):
return a
return pair(f)

def cdr(pair):
def f(a, b):
return b
return pair(f)

print cdr(cons(3,4))
print car(cons(3,4))

@Absinthe
other product using division
git.sr.ht/~namark/mercury_stuf
hate all the edge cases

no division version in the working, hopefully would be much smoother.

#toyprogrammingchallenge #mercurylang

@namark Now I really wish I had gotten the compiler installed. :) We'll see what happens during the week.

re: A Python solution 

@Absinthe @zingbretsen

I'm going to do the next one in Elm, working example published at https://ellie-app.com

#toyprogrammingchallenge

re: A Python solution 

@billstclair @zingbretsen right, so I had to do more than just run it :) It just gave me some funtions to call. I got it now.

Show older
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.