diff options
| author | Stephen Lynn <bizlsg@localhost.localdomain> | 2022-12-14 21:52:34 +0800 |
|---|---|---|
| committer | Stephen Lynn <bizlsg@localhost.localdomain> | 2022-12-14 21:52:34 +0800 |
| commit | dbb7be7971d565a97f039fcaeb0def760c6f31ad (patch) | |
| tree | bc252e22ebe562aa0e61b0c3eaf7110edb443f35 | |
| parent | 26fbe4844eb0eb44c5c0af69b067e9248b2dbb40 (diff) | |
| download | perlweeklychallenge-club-dbb7be7971d565a97f039fcaeb0def760c6f31ad.tar.gz perlweeklychallenge-club-dbb7be7971d565a97f039fcaeb0def760c6f31ad.tar.bz2 perlweeklychallenge-club-dbb7be7971d565a97f039fcaeb0def760c6f31ad.zip | |
julia pwc195
| -rwxr-xr-x | challenge-195/steve-g-lynn/julia/ch-1.jl | 15 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/julia/ch-2.jl | 31 |
2 files changed, 46 insertions, 0 deletions
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 + |
