Skip to content

Commit a817589

Browse files
tidy up the ;;=>
1 parent c7afc24 commit a817589

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

notebooks/code_interview/beating/with_stupid_stuff/z_combinator_gambit.clj

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
;; People often send me emails asking, "How can I use lambda calculus to impress people?"
1515
;; Today, we find out.
1616

17-
;; ![programmer staring at Z-combinator](z-combinator.jpg)
17+
;; ![Programmer staring at Z-combinator](z-combinator.jpg)
1818

1919
;; I have an interview with ZCorp lined up in 5 minutes,
2020
;; and our challenge is to only use anonymous functions.
@@ -52,7 +52,6 @@
5252
(conj (SELF SELF (rest LIST))
5353
(first LIST)))))
5454
(REV REV [1 2 3 4 5])
55-
;;=> [5 4 3 2 1]
5655

5756
;; `SELF` is an input to itself, the logic of reversal.
5857

@@ -70,7 +69,7 @@
7069
[]
7170
(conj (SELF (rest LIST))
7271
(first LIST))))))
73-
;; ```
72+
;; ```clojure
7473
;; ((REV' REV') [1 2 3 4 5])
7574
;; ```
7675
;; **error**
@@ -90,7 +89,6 @@
9089
(first LIST))))))
9190

9291
((REV'' REV'') [1 2 3 4 5])
93-
;;=> [5 4 3 2 1]
9492

9593
;; > That's a confusing way to write it
9694

@@ -116,15 +114,12 @@
116114
;; But identity is the identity of itself:
117115

118116
(identity 1)
119-
;;=> 1
120117

121118
((identity identity) 1)
122-
;;=> 1
123119

124120
;; > O.K. sure, but that's a special case.
125121

126122
(((identity identity) (identity identity)) 1)
127-
;;=> 1
128123

129124
;; > This is an identity crisis.
130125

@@ -187,7 +182,7 @@
187182

188183
;; Because `(FIX F) = ((FIX F) (FIX F))`, it was your idea to refactor remember?
189184

190-
;; ```
185+
;; ```clojure
191186
;; (FIX REV-LOGIC)
192187
;; ```
193188
;; **stack overflow**
@@ -246,17 +241,14 @@
246241
;; > At least it didn't blow up this time...
247242

248243
((FIX REV-LOGIC) [1 2 3 4 5])
249-
;;=> [5 4 3 2 1]
250244

251245
;; > Nice, that's the right answer.
252246

253247
;; Even nicer is that our fixed logic behaves like identity now:
254248

255249
((REV-LOGIC (FIX REV-LOGIC)) [1 2 3 4 5])
256-
;;=> [5 4 3 2 1]
257250

258251
((REV-LOGIC (REV-LOGIC (FIX REV-LOGIC))) [1 2 3 4 5])
259-
;;=> [5 4 3 2 1]
260252

261253
;; > I can't believe something so ridiculous actually works.
262254

@@ -274,7 +266,6 @@
274266
;; Your essence is invariant.
275267

276268
((Z REV-LOGIC) [1 2 3 4 5])
277-
;;=> [5 4 3 2 1]
278269

279270
;; > Wait, we are meant to be doing Fibonacci, remember?
280271

@@ -283,8 +274,8 @@
283274
;; > It looks to me like you doubled the code, that's not great refactoring.
284275
;; > Using single letters make it totally unreadable.
285276

286-
;; Hmmm you got me there, there does seem to be a lot of doubling.
287-
;; What if we had a function for `f => (f f)`
277+
;; Hmmm, there does seem to be a lot of doubling.
278+
;; We can factor out a function for `f => (f f)`.
288279

289280
(def REPLICATE "Omega, the self-devouring serpent"
290281
(fn [F]
@@ -293,11 +284,10 @@
293284
;; The replication of identity is itself.
294285

295286
((REPLICATE identity) 1)
296-
;;=> 1
297287

298288
;; But test not the serpent lightly
299289

300-
;; ```
290+
;; ```clojure
301291
;; (REPLICATE REPLICATE)
302292
;; ```
303293
;; **stack overflow**
@@ -311,7 +301,6 @@
311301
(LOGIC (fn [V] ((X X) V)))))))
312302

313303
((Z REV-LOGIC) [1 2 3 4 5])
314-
;;=> [5 4 3 2 1]
315304

316305
;; > That's not really any clearer...
317306

@@ -332,7 +321,6 @@
332321
;; OMEGA diverges, ZETA folds, LOGIC writes QED.
333322

334323
((FOLD REV-LOGIC) [1 2 3 4 5])
335-
;;=> [5 4 3 2 1]
336324

337325
;; That's much nicer, I'm so glad you suggested using longer names.
338326

@@ -348,14 +336,12 @@
348336
(SELF (concat [(+ A B) B] FIBS))))))
349337

350338
((FOLD FIB-LOGIC) [1 1])
351-
;;=> (13 8 8 5 5 3 3 2 2 1 1 1)
352339

353340
;; > That's all backward!!
354341

355342
;; Oh, my mistake
356343

357344
((FOLD REV-LOGIC) ((FOLD FIB-LOGIC) [1 1]))
358-
;;=> [1 1 1 2 2 3 3 5 5 8 8 13]
359345

360346
;; > You can't be serious...
361347
;; > This is ridiculous.
@@ -372,15 +358,14 @@
372358
(cons A ((SELF B) (+ A B))))))))
373359

374360
(take 20 (((FOLD FIB-LOGIC-FOREVER) 1) 1))
375-
;;=> (1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765)
376361

377362
;; That's so nice.
378363

379364
;; > Oh look at the time! I have a more important meeting to go to!
380365
;; **disconnects**
381-
;;
366+
382367
;; Ouch, Rough.
383-
;; ZCorp never got back to me, so let’s update the scoreboard as a loss without a GG.
368+
;; ZCorp never got back to me, so let’s update the scoreboard as a loss.
384369

385370
^:kind/table ^:kindly/hide-code
386371
{:Interviews [1]

0 commit comments

Comments
 (0)