Skip to content

Instantly share code, notes, and snippets.

@VictorTaelin
Created March 27, 2025 03:01
Show Gist options
  • Save VictorTaelin/71307efdb407c2722be248870cd9d6cf to your computer and use it in GitHub Desktop.
Save VictorTaelin/71307efdb407c2722be248870cd9d6cf to your computer and use it in GitHub Desktop.
Vibe Test Prompt
-- Let's serialize lists of uints as follows:
--
-- <Uint> ::= 0 | 1 <Uint>
-- <List> ::= 0 | 1 <Uint> <List>
--
-- For example, [1,2,3] serializes to '1 10 1 110 1 1110 0'.
--
-- Let f be a function that, given a number N, and a list of
-- numbers XS, sets the Nth number on XS to 0. For example:
-- - f(2, [0,1,2,3,4]) = [0,1,0,3,4]
-- - f(0, [7,7,7]) = [0,7,7]
-- - f(3, [4,3,2,1,0]) = [4,3,2,0,0]
--
-- Your goal is to implement f for Bits, in Haskell.
-- Do not use any type in your solution, other than Bits.
-- You can not convert Bits to Ints, or any other type.
-- Complete the code below, making the tests pass.
data Bits = O Bits | I Bits | E deriving (Show, Eq)
fn :: Bits -> Bits -> Bits
-- SOLUTION HERE
main :: IO ()
main = do
let x0 = fn (I (O E)) (I (I (O (I (I (I (O (I (I (I (I (O (O E)))))))))))))
let y0 = I (I (O (I (O (I (I (I (I (O (O E))))))))))
let x1 = fn (I (I (O E))) (I (I (O (I (I (O (I (I (O (O E))))))))))
let y1 = I (I (O (I (I (O (I (O (O E))))))))
print $ x0 == y0 && x1 == y1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment