[4Clojure]解题记录-#78

Reimplement Trampoline


Difficulty: Medium
Topics: core-functions

Reimplement the function described in "Intro to Trampoline".

(= (letfn [(triple [x] #(sub-two (* 3 x)))

(sub-two [x] #(stop?(- x 2)))

(stop? [x] (if (> x 50) x #(triple x)))]  (__ triple 2))  82)

(= (letfn [(my-even? [x] (if (zero? x) true #(my-odd? (dec x))))

(my-odd? [x] (if (zero? x) false #(my-even? (dec x))))]

(map (partial __ my-even?) (range 6)))  [true false true false true false])

解长度 41:

#(loop [t (apply % %&)] (if (fn? t) (recur (t)) t))
时间: 2024-10-05 05:01:59

[4Clojure]解题记录-#78的相关文章

[4Clojure]解题记录-#80

Perfect Numbers Difficulty: Medium Topics:   A number is "perfect" if the sum of its divisors equal the number itself. 6 is a perfect number because 1+2+3=6. Write a function which returns true for perfect numbers and false otherwise. (= (__ 6)

[4Clojure]解题记录-#79

Triangle Minimal Path Difficulty: Hard Topics: graph-theory Write a function which calculates the sum of the minimal path through a triangle. The triangle is represented as a collection of vectors. The path should start at the top of the triangle and

[4Clojure]解题记录-#77

Anagram Finder Difficulty: Medium Topics:   Write a function which finds all the anagrams in a vector of words. A word x is an anagram of word y if all the letters in x can be rearranged in a different order to form y. Your function should return a s

[4Clojure]解题记录-#67

Difficulty: Medium Topics: primes Write a function which returns the first x number of prime numbers. (= (__ 2) [2 3]) (= (__ 5) [2 3 5 7 11]) (= (last (__ 100)) 541) 提交长度:Code Golf Score: 120 (fn [x] (take x (filter (fn [n] (if (= 2 n) true (empty? 

[4Clojure]解题记录-#73

Difficulty: Hard Topics: game A tic-tac-toe board is represented by a two dimensional vector. X is represented by :x, O is represented by :o, and empty is represented by :e. A player wins by placing three Xs or three Os in a horizontal, vertical, or

[4Clojure]解题记录-#69

Difficulty: Medium Topics: core-functions Write a function which takes a function f and a variable number of maps. Your function should return a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, t

[4Clojure]解题记录-#63

题目 Difficulty: Easy Topics: core-functions Given a function f and a sequence s, write a function which returns a map. The keys should be the values of f applied to each item in s. The value at each key should be a vector of corresponding items in the

Pwnable中的passcode解题记录:

Pwnable中的passcode解题记录: 看下源码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 void login(){ 5 int passcode1; 6 int passcode2; 7 8 printf("enter passcode1 : "); 9 scanf("%d", passcode1); //这里没有加取地址符号 10 fflush(stdin); 11 12 //

AC自动机解题记录

1.HDU 2222 Keywords Search 模板题 1 #include <bits/stdc++.h> 2 #define fir first 3 #define sec second 4 #define EPS 1e-12 5 using namespace std; 6 7 typedef long long LL; 8 typedef pair<int , int > pii; 9 const int MAXN=5e5+5; 10 11 struct Trie{