This file contains 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
// Sha512 in Rust | |
#[macro_use] | |
extern crate itertools; | |
use sha2::{Digest, Sha512}; | |
fn main() { | |
let target = Sha512::new().chain(b"help").result(); | |
let alpha = "abcdefghijklmnopqrstuvwxyz"; | |
let col = iproduct!(alpha.chars(), alpha.chars(), alpha.chars(), alpha.chars()) | |
.map(|(a, b, c, d)| format!("{}{}{}{}", a, b, c, d)) |
This file contains 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
/* | |
** In java remove() is overloaded | |
** for Class ArrayList<E> | |
** we have: | |
** | |
** public E remove(int index) | |
** Removes the element at the specified position in this list. | |
** | |
** public boolean remove(Object o) | |
** Removes the first occurrence of the specified element from this list |
This file contains 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
ch := make(chan WeatherReport) | |
for _, city := range cities { | |
go fetch(city, ch) // fetch call api and put response in ch | |
} | |
for range cities { | |
rep := <- ch | |
reports = append(reports, rep) | |
} |
This file contains 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
let (tx, rx) = mpsc::channel(); | |
for city in cities { | |
let tx = tx.clone(); | |
let city = city.clone(); | |
thread::spawn(move || { | |
let report = api_call(&city, &api_key); | |
tx.send(report).unwrap(); | |
}); | |
} | |
let mut reports : Vec<ApiResult> = Vec::with_capacity(cities.len()); |
This file contains 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-weather (sort-reports (pmap weather-api r)))) |
This file contains 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
def parFetch(cities:List[String]) : Unit = { | |
val reports = (cities.par map (city => apiCall(city))).toList | |
printReports(reports) | |
} |
This file contains 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
var reports = [ApiResult?]() | |
for i in 1...cities.count { | |
reports.append(nil) | |
} | |
let globalQueue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0) | |
dispatch_apply(cities.count, globalQueue) { | |
i in | |
let index = Int(i)+2 // cities start from 2 | |
let city = cities[index] | |
let rep = callApi(city, apiKey:apiKey) |
This file contains 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
(defn gano? [num sec tam] | |
(let [f (famas num sec) t (- (toques num sec) f)] | |
(println "tu ingresaste" num) | |
(println "resultado:" t "Toques, " f "Famas\n") | |
(= tam f))) |
This file contains 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
let comparar num sec = | |
let rec tyf ns xs ys = | |
match (ns, xs, ys) with | |
| ([], _, _) -> (0,0) | |
| (n::ns, x::xs, ys) -> | |
let (t,f) = tyf ns xs ys | |
if n = x then (t,f+1) else (if List.exists (fun x -> x = n) ys then (t+1,f) else (t,f)) | |
tyf num sec sec |
This file contains 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
contar_toques_y_famas(Num,Sec) -> tyf(Num,Sec,Sec). | |
tyf([],_,_) -> {0,0}; | |
tyf([HNS|TNS],[HXS|TXS],YS) -> | |
{T,F} = tyf(TNS,TXS,YS), | |
if HNS =:= HXS -> {T,F+1}; | |
HNS =/= HXS -> {T+toque(HNS,YS),F} | |
end. | |
toque(X,XS) -> IN = lists:member(X,XS), if IN =:= true -> 1; IN =:= false -> 0 end. |
NewerOlder