BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Fun Coding Challenges / Questions


@Darin.K wrote:

I agree that arbitrary precision math as a first-class citizen would be awesome.


 

Me too! It's a request I hear often, people wanting to do integer math with values greater than I64/U64 can handle. If you ever felt so inspired as to submit your library to the LabVIEW Tools Network, I'd love to have a place to send people to get such a library from a source I trust with that sort of thing.

0 Kudos
Message 21 of 53
(8,959 Views)

So here's finally a screenshot of my first effort (With recursion).

 

2016-02-16 09_06_10-Coconuts.vi Front Panel on Untitled Project 1_My Computer _.png

So if we analyse the recursion level with iterations we see a very clear pattern of repeating values at (sailor-1) intervals.  The only part I didn't get right away is the initial iteration count (first "1" peak visible).  The rest is relatively clearly "static" as a function of the number of sailors.  But this versions leaves any such optimisations out.

 

This version takes nearly 8 seconds for 8 sailors on my machine.

Download All
Message 22 of 53
(8,946 Views)

lol, my results are all wrong..... Smiley Very Happy

0 Kudos
Message 23 of 53
(8,943 Views)

That was fun. I think altenbach's was the best with runner up of Intaris because I didn't even think of a recursive solution.

 

Anyway, here is round 2!

(stolen from https://www.reddit.com/r/dailyprogrammer/comments/45w6ad/20160216_challenge_254_easy_atbash_cipher/)

 

Description

Atbash is a simple substitution cipher originally for the Hebrew alphabet, but possible with any known alphabet. It emerged around 500-600 BCE. It works by substituting the first letter of an alphabet for the last letter, the second letter for the second to last and so on, effectively reversing the alphabet. Here is the Atbash substitution table:

Plain:  abcdefghijklmnopqrstuvwxyz
Cipher: ZYXWVUTSRQPONMLKJIHGFEDCBA

Amusingly, some English words Atbash into their own reverses, e.g., "wizard" = "draziw."

This is not considered a strong cipher but was at the time.

For more information on the cipher, please see the Wikipedia page on Atbash.

Input Description

For this challenge you'll be asked to implement the Atbash cipher and encode (or decode) some English language words. If the character is NOT part of the English alphabet (a-z), you can keep the symbol intact. Examples:

foobar
wizard
/r/dailyprogrammer
gsrh rh zm vcznkov lu gsv zgyzhs xrksvi

Output Description

Your program should emit the following strings as ciphertext or plaintext:

ullyzi
draziw
/i/wzrobkiltiznnvi
this is an example of the atbash cipher

Bonus

Preserve case.

0 Kudos
Message 24 of 53
(8,892 Views)

That was a fun waste of 10 minutes 🙂

 

Spoiler

Atbash Cipher.png

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 25 of 53
(8,883 Views)

This was easier than I thought it would be.  My solution isn't elegant, but here it is.

 

Spoiler
Cipher.png

 

Edit:

Blast.  After looking at bsvare's answer... my solution may belong in the RG thread. I didn't think it all the way through 🙂

0 Kudos
Message 26 of 53
(8,902 Views)

@BowenM wrote:

Amusingly, some English words Atbash into their own reverses, e.g., "wizard" = "draziw."


 

I was curious what other words Atbash into their own reverses. So I used bsvare's code to generate a list, based on the dictionary used by the VI Analyzer Toolkit's Spell Check test:

 

w.png

Message 27 of 53
(8,876 Views)

 


@Darren wrote:

 I was curious what other words Atbash into their own reverses. So I used bsvare's code to generate a list, based on the dictionary used by the VI Analyzer Toolkit's Spell Check test


 That... is a surprisingly small list.  I expected it to be larger.

0 Kudos
Message 28 of 53
(8,860 Views)

Problem description

When you were a little kid, was indiscriminately flicking light switches super fun? I know it was for me. Let's tap into that and try to recall that feeling with today's challenge.

Imagine a row of N light switches, each attached to a light bulb. All the bulbs are off to start with. You are going to release your inner child so they can run back and forth along this row of light switches, flipping bunches of switches from on to off or vice versa. The challenge will be to figure out the state of the lights after this fun happens.

Input description

The input will have two parts. First, the number of switches/bulbs (N) is specified. On the remaining lines, there will be pairs of integers indicating ranges of switches that your inner child toggles as they run back and forth. These ranges are inclusive (both their end points, along with everything between them is included), and the positions of switches are zero-indexed (so the possible positions range from 0 to N-1).

 

Example input:

10
3 6
0 4
7 3
9 9

There is a more thorough explanation of what happens below.

 

Output description

The output is a single number: the number of switches that are on after all the running around.

Example output:

7

Explanation of example

Below is a step by step rendition of which switches each range toggled in order to get the output described above.

    0123456789
    ..........
3-6    ||||
    ...XXXX...
0-4 |||||
    XXX..XX...
7-3    |||||
    XXXXX..X..
9-9          |
    XXXXX..X.X

As you can see, 7 of the 10 bulbs are on at the end.

Challenge input

1000
616 293
344 942
27 524
716 291
860 284
74 928
970 594
832 772
343 301
194 882
948 912
533 654
242 792
408 34
162 249
852 693
526 365
869 303
7 992
200 487
961 885
678 828
441 152
394 453

Bonus points

Make a solution that works for extremely large numbers of switches with very numerous ranges to flip. In other words, make a solution that solves this input quickly (in less than a couple seconds): lots_of_ranges.txt (3 MB). So you don't have to download it, here's what the input is: 5,000,000 switches, with 200,000 randomly generated ranges to switch.

 

Edit: formatting from the copy paste. As before this was stolen from The Daily Programmer.  Also, feel free to post your own puzzles!  I've been enjoying this so far - it has provided needed breaks.

0 Kudos
Message 29 of 53
(8,744 Views)

@bsvare wrote:

That was a fun waste of 10 minutes 🙂

 

Spoiler

Challenge3.png


Didn't spend any longer this time, though, it's not the most optimized. Certinally doesn't work well with the bonus points.

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

0 Kudos
Message 30 of 53
(8,733 Views)