From dbb7be7971d565a97f039fcaeb0def760c6f31ad Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Wed, 14 Dec 2022 21:52:34 +0800 Subject: julia pwc195 --- challenge-195/steve-g-lynn/julia/ch-1.jl | 15 +++++++++++++++ challenge-195/steve-g-lynn/julia/ch-2.jl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 challenge-195/steve-g-lynn/julia/ch-1.jl create mode 100755 challenge-195/steve-g-lynn/julia/ch-2.jl diff --git a/challenge-195/steve-g-lynn/julia/ch-1.jl b/challenge-195/steve-g-lynn/julia/ch-1.jl new file mode 100755 index 0000000000..4d67db2003 --- /dev/null +++ b/challenge-195/steve-g-lynn/julia/ch-1.jl @@ -0,0 +1,15 @@ +#!/usr/bin/env julia + +function special_integers( n::Int64 ) ::Int64 + ctr=0 + for i in 1:n + if length(digits(i)) == length(unique(digits(i))) + ctr += 1 + end + end + return ctr +end + +println(special_integers(15)) +println(special_integers(35)) + diff --git a/challenge-195/steve-g-lynn/julia/ch-2.jl b/challenge-195/steve-g-lynn/julia/ch-2.jl new file mode 100755 index 0000000000..e83f504c80 --- /dev/null +++ b/challenge-195/steve-g-lynn/julia/ch-2.jl @@ -0,0 +1,31 @@ +#!/usr/bin/env julia + +using StatsBase + +function most_frequent_even( mylist::Vector{Int64} )::Int64 + evens = mylist[mylist .% 2 .== 0] + + if length(evens)==0 + return -1 + end + + d_freq = countmap(evens) #-- a dictionary (hash) + + max_freq=maximum(values(d_freq)) + + retval = Vector{Int64}() + + for i in keys(d_freq) + if d_freq[i] == max_freq + push!(retval, i) + end + end + + return minimum(retval) +end + + +println(most_frequent_even([1,1,2,6,2])) #2 +println(most_frequent_even([1,3,5,7])) #-1 +println(most_frequent_even([6,4,4,6,1])) #4 + -- cgit