Would #Forth be good for DSP work? Think implementing an over the air ham radio digital mode protocol, either voice or data. What about SDR firmware?
Would #Forth be good for DSP work? Think implementing an over the air ham radio digital mode protocol, either voice or data. What about SDR firmware?
New era, new #introduction!
I started with #biology, realized I like #math along the road, and ended up loving #evolution.
After a BSc in the first, an MSc (and a half) in Bioinformatics/Computational biology (and applied math) I have started my #PhD in Ecological evolutionary modelling at @KorinnaAllhoff team at @unihohenheim!
I will be building models of biotic-interractions (antagonistic and/or mutualistic) between 2 and 3 species and check out emerging networks of these communities.
Looking forward to the adventure in this new landscape of possibilities of #programing ∩ #ecology ∩ #math!! :D
Almost done with my RSS Feed manager, Feeder. I just need to:
1) Add build and publication times
2) Polish up the user experience
3) Port it to Windows and Web
This became longer than a weekend project but I've made some progress on my RSS feed generator.
Did you know Java runs on 3 billion devices?
I wonder if this was ever updated for Android… I also wonder what proportion of Android apps currently out there are actually written in Kotlin.
I am stupid-proud of this small #haskell program. It’s not complex, but it is pretty haskell-y.
It’s another HackerRank challenge: Given a string of lowercase characters – a “word” – find the very next word in the dictionary (lex sorted) made only by rearranging letters of your word OR “no answer” if that’s not possible.
module Main where
import Control.Monad (replicateM_)
import Data.List (find, sort, span)
go :: String -> String -> Maybe String
go ts "" = Nothing
go ts (h : hs) = do
let ts' = sort ts
let mc = find (> h) ts'
case mc of
Nothing -> go (h : ts) hs
Just c -> do
let (left, _ : right) = span (< c) (sort (h : ts'))
Just $ reverse (c : left ++ right) ++ hs
solve :: String -> String
solve w = do
maybe "no answer" reverse (go "" (reverse w))
main :: IO ()
main = do
cases <- readLn :: IO Int
replicateM_ cases $ do
getLine >>= putStrLn . solve
It’s not necessarily the best or most efficient, but it does deal with haskell’s preference for the front of a list, light use of Maybe, recursion, … On a second pass, I might use Data.Sequence for working from the tail and splicing… still, it’s nice when concepts click.
I don’t know how I feel about #programing exercises that go a little far afield from programing… but I do like my math
Challenge from HackerRank, solution in #haskell
Given k
in the natural numbers, N
, and S
subset of N
such that the elements of S
are unique, find max |S'|
where S'
subset of S
and for all m
, n
in S'
with m != n
, k
does not divide m + n
.
module Main where
import qualified Data.IntMap as M
solve :: Int -> [Int] -> Int
solve 1 _ = 1
solve k xs =
let
-- size the mod k equivalence classes
observed = M.fromListWith (+) $ map (\x -> (x `mod` k, 1)) xs
-- for convenience in map lookups, zero any class not seen
counts = foldr (\i acc -> M.insertWith (+) i 0 acc) observed [0 .. k - 1]
-- two types of classes can only have at most one elt each
picker :: Int -> Int -> Int
picker m i
| i == 0 || i == m - i = min 1 $ counts M.! i
| i > m - i = 0 -- safety guard in case I screwed up the edge
| otherwise = max (counts M.! i) (counts M.! (m - i))
in
foldl (\acc i -> acc + picker k i) 0 [0 .. k `div` 2]
main :: IO ()
main = do
[_, k] <- map read . words <$> getLine :: IO [Int]
xs <- map read . words <$> getLine :: IO [Int]
print $ solve k xs
My first “up close & personal” with monad stacks. Rationalized and successfully changed a few
IO Either ErrorString a
(no, I don’t remember how I got there)
to
ExceptT ErrorString IO a
so I can happy-path chain some “might fail and I want to report why nicely” functions.
After a day or so of struggles, it’s starting to make sense. (Hell, it took a bit just to find ExceptT
did the work of Either
.)
Wishing the struggle was lighter, but working through it.
The evening #python distraction from HackerRank: Break a string into chunks of length k and print the unique characters in each chunk (preserving order).
def solve(string, k):
batches = batched(string, k)
m=map(lambda b: str.join("", unique_everseen(b)), batches)
print(*m, sep="\n")
batched
is from itertools
; unique_everseen
is from more-itertools
.
Looking at everyone’s solutions in the discussions section, you really have to wonder how anything works
As for me, a little intellectual masturbation with an elegant, generator-based solution.
Style question for the object-oriented folks: If you have a “helper function” of sorts – something that basically improves readability of some other method but does nothing in particular to operate on an object’s state and likely has no reuse value outside the class, where do you put it?
I’m leaning more toward “It doesn’t matter; it’s semantic gobbledygook and style preference,” but I haven’t been keeping up with the OO Jonses
Python gurus, can I wrap a function in more than one decorator at the same time? On the same topic, can I wrap a decorator in another decorator ?
Asking for a friend...
What’s your opinion on using macros for stuff like that? I didnt like the nested match thingies and it could get quite huge with the auto-formatting, so I have made macros to unpack results, options and results of an option since I use these ALOT xD Now Im wondering... Is this an okay thing to do or too confusing for others? I made sure to name the macros properly and I guess you can see from the code what they do. #RustLang #coding #programing #tech #dev #development
Resist the urge to make temporary files with names like foo, foo2, foo3, foo.old, foo.old2, foo.new, newfoo2.old and so on.
Trust me. That which is new will become old. Your throw away scripts will become critical infrastructure.
Use meaningful names, even for temporary things, and have some sort of version control.
"There is nothing as temporary, as that which is called permanent, and nothing as permanent, as that which is called temporary."