Show more

*I* used to be the only spinster on fediverse. The first. By Jove, I’m taking the word back right now.

Anyone who wants to “identify as a spinster” must not be a nazi/terf.

Thanks for your attention.

Okay, here is a fun one. We've all seen Fibonacci sequences. But they are all played out. Let's look at a different sequence. They are called Hamming Numbers after Richard Hamming, who proposed the problem of finding computer algorithms for generating these numbers in ascending order.

For number H is equal to 2**i * 3**j * 2**k where i,k,k are all non negative.

For example
2**0 * 3**0 * 5**0 = 1
2**1 * 3**0 * 5**0 = 2
2**0 * 3**1 * 5**0 = 3
2**2 * 3**0 * 5**0 = 4
2**0 * 3**0 * 5**1 = 5
2**2 * 3**1 * 5**0 = 6
2**3 * 3**0 * 5**0 = 8

So hopefully that explains what the sequence looks like. Your challenge, if you choose to accept it is to generate the first 25 of them. An arbitrary nth one such as 1700th. And given a number X determine if it is or is not a valid hamming number.

Here is the wiki article on them:

en.wikipedia.org/wiki/Regular_

go solution 

@Absinthe Keeping in the tradition of choosing the worst possible languages for this time it's Go: gitlab.com/tymorl/warmups/blob . The algorithm is essentially the same as @khird proposed.

@Absinthe I'm very slowly working on a little clever one, and I'm going to use it to make me a new profile picture, just you wait...

@Absinthe couldn't resist this one:
git.sr.ht/~namark/snail/tree/m
I swear I tried to do it for square only but it seems to work for rectangles too.

In true c++ fashion it comes with a bunch of illegible library code, which I had to extend with a couple of extra abominable appendages to accommodate this toy.

#toyprogrammingchallenge #cpp

@Absinthe

#toyprogrammingchallenge

I wrote a Life in JavaScript a few years ago. I suppose I could interpret the challenge as building the smallest one I can, but I've done enough of them that one more isn't interesting at present. I suppose I should do it in Elm, but I'm having too much fun programming MIDI in Lisp right now.

https://billstclair.com/life

Okay, here is one before the weekend.

Conway's Game of Life. It is a simple concept. Set up some cool patterns and let it run on a good cycle. I just did it, using '*' and ' ' but feel free to do it graphically if you prefer. Here are the rules, and my code is in the same repo so let that be a spoiler warning:

git.qoto.org/Absinthe/life-con

@Absinthe Hello! I saw you write about programming puzzles (and that's why I followed you), I was wondering if you know Advent of Code, and if you do, how do you like it 🙂
adventofcode.com

@freemo @Absinthe some people (eg. those on the autism spectrum) are uncomfortable with direct eye contact

eg. i for one can handle it in images but not irl. for some it's more intense.

so it's best to be safe an CW eye contact

The number and nature of the compromises I have to make when choosing a programming language for every goddamn project really gets to me

Show thread

Except for C. To every use-case which C is suitable, it has never been a disappointment to me.

Show thread

why do people mention the presence or lack of eye contact in their cw protected selfies?

Python Solution 

def snail_sort(matrix):
new_list = []

while matrix:
new_list.extend(matrix.pop(0))
if not matrix:
continue

for i in range(len(matrix)):
new_list.append(matrix[i].pop())
if not matrix:
break
if not matrix:
continue

new_list.extend(reversed(matrix.pop()))
if not matrix:
continue

for i in range(len(matrix) - 1, -1, -1):
new_list.append(matrix[i].pop(0))
if not matrix:
break
return new_list

MATRIX = [
[1, 2, 3, 4, 5],
[16, 17, 18, 19, 6],
[15, 24, 25, 20, 7],
[14, 23, 22, 21, 8],
[13, 12, 11, 10, 9],
]

snail_sort(MATRIX)

Show thread

I borrowed this one from codewars

Snail Sort
Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.

array = [[1,2,3],
[4,5,6],
[7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
For better understanding, please follow the numbers of the next array consecutively:

array = [[1,2,3],
[8,9,4],
[7,6,5]]
snail(array) #=> [1,2,3,4,5,6,7,8,9]
This image will illustrate things more clearly:

NOTE: The idea is not sort the elements from the lowest value to the highest; the idea is to traverse the 2-d array in a clockwise snailshell pattern.

Octave solution 

@Absinthe

function sorted = snail(array)
if numel(array) <= 1
sorted = array;
else
sorted = [array(1, 1:(end-1)),...
array(1:(end-1), end)',...
array(end, end:-1:2),...
array(end:-1:2, 1)',...
snail(array(2:(end-1), 2:(end-1))) ]; end; end;

For those of you who missed the announcement from the @freemo account just wanted to reiterate it here.

In honor of our new Indian friends we added two new emoji to the server.

:india: :thiruvalluvar:

Also if anyone has any emoji they want added, even if its just for personal use (like a monogram of your name or a picture of your own face, anything) we can add it. Just send a 50kb or less PNG image to @freemo and it can be added.

I borrowed this one from codewars

Snail Sort
Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.

array = [[1,2,3],
[4,5,6],
[7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
For better understanding, please follow the numbers of the next array consecutively:

array = [[1,2,3],
[8,9,4],
[7,6,5]]
snail(array) #=> [1,2,3,4,5,6,7,8,9]
This image will illustrate things more clearly:

NOTE: The idea is not sort the elements from the lowest value to the highest; the idea is to traverse the 2-d array in a clockwise snailshell pattern.

Show more
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.